cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030CCT6 RTC is giving invalid minutes and seconds information

Danish Joseph
Associate II
Posted on September 13, 2017 at 14:56

Hi Guys,

This is my first question in ST forum. Its is regarding RTC.

I am currently working on a project that uses STM32F030CCT6 controller. Project is already halfway through. 

I am using RTC clock for updating the time information to the server(requirement). 

CMSIS api's are using to set the date and time from GSM module to my controller RTC. What I am observing here is minutes and second parameters are counting to a value more than 59. 

OS: FreeRTOS and It is customized board.

How can I rectify this problem?

Please comment if anyone want more information to identifying the problem.

#freertos #rtc #stm32f030cct6 #rtc-hal
6 REPLIES 6
Posted on September 13, 2017 at 15:09

There must be a bug in your code. Post the relevant parts of the code (RTC initialization, time setting, time reading, etc.) so we can find it.

Posted on September 13, 2017 at 16:59

BCD vs binary? ie 0x59 ?

You'll need to dig into the source code and chip docs.

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

These are the part of code which set RTC date and Time

void StartDefaultTask(void const * argument)

{

   /* USER CODE BEGIN 5 */

   /* Registering UART RXNE interrupt */

   SET_BIT(huart1.Instance->CR1, USART_CR1_RXNEIE);

   GSMPowerUp();

   osDelay(15000);

   GSMDisableEcho();

   osDelay(5000);

   GSMGetTD(); /* Getting Date and time from GSM module */

   if (HAL_RTC_SetTime(&hrtc, &Time, RTC_FORMAT_BCD) != HAL_OK)

   {

            _Error_Handler(__FILE__, __LINE__);

   }

   if (HAL_RTC_SetDate(&hrtc, &Date, RTC_FORMAT_BCD) != HAL_OK)

   {

         _Error_Handler(__FILE__, __LINE__);

   }

   /* Infinite loop */

   for(;;)

   {

         osSemaphoreWait (GPSWakeUpSemaphoreHandle, portMAX_DELAY);

         osTimerStart(RemotePowerONOFFTimerHandle, 3 * ONE_MINUTE_TIME);

         osDelay(1);

   }

     /* USER CODE END 5 */

}

Only Hour, Minutes and Senconds parameters of the RTC Time structure I am updating. All other fields are left unchanged (TimeFormat, SubSeconds, SecondFraction, DayLightSaving, StoreOperation)

And Month, Date, and Year parameters of RTC Date structure is updating, WeekDay will be the default value.

Date and Time information from the GSM module is properly populating to the Time and Date Structures.

Note: CMSIS Api 'MX_RTC_Init' updating RTC at the time of initialization as follows.

static void MX_RTC_Init(void)

{

   RTC_TimeTypeDef sTime;

   RTC_DateTypeDef sDate;

   /**Initialize RTC Only

   */

   hrtc.Instance = RTC;

   hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

   hrtc.Init.AsynchPrediv = 127;

   hrtc.Init.SynchPrediv = 255;

   hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

   hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

   hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

   if (HAL_RTC_Init(&hrtc) != HAL_OK)

   {

   _Error_Handler(__FILE__, __LINE__);

   }

   /**Initialize RTC and set the Time and Date

   */

   sTime.Hours = 0x0;

   sTime.Minutes = 0x0;

   sTime.Seconds = 0x0;

   sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

   sTime.StoreOperation = RTC_STOREOPERATION_RESET;

   if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)

   {

   _Error_Handler(__FILE__, __LINE__);

   }

   sDate.WeekDay = RTC_WEEKDAY_MONDAY;

   sDate.Month = RTC_MONTH_JANUARY;

   sDate.Date = 0x1;

   sDate.Year = 0x0;

   if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)

   {

   _Error_Handler(__FILE__, __LINE__);

   }

}

I have used a 5 minute timer to get the RTC Time and Date. On the first timer hit the Time value is Hours = 0, Minutes = 5 and Seconds = 9 (This is just an example).

But for the remaining Timer hits Hours, Minutes and seconds values unchanged and only Subseconds value is changing.

Posted on September 14, 2017 at 08:45

BCD vs binary? ie   

0x59 

?

I didn't get the exact meaning.

Posted on September 14, 2017 at 12:41

The registers hold BCD digits where 0x59 > 59 yet is entirely valid. Trying to understand complaint while lacking data to see what you are actually observing. 

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

Problem 1, as guessed by

Turvey.Clive.002

, you are using

https://en.wikipedia.org/wiki/Binary-coded_decimal

but expecting binary, change all RTC_FORMAT_BCD mentions to RTC_FORMAT_BIN.

Problem 2, let me guess, you are calling HAL_RTC_GetTime() but forgetting to call HAL_RTC_GetDate() after that. Any time you get the time, you must also get the date to unlock the shadow registers (that is well-documented).