uint8_t I2C_ReadRegister(uint8_t deviceRegister) { uint8_t data = 0; // start and write address I2C_Start(DS1307); I2C_Write(deviceRegister); // set register pointer // repeated start for read from address we sent earlier I2C_Start(DS1307 + TW_READ); data = I2C_ReadNACK(); I2C_Stop(); return data; }
byte I2C_ReadRegister1(uint16_t deviceRegister) { byte data = 0; byte status; status=I2C_Start(); status=I2C_SendAddr(AT256); // send device bus address status=I2C_Write(deviceRegister>>8); //parte alta status=I2C_Write(deviceRegister); // parte baja status=I2C_Start(); status=I2C_SendAddr(AT256+READ); // restart as a read operation data = I2C_ReadNACK(); // read the register data I2C_Stop(); // stop while(TWCR & (1<<TWSTO)); return data; }