Skip to main content
baris.akpinar
Associate II
August 9, 2023
Solved

Calculation of RTC in certain months(Months with 31)

  • August 9, 2023
  • 8 replies
  • 2128 views

Hello everyone,
In my sample project I have created, RTC does not perceive certain months as 31 days. Although it is 31 days in July, October, December, I took the same result in my essays with a code sample with an RTC code.I don't have problems in January, March, and August.
What are your ideas?

 

July 30 -> 01 august (Problem)

Func:

HAL_RTC_SetTime(&hrtc,&updateTime,RTC_FORMAT_BIN);
HAL_RTC_SetDate(&hrtc,&updateDate,RTC_FORMAT_BIN);

Card I used: F407VG 168mhz 

This topic has been closed for replies.
Best answer by TDK

Did you fix your code?

Not sure what you're looking for here. The off-by-one error was clearly the issue.

8 replies

TDK
August 9, 2023

Sure you're not setting the month off by 1? What is your code to set the date to july 30th?

"If you feel a post has answered your question, please click ""Accept as Solution""."
baris.akpinar
Associate II
August 9, 2023

 

I set up RTC for the time I wanted and then read it.

updateTime.Seconds=SECONDS; // 45
updateTime.Minutes=MINUTES; // 59
updateTime.Hours =HOUR; //23
 
updateDate.Date = DAY; // 30
updateDate.Month = MONTH; // 06
updateDate.Year = YEAR;
 
HAL_RTC_SetTime(&hrtc,&updateTime,RTC_FORMAT_BIN);
HAL_RTC_SetDate(&hrtc,&updateDate,RTC_FORMAT_BIN);
TDK
August 9, 2023

July is 7, not 6.

"If you feel a post has answered your question, please click ""Accept as Solution""."
baris.akpinar
Associate II
August 10, 2023

My problem is still going on.

TDK
TDKBest answer
August 10, 2023

Did you fix your code?

Not sure what you're looking for here. The off-by-one error was clearly the issue.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
August 10, 2023

With MONTH = 7?

JW

baris.akpinar
Associate II
August 11, 2023

July = 6(Including zero)