maxim 3231

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

The time and date info from the DS3231 is read in BCD (binary coded decimal) format and this is probably where your seeing the errors. There are several libraries that work with the DS3231 & DS1307 RTC chips, I suggest either using one of them or at least looking to see how they work in conjunction with the datasheet.

BCD ofcourse, eh duhhh... -_-

im going to try the following :

code.......

c = Wire.read(); // reads the seconds in BCD

x = c << 4; // get the ten number and store it under x
c = c && 0b1111; // and mask for the units and store it under c

second = x + c; v= add the unit and the 10 number to get the true value

Serial.println(second);

code......

wait i just found something;

second = (val/16*10) + (val%16)

with val being the byte of the RTC

bask185:
second = (val/16*10) + (val%16)

That's pretty much the way the library code I have does it. It just does (val >> 4) to divide by 16 instead.
Don't forget you will also need to convert to BCD to set the date/time

well tnx for the help. I was going to use a 4 block 7-segment diplay. But to only give time when it can give the data and day as well. Im going to use an LCD 2x16 screen instead :

HH:MM:SS (8 chars)
DAY DD:MM:YYYY (14 chars)