I bought a maxim 3231 because I want to build an alarmclock. The device communicates over I2C. I figured the entire communication out. And I can write and read data to my will. When i am counting the seconds and minutes, it counts to 9 than jumps to 16 it continous counting to 25 from where it jumps to 36, when either the minutes or second reaches 89, it jumps back to 0. I am using an arduino mega and the serial monitor to debug. Stupid thing keeps making jumps of 7-8 sec/min. currently I solved the problem in my software, where I use second++ every time the sec counter toggle to another number so that it doesn't matter if the device jumps from 9 to 10, or from 9 to 16 like it tends to do -_- but this is as simple as using the f*ckn millis() function, thus renders this time module rather unneeded and useless, except for some accuracy.
in the code i am requesting one byte. but I can only do it with 7 bits, I dont need the MSB, i dont know if this causes the problem. any??
int c;
int x = 0;
int second = 0;
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(0b1101000); //rtc adress
Wire.write(0x00);
Wire.write(0x00); // set second counter at 0 when arduino starts up
Wire.endTransmission();
}
void loop()
{
Wire.beginTransmission(0b1101000);
Wire.write(0x00); // select second memory bank
Wire.endTransmission();
Wire.requestFrom(0b1101000, 1); // request 1 byte from RTC
if(Wire.available())
{
c = Wire.read(); // reads the seconds
}
if (c - x != 0) //solution for the 7 second gaps
{
second++;
if(second == 60) second = 0;
Serial.println(second);
}
x = c;
delay(1);
}