• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   1 Anonymous Users






[I2C] Address Match issue 請問如何在程式 加入 Address Match 的機制
#1
新會員
新會員


查看用戶資訊
請問如何在程式 加入 Address Match 的機制
[Master 端]

if (!I2C_ACKPolling(0xA0))
{
fs_value0 = EEPROM_ByteRead(0xA1 , 0x50);
fs_value1 = EEPROM_ByteRead(0xA1 , 0x50);
fs_value2 = (fs_value1 << 8) | (fs_value0);

**
int EEPROM_ByteRead(unsigned char CMD , unsigned char Addr )
{
unsigned char Temp_Buffer,Temp_Buffer1,Temp_Buffer2,t1,t2,t3 ;
unsigned ReadDelay ;
IdleI2C( ) ;
StartI2C( ) ;
while ( I2CCONbits.SEN) ;
IFS0bits.MI2CIF = 0 ;
MasterWriteI2C((CMD & 0xFE)) ;
// Mask bit 0 -> Write command
while(! IFS0bits.MI2CIF ) ;
if ( I2CSTATbits.ACKSTAT )
REPORT_NACK
IFS0bits.MI2CIF = 0 ;
MasterWriteI2C(Addr) ;
while(! IFS0bits.MI2CIF ) ;

if ( I2CSTATbits.ACKSTAT )
REPORT_NACK

IFS0bits.MI2CIF = 0 ;
RestartI2C( ) ;
while ( I2CCONbits.RSEN) ;

IFS0bits.MI2CIF = 0 ;
MasterWriteI2C((CMD | 0x01)) ;
// Set bit 0 for "Read" command
while(! IFS0bits.MI2CIF ) ;

if ( I2CSTATbits.ACKSTAT )
REPORT_NACK

IFS0bits.MI2CIF = 0 ;

Temp_Buffer = MasterReadI2C( ) ;//read 1 byte
t1=Temp_Buffer;

while(! IFS0bits.MI2CIF ) ;

IFS0bits.MI2CIF = 0 ;
NotAckI2C( ) ;
while(! IFS0bits.MI2CIF ) ;
IFS0bits.MI2CIF = 0 ;
*************
#define SLAVE_ADDRESS (0xA0 >> 1) // I2C module compares bit<0..6> of I2CADD with bit<1..7> of I2C Command Byte

int EEPROM_ByteRead(unsigned char , unsigned char ) ;
int EEPROM_ByteWrite(unsigned char , unsigned char , unsigned char);
int I2C_ByteWrite(unsigned char CMD , unsigned char Addr , unsigned char Data);
void Init_I2C(void) ;
unsigned char I2C_ACKPolling(unsigned char ) ;
************************************

[Slave 端]
*****************
#define SLAVE_ADDRESS (0xA0 >> 1)

// I2C module compares bit<0..6> of I2CADD with bit<1..7> of I2C Command Byte

int EEPROM_ByteRead(unsigned char , unsigned char ) ;
int EEPROM_ByteWrite(unsigned char , unsigned char , unsigned char ) ;
void Init_I2C(void) ;
unsigned char I2C_ACKPolling(unsigned char ) ;



*******************
void _ISR _SI2CInterrupt(void)
{
IFS0bits.SI2CIF = 0 ;
DummyByte = I2CRCV ;
I2CSTATbits.I2COV = 0;


if (!I2CSTATbits.D_A && I2CSTATbits.S ) // address & stop bit
{
I2CState = 0 ; // Reset I2C State !!

if (I2CSTATbits.R_W ) // Read Command
{
if(t==0)
{
I2CTRN =AD15v;
t++;
}
if(t==3)
{
I2CTRN = AD15v>>8;
}

if(t==4) t=0;
t++;
if(t==1) t=0;
Nop( );
I2CCONbits.SCLREL = 1; // Release the clock
}else // Write Command
{

I2CState = 1 ;
Nop( );
//I2CBuf[I2CIndexAddress]=I2CRCV;
}

}
else if ( I2CSTATbits.P )
// 如果是 STOP , 直接將 I2CState 清除後結束
{
Nop();
I2CState = 0 ;


}//while (WaitLoop < 1000) ;

else // Write Command
{
if ( I2CState == 1 ) // Internal address byte
{
I2CState = 2 ;
I2CIndexAddress = DummyByte ;
if ( I2CIndexAddress >= 5 )
I2CIndexAddress = 5 ;
}

else if ( I2CState >= 2 )
{
I2CBuf2[i++] = DummyByte ;
if (i>6)i=0;
// tmp_2=DummyByte ;
}
else Nop();
}
}

發表於: 2008/11/10 10:31

Edited by kindpan on 2008年11月10日 11:22:25
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... ]

教育訓練中心

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