I²C Byte Write
Please put this data at this address…
An I²C byte write is used to write a byte of data to a specific address.
EEPROM Byte Write Procedure
- Check for bus idle
- Send start condition, wait for it to complete
- Write control byte (with device address)
- Check for bus idle
- Write high byte of memory address
- Check for bus idle
- Write low byte of memory address
- Check for bus idle
- Write byte of data
- Check for bus idle
- Send stop condition, wait for it to complete
- Wait for write cycle to complete (ACK from EEPROM)
Example Code (PIC18)
Specific I²C function names and parameters may differ depending on your target device, compiler and/or peripheral library.
IdleI2C(); | // Ensure module is idle |
StartI2C(); while (SSPCON2bits.SEN); |
// Initiate START condition // Wait until START condition is over |
WriteI2C(0xA0); | // Write 1 byte - R/W bit should be 0 |
IdleI2C(); | // Ensure module is idle |
WriteI2C(HighAddress); | // Write high address byte to EEPROM |
IdleI2C(); | // Ensure module is idle |
WriteI2C(LowAddress); | // Write low address byte to EEPROM |
IdleI2C(); | // Ensure module is idle |
WriteI2C(Data); | // Write data byte to EEPROM |
IdleI2C(); | // Ensure module is idle |
StopI2C(); while (SSPCON2bits.PEN); |
// Send STOP condition // Wait until STOP condition is over |
while (EEAckPolling(0xA0)); | // Wait for write cycle to complete |