Zbernica i2c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 21: | Riadok 21: | ||
unsigned char ret; | unsigned char ret; | ||
i2c_init(); // initialize I2C library | state = i2c_init(); // initialize I2C library | ||
if (state != 0) call_error(state); | |||
// read value from EEPROM address 5 | // read value from EEPROM address 5 |
Verzia z 10:09, 6. december 2012
K. Zbernica i2c: EEPROM
Prečítajte obsah predloženej pamäti EEPROM a zobrazte na PC.
Literatúra:
- M24C02 Datasheet
- Mitchell Kahn: Programming the i2c interface. Dr. Dobb's Journal, June 1992.
- Example using the two-wire interface (TWI). AVRlibc demo projects.
#define Dev24C02 0xA2 // device address of EEPROM 24C02, see datasheet
int main(void)
{
unsigned char ret;
state = i2c_init(); // initialize I2C library
if (state != 0) call_error(state);
// read value from EEPROM address 5
i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode
i2c_write(0x05); // write address = 5
i2c_rep_start(Dev24C02+I2C_READ); // set device address and read mode
ret = i2c_readNak(); // read one byte from EEPROM
i2c_stop();
for(;;);
}