Page 1 of 1

DS3231 not display correct year and day of week

Posted: Tue Jan 24, 2017 4:54 pm
by maharadga
Hi.
I found bug with component DS3231 v1.68 from here => http://www.matrixtsl.com/mmforums/viewt ... 58&t=14566
I set in properties date format DDMMYYYY. When I set year to correct 2017, DS3231 return 2065. When date format is DDMMYY it's no problem. Interesting is that day of the week is not true on 2065 and correct in 2017.
I attach simple project.

Re: DS3231 not display correct year

Posted: Tue Jan 24, 2017 5:55 pm
by Benj
Hello,

The year can only be stored as a two digit number 00 to 99 on the DS3231 device, maybe this is the cause of the issue?

So at the moment you would store the number as 17 and then when printing out the year you could add the century.

"20" + ToString(Year)

Re: DS3231 not display correct year

Posted: Wed Jan 25, 2017 2:55 pm
by maharadga
Aha, this explain all. Thanks, Benj for your time to explain me.
But why day of week not correspond truth day? I try different date and month for example:

1.1.2000 must be Sat => shows Sun
3.2.2004 must be Tue => shows Sat
1.1.2012 must be Sun => shows Wed
6.8.2010 must be Fri => shows Tue
26.1.2017 must be Thu => shows Mon
30.5.2020 must be sat => shows Sun

I don't see any sequence. Is there no way I write correct day of week and DS3231 begin work correctly after that?

Re: DS3231 not display correct year

Posted: Wed Jan 25, 2017 3:08 pm
by LeighM
Hi,
A Day (of the week) counter will just increment each day.
So if you set it to 1 on a Monday, it will read as 2 the following day, then 1 again next Monday.
It will not work out the day of the week for any given date.

Re: DS3231 not display correct year

Posted: Thu Jan 26, 2017 6:41 am
by maharadga
I understand, thank you.
But how set day of week? I didn't see write option, only read?
I tune day as calculated depending on what value displayed and add or subtract the required days. But I think that the various chips will return a different value. Or at a different date will back a different day of the week and my method will not be accurate.

Re: DS3231 not display correct year

Posted: Sat Jan 28, 2017 4:22 pm
by maharadga
I try write day of week, but Flowcode return mistake wenn compile. I added C code:

FCD_005f1_I2C_Master1__Start();
FCD_005f1_I2C_Master1__TransmitByte(0xD0);
FCD_005f1_I2C_Master1__TransmitByte(3);
FCD_005f1_I2C_Master1__TransmitByte(day_of_Week);
FCD_005f1_I2C_Master1__Stop();

after my macro adjust_Date with the intention to record the set value. I use variable day_of_Week to set correct day.
The mistake is in red color. What should I do?
When try write some value for example 5 instead day_of_Week no mistake. I sure the answer is simple, but I don't know it.
I'm not expert in C.

Re: DS3231 not display correct year

Posted: Sat Jan 28, 2017 5:32 pm
by kersing
maharadga wrote: FCD_005f1_I2C_Master1__TransmitByte(day_of_Week);
If your Flowcode variable is called day_of_Week the C variable is called FCV_DAY_OF_WEEK or FCL_DAY_OF_WEEK. The easiest way to get the variable name right is to drag the variable from the right pane with the variables in the C code editor.

Re: DS3231 not display correct year

Posted: Sun Jan 29, 2017 12:04 pm
by maharadga
Hello kersing, I try that, what you say but can't make success. Finally I made switch with this variable and solve problem.
As an amateur, but an amateur resourceful :D

I attach my sample, which work very correct, with leap year compensation / tryed this/, writable correct Day of Week and tree buttons for adjust time and day.
In next stage I add alarms. Last two days was very difficult understand I2C protocol, but I success. Hope this sample helps beginners like me understand DS3231 better.
Have a nice day.