Operácie

Zbernica i2c: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Bez shrnutí editace
Chamraz (diskusia | príspevky)
Bez shrnutí editace
Riadok 23: Riadok 23:
     i2c_init();                            // initialize I2C library
     i2c_init();                            // initialize I2C library


    // write 0x75 to EEPROM address 5 (Byte Write)
     // 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_write(0x75);                        // write value 0x75 to EEPROM
    i2c_stop();                            // set stop conditon = release bus
 
 
     // read previously written value back from EEPROM address 5  
     i2c_start_wait(Dev24C02+I2C_WRITE);    // set device address and write mode
     i2c_start_wait(Dev24C02+I2C_WRITE);    // set device address and write mode



Verzia z 10:07, 6. december 2012

K. Zbernica i2c: EEPROM

Prečítajte obsah predloženej pamäti EEPROM a zobrazte na PC.

Literatúra:


 #define Dev24C02  0xA2      // device address of EEPROM 24C02, see datasheet

 int main(void)
 {
     unsigned char ret;

     i2c_init();                             // initialize I2C library

     // 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(;;);
 }