C Control PRO UNIT MEGA 32 198206 User Manual
Product codes
198206
78
Compiler
© 2005 Conrad Electronic
Tabelle: Status Codes Master
Receiver
Mode
Status Code
Beschreibung
0x08
eine START Sequenz wurde gesendet
0x10
eine "repeated" START Sequenz wurde gesendet
0x38
Konflikt in SLA+R or data bytes
0x40
SLA+R wurde gesendet, ACK wurde empfangen
0x48
SLA+R wurde gesendet, NACK wurde empfangen
0x50
Data byte wurde empfangen, ACK wurde gesendet
0x58
Data byte wurde empfangen, NACK wurde gesendet
5.3.8.9 I2C Beispiel
Beispiel: EEPROM 24C64 lesen und schreiben ohne I2C_Status Abfrage
// I2C Initialization, Bit Rate 100kHz
main(void)
{
word address;
byte data,EEPROM_data;
{
word address;
byte data,EEPROM_data;
address=
0x20
;
data=
0x42
;
I2C_Init(I2C_100kHz );
// write data to 24C64 (8k x 8) EEPROM
I2C_Start();
I2C_Write(
I2C_Write(
0xA0
);
// DEVICE ADDRESS : A0
I2C_Write(address>>
8
);
// HIGH WORD ADDRESS
I2C_Write(address);
// LOW WORD ADDRESS
I2C_Write(data);
// write Data
I2C_Stop();
AbsDelay(
AbsDelay(
5
);
// delay for EEPROM Write
Cycle
// read data from 24C64 (8k x 8) EEPROM
I2C_Start();
I2C_Write(
I2C_Write(
0xA0
);
// DEVICE ADDRESS : A0
I2C_Write(address>>
8
);
// HIGH WORD ADDRESS
I2C_Write(address);
// LOW WORD ADDRESS
I2C_Start();
// RESTART
I2C_Write(
0xA1
);
// DEVICE ADDRESS : A1
EEPROM_data=I2C_Read_NACK();
I2C_Stop();
Msg_WriteHex(EEPROM_data);
}
I2C_Stop();
Msg_WriteHex(EEPROM_data);
}