[I2C] 請問如何在Master程式端 連續讀取 2 bytes 以上 的資料 謝謝
if (!I2C_ACKPolling(0xA0))
{
EEPROM_ByteRead(0xAF , 0x57);
**************************
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 ;
StopI2C( ) ;
while ( I2CCONbits.PEN ) ;
return (int)Temp_Buffer ;
}