• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: PIC18F4550 I2C 的address 問題___part 2
#7
版主
版主


查看用戶資訊
這些都是 I2C 的函數,由 Microchip 的 Library 所提供。
請參考 C18 Libraries User's Guide的說明。
C:\mcc18\doc\MPLAB-C18-Libraries_51297f.pdf

或參考 W401 C18 workshop 教材第六張的說明。

發表於: 2007/11/29 11:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4550 I2C 的address 問題___part 2
#6
初級會員
初級會員


查看用戶資訊
版主大大
請問有void Initialize_I2C_Slave(void)
裡頭OpenI2C(SLAVE_7,SLEW_ON);
的程式嗎? 因為看不到OpenI2C(SLAVE_7,SLEW_ON)
函式的內容ㄝ
謝謝

發表於: 2007/11/29 11:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4550 I2C 的address 問題___part 2
#5
版主
版主


查看用戶資訊
直接 copy 一段 何仁杰 先生寫的 I2C Slave 程式,參考依下:
#include         <p18f4520.h>
#include         <i2C.h>
#include        <delays.h>

#include        "EVM_LCD.h"


#define        EEPROM_ADDR        0xAE 


void         InitializePORT(void) ;
void        InitializeADCvoid ) ;
void         Initialize_I2C_Slave(void) ;

unsigned char    I2C_Index I2C_Address,  I2C_RW I2C_Data I2C_Null ;

union 
{
int Word;
unsigned char Bytes[2];
}
EE_Data;

char    EE_Result ;

char    RERR WERR ;

 



#pragma interrupt isr_high

void    isr_high(void)
{
    if ( 
PIR1bits.SSPIF )
    {
                                                                    
// Clear Flag
            
if (SSPSTATbits.&& (!SSPSTATbits.D_A))                //     Address ?
            
{
                if (
SSPSTATbits.R_W == 0)     
                    {
                        
I2C_RW ;
                        
I2C_Index SSPBUF ;        // Null Read !!
                        
SSPCON1bits.CKP ;
                        
I2C_Index ;
                    }
                else                        
                    {
                        
I2C_Null SSPBUF ;
                        
SSPBUF I2C_Data ;
                        
SSPCON1bits.CKP ;
                        
I2C_Index ;
                        
I2C_RW ;
                    }

                
            }

            else if ( 
SSPSTATbits.)        // If STOP !!
                
{
                    
I2C_RW ;
                    
I2C_Index ;
                }
            else 
            {
                if (
I2C_RW == 0)            //    if Data Write
                    
{
                        if ( 
I2C_Index == )
                            {
                                
I2C_Address SSPBUF ;
                                
SSPCON1bits.CKP ;    
                                
I2C_Index++ ;
                            }
                        else
                            {
                                
I2C_Data SSPBUF ;    
                                
SSPCON1bits.CKP ;
                            }
                    }
                else
                    {
                         ;    
                    }
            }
                     
PIR1bits.SSPIF ;    
    }
}
#pragma code

#pragma code my_isr_vector=0x0008
void isr_high_direct(void)    
{                                  
     
_asm             //begin in-line assembly
     
goto isr_high    //go to isr_high function
     
_endasm         //end in-line assembly
}
#pragma code
    
void main (void)
{
    
    
InitializePORT( ) ;
    
OpenLCD( ) ;

    
InitializeADC( ) ;
    
Initialize_I2C_Slave( ) ;

    
LCD_Set_Cursor(0,0) ;
    
putrsLCD"I am PIC18F452") ;
    
    
WERR ;
    
RERR ;

    
INTCONbits.PEIE ;
    
INTCONbits.GIE ;

    while(
1
    {
        
Delay10KTCYx(10) ;
        
ADCON0bits.GO ;
            
            while ( 
ADCON0bits.GO) ;
            
            
LCD_Set_Cursor(1,0) ;
            
puthexLCD(ADRESH) ;

                
LCD_Set_Cursor(1,3) ;
                
puthexLCD(I2C_Data) ;
    }
}

//************************************************
//*        Function: Initialize PORT             *
//************************************************
void InitializePORT(void)
{
    
ADCON1=0b00000101;            // Enable AN0 & AN1 with External Vref
    
PORTA=0x00;
    
TRISA=0b11011011;            // RA0 & RA1 as A/D input,RA4 as SW2 input
                                // RA2 as LCD-E control, RA5 as CS Control  for SPI
    
PORTB=0b11000111;
    
TRISB  =0b11000111;            // RB[6:7] as ICD2,     
                                // RB3 : Clear Output , RB0 : Start/Stop Interrupt , RB1 : SCL Data/interrupt , RB2 : SDA Data 
    
INTCON2bits.RBPU ;        // Disable All Push-pull on PORTB                                    
    
PORTC=0x00;
    
    
PORTD=0x00;
}

void    InitializeADCvoid 
{
        
ADCON0 0b10000001 ;
        
ADCON1 0b00001110 ;        // Only RA0 as Analog Pin ( AN0 )
}

//************************************************
//* Initial I2C Master Mode with 7 bits Address  *
//* Clock Speed : 100KHz @16MHz                     *
//************************************************
void Initialize_I2C_Slave(void)
{
    
TRISCbits.TRISC3=1;
    
TRISCbits.TRISC4=1;
    
OpenI2C(SLAVE_7,SLEW_ON);
    
SSPADDEEPROM_ADDR;
    
SSPSTATbits.CKE=1;                // SMBus specific inputs
    
PIR1bits.SSPIF ;
    
PIE1bits.SSPIE ;
    
RCONbits.IPEN ;
    
SSPCON1bits.CKP ;
}

發表於: 2007/11/28 8:27
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4550 I2C 的address 問題___part 2
#4
初級會員
初級會員


查看用戶資訊
這是slaver 的設定程式
LATBbits.LATB0 = 0; // initial Latch of PORTB
LATBbits.LATB1 = 0; // initial Latch of PORTB
TRISBbits.TRISB0 = 1; // set RB0/SDA as input pin.
TRISBbits.TRISB1 = 1; // set RB1/SCL as input pin.
SSPCON1=0b00100110; //
SSPADD=0x02; // Address = 0x02
SSPCON2bits.GCEN=1;

RCONbits.IPEN=1; INTCONbits.GIEH=1; //enable ALL high priority interrupts
INTCONbits.GIEL=1; INTCON2bits.TMR0IP=1; //TMR0 is high priority
PIE1bits.SSPIE=1; //enable the MSSP interrupt
IPR1bits.SSPIP=0; //MSSP interrupt low priority

T0CON=0b00000000; //bit7:enable
TMR0H=0b11101000;
TMR0L=0b10001111;
INTCONbits.TMR0IE=1;

這是slaver的中斷副程式

void I2C_interrupt ()
{

unsigned char temp;
int i;

if(PIR1bits.SSPIF==1) //如果I2C中斷發生
{
PIR1bits.SSPIF=0;
temp=SSPBUF;

if(temp == 0x02)
{
TRISDbits.TRISD1=0;
PORTDbits.RD1=1;
}
}
}

這是 master 的設定程式

LATBbits.LATB0 = 1; // initial Latch of PORTB
LATBbits.LATB1 = 1; // initial Latch of PORTB
TRISBbits.TRISB0 = 1; // set RB0/SDA as input pin.
TRISBbits.TRISB1 = 1; // set RB1/SCL as input pin.

SSPADD=0xe; //clock = 400kHZ
SSPCON1=0b00111000;
SSPCON2bits.GCEN=1;
SSPSTAT=0b00000000;

這是master send I2C 給slave(0x02)的程式 , 只是slaver沒ack, 也就是沒回應 , 沒產生中斷 , 不過送0x00就會中斷
I2C_START();
if (I2C_Send_Address(0x02))
{ I2C_STOP();
}
else{
I2C_Send_Data(0x66);
I2C_STOP();
}



發表於: 2007/11/27 23:17
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4550 I2C 的address 問題___part 2
#3
資深會員
資深會員


查看用戶資訊
我想可檢查以下幾點

PIE1<SSPIE> 要設為 1
SSPCON1<SSPM3:SSPM0> 跟 start/stop bit 中斷有關

GCEN 是用在當有 address 0 的訊號時用的 若沒用應設為 0

還有 SSPIF 要設為 0, 中斷後也要還原為 0 (clear)

或許把你的程式 post 出來, 要不很難知道...

發表於: 2007/11/23 16:32
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4550 I2C 的address 問題___part 2
#2
版主
版主


查看用戶資訊
PIC18F4550 已經量產很久了,查了一下 Silicon B5 版本的 Errata 也沒有相關的I2C Slave 問題,所以我個人認為還是要找一下程式的 Bug。

發表於: 2007/11/21 14:57
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC18F4550 I2C 的address 問題___part 2
#1
初級會員
初級會員


查看用戶資訊
Dear 大大
雖然我的slaver PIC的SSPADD設0x02 , SSPCON2的GCEN設1,
但我的master PIC的I2C 第一個byte(address) 從1送到255 ,
slaver PIC也不會有中斷發生 , 只有address送0x00 , slaver PIC才發生中斷 . . . . . . 這是PIC的問題嗎??????

發表於: 2007/11/19 22:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------