DS3231 not display correct year and day of week

A forum where Flowcode v6 user created components can be shared, discussed and reviewed.

Moderator: Benj

maharadga
Posts: 57
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

DS3231 not display correct year and day of week

Postby maharadga » Tue Jan 24, 2017 4:54 pm

Hi.
I found bug with component DS3231 v1.68 from here => viewtopic.php?f=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.
Attachments
DS3231.fcfx
(50.07 KiB) Downloaded 137 times
Last edited by maharadga on Sun Jan 29, 2017 12:05 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 13948
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4224 times
Been thanked: 3980 times
Contact:

Re: DS3231 not display correct year

Postby Benj » Tue Jan 24, 2017 5:55 pm

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)
These users thanked the author Benj for the post:
maharadga (Wed Jan 25, 2017 2:56 pm)
Rating: 5.88%
 

maharadga
Posts: 57
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: DS3231 not display correct year

Postby maharadga » Wed Jan 25, 2017 2:55 pm

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?
Last edited by maharadga on Fri Jan 27, 2017 1:08 pm, edited 1 time in total.

User avatar
LeighM
Matrix Staff
Posts: 1749
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 414 times
Been thanked: 578 times
Contact:

Re: DS3231 not display correct year

Postby LeighM » Wed Jan 25, 2017 3:08 pm

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.
These users thanked the author LeighM for the post:
maharadga (Thu Jan 26, 2017 6:41 am)
Rating: 5.88%
 

maharadga
Posts: 57
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: DS3231 not display correct year

Postby maharadga » Thu Jan 26, 2017 6:41 am

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.

maharadga
Posts: 57
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: DS3231 not display correct year

Postby maharadga » Sat Jan 28, 2017 4:22 pm

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.
Last edited by maharadga on Sat Jan 28, 2017 5:51 pm, edited 1 time in total.

kersing
Valued Contributor
Valued Contributor
Posts: 1869
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 525 times
Been thanked: 1037 times
Contact:

Re: DS3231 not display correct year

Postby kersing » Sat Jan 28, 2017 5:32 pm

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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

maharadga
Posts: 57
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: DS3231 not display correct year

Postby maharadga » Sun Jan 29, 2017 12:04 pm

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.
Attachments
DS3231.fcfx
(50.85 KiB) Downloaded 164 times