/* Sample program of I2C access to RTC chip on Wytec EduBase board. * This program clears the second counter in BQ32000 RTC chip. * The second counter is read every second and print it. * The address of second counter in RTC is 0. * The second counter increments once every second and has the BCD format * * This program uses Energia Wire library. */ #include char SLAVEADDR = 0x68; // RTC BQ32000 address void setup() { // patch for a bug in Wire.begin() // http://forum.43oh.com/topic/7147-i2c-on-stellaris-launchpad/ Wire.begin(1); Wire.setModule(1); Wire.begin(); Serial.begin(9600); // start serial for output // the following pair clears the second counter in RTC const uint8_t data[2] = {0, 0}; // address 0, data 0 Wire.beginTransmission(SLAVEADDR); // start talking to RTC Wire.write(data, 2); // reset second count Wire.endTransmission(); // stop delay(500); } void loop() { // set address counter in slave to 0 (second counter) Wire.beginTransmission(SLAVEADDR); // start talking to RTC Wire.write(0); // send address 0 for second counter in RTC Wire.endTransmission(); // stop Wire.requestFrom(SLAVEADDR, 1); // request 1 byte from slave while(Wire.available()) // read while there is data { char c = Wire.read(); // read a byte Serial.print(c, HEX); // print the byte Serial.print('.'); if ((c & 0x0F) == 9) Serial.println(); } delay(1000); }