void rtcCorrSec(void) { I2CswStart(RTC_I2C_ADDR); I2CswWriteByte(RTC_SEC); I2CswWriteByte(rtcDecToBinDec((uint8_t)rtc.sec)); I2CswStop(); }
void I2CswStart(uint8_t addr) { IN(I2C_SCL); // Pullup SCL = 1 IN(I2C_SDA); // Pullup SDA = 1 _delay_us(5); OUT(I2C_SDA); // Active SDA = 0 _delay_us(5); OUT(I2C_SCL); // Active SCL = 0 I2CswWriteByte(addr); }
static void rtcSaveTime(void) { int8_t etm = rtc.etm; if (etm > RTC_WDAY) { rtcWeekDay(); etm = RTC_WDAY; } I2CswStart(RTC_I2C_ADDR); I2CswWriteByte((uint8_t)etm); if (etm == RTC_SEC) { I2CswWriteByte(0); } else { for (int8_t i = etm; i <= RTC_YEAR; i++) I2CswWriteByte(rtcDecToBinDec(*((uint8_t *)&rtc + i))); } I2CswStop(); }
void I2CswStart(uint8_t addr) { DDR(I2C_SCL) &= ~I2C_SCL_LINE; // Pullup SCL = 1 DDR(I2C_SDA) &= ~I2C_SDA_LINE; // Pullup SDA = 1 _delay_us(5); DDR(I2C_SDA) |= I2C_SDA_LINE; // Active SDA = 0 _delay_us(5); DDR(I2C_SCL) |= I2C_SCL_LINE; // Active SCL = 0 I2CswWriteByte(addr); return; }
void rtcReadTime(void) { uint8_t temp; uint8_t i; I2CswStart(RTC_I2C_ADDR); I2CswWriteByte(RTC_SEC); I2CswStart(RTC_I2C_ADDR | I2C_READ); for (i = RTC_SEC; i <= RTC_YEAR; i++) { temp = I2CswReadByte((i == RTC_YEAR) ? I2C_NOACK : I2C_ACK); *((int8_t *)&rtc + i) = (int8_t)rtcBinDecToDec(temp); } I2CswStop(); }