cancel
Showing results for 
Search instead for 
Did you mean: 

HAL RTC

Sandeep Dhokne
Associate II
Posted on October 09, 2017 at 13:52

@

Hi,

I did my project in cubemx  with STM32F405.

But unfortunately i forgot to add/initialize rtc in cubemx.

Now i want to add rtc in my project.

And i don't know how to add it (because my code size is too much heavy and i dont want to do rework in cubemx).

Can you please tell me how can i do this without cubemx?   

Thank you.

#

15 REPLIES 15
Posted on October 09, 2017 at 14:32

Could you create a donor project and use WinMerge to pull the incremental additions? Could you review the RTC examples under the Cube directories and merge the required code?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 10, 2017 at 06:08

I'm sorry but i don't know WinMerge Concept? 

I will create one more project in cubemx with rtc initialization and whatever the rtc code (initialization and other) i will add in my existing project.

Is it possible / is a right way to do this?

Thank you.

Sandeep Dhokne
Associate II
Posted on October 12, 2017 at 11:49

Problem not solved.

st.mcu

please help.

Posted on October 12, 2017 at 14:03

Perhaps you should study diff and merge concepts so you can apply then here.

You can manually cut and paste code if that's a more comfortable method 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 12, 2017 at 14:09

 ,

 ,

Generate a project with STM32CubeMX application consisting of nothing but the RTC. , in the project settings, choose 'generate as separate .c/.h files' and add the rtc.h and rtc.c files to your project. , If you want to use alarms, add void RTC_Alarm_IRQHandler(void), to stm32f4xx_it.h. , Uncomment the RTC module from stm32f4xx_hal_conf.h. , Add ♯ include 'rtc.h' to main.c, and in main() add MX_RTC_Init(),

Posted on October 13, 2017 at 05:50

Thank you.

Sandeep Dhokne
Associate II
Posted on October 13, 2017 at 12:29

Now rtc initialized without any error and show some value.

while(HAL_RTC_GetTime(&hrtc,&sTime,RTC_FORMAT_BCD)!= HAL_OK)

while(HAL_RTC_GetDate(&hrtc,&sDate,RTC_FORMAT_BCD)!= HAL_OK)

sprintf(MyStr, '%d:%d:%d:%d - %d/%d/%d $',sTime.Hours,sTime.Minutes,sTime.Seconds,sTime.SubSeconds,sDate.Date,sDate.Month,sDate.Year);

LCD_ShowString((32*6),0,MyStr,32);

sTime.Minutes:-Increment one by one.

sTime.Seconds:Increment but in a wrong way.

for example increment like 1,2,3..and directly jumped to 10,11,12...

And one interesting thing is second overflow means gave values which are more than 60 (eg.60,61,63....)

how it is possible?

what is the issue?

Thank you.

Posted on October 13, 2017 at 13:29

You are using BCD, you need to use %02X not %d 

Fifty nine seconds is 0x59

If you want binary numbers use the BIN mode.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 13, 2017 at 13:35

uint8_t bcdToDec(uint8_t val) {
// Convert binary coded decimal to normal decimal numbers
 return ( (val/16*10) + (val%16) );
}
�?�?�?�?