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

Post Reply
maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times

DS3231 not display correct year and day of week

Post 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.
Attachments
DS3231.fcfx
(50.07 KiB) Downloaded 456 times
Last edited by maharadga on Sun Jan 29, 2017 12:05 pm, edited 1 time in total.

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

Re: DS3231 not display correct year

Post 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)

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times

Re: DS3231 not display correct year

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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: DS3231 not display correct year

Post 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.

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times

Re: DS3231 not display correct year

Post 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.

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times

Re: DS3231 not display correct year

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

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: DS3231 not display correct year

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

― C.S. Lewis

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times

Re: DS3231 not display correct year

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

Post Reply