Mikroelektronika MIKROE-350 Fiche De Données
program TWI_Simple
main:
DDRA = 0xFF ' configure PORTA as output
TWI_Init(100000) ' initialize TWI communication
TWI_Start() ' issue TWI start signal
TWI_Write(0xA2) ' send byte via TWI (device address + W)
TWI_Write(2) ' send byte (address of EEPROM location)
TWI_Write(2) ' send byte (address of EEPROM location)
TWI_Write(0xAA) ' send data (data to be written)
TWI_Stop() ' issue TWI stop signal
Delay_100ms()
TWI_Start() ' issue TWI start signal
TWI_Write(0xA2) ' send byte via TWI (device address + W)
TWI_Write(2) ' send byte (data address)
TWI_Start() ' issue TWI signal repeated start
TWI_Write(0xA3) ' send byte (device address + R)
PORTA = TWI_Read(0) ' read data (NO acknowledge)
TWI_Stop() ' issue TWI stop signal}
end.
HW Connection
Interfacing 24c02 to AVR via TWI
468
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6