2020-02-17 07:32 AM
I have problems when I read continuously the RTC time in stm32f446 at 180MHz, after some readings, this gives me the same value. To find a solution, I implement a delay of 1 second to read the RTC and this solves the problem, however, I don't know what is the source of the issue. I am using HAL library for read the RTC.
Solved! Go to Solution.
2020-02-17 11:56 AM
OK, so
- set the BYPSHD bit when setting up the RTC, or
- always read date after reading time,
or do both.
JW
2020-02-17 09:05 AM
> I read continuously the RTC time
How exactly?
Are you aware of the RTC_CR.BYPSHAD bit and that if it's cleared, you have to read RTC->DR after you've read RTC->TR? Read Reading the calendar chapter in RM.
JW
2020-02-17 09:21 AM
Yes, I dont perform any change to RTC_CR.BYPSHAD bit so I suppose that this uses the deafult value which is cleared, however, I was looking to check this by using stm32ide with SFRs view tool, but the bit is not including here, however, the total register is showed and this effectivly is cleared. I attach the picture.
I am using the HAL library to get the time, so I assume it is correct. Here de code:
/**
* @brief Gets RTC current time.
* @param hrtc pointer to a RTC_HandleTypeDef structure that contains
* the configuration information for RTC.
* @param sTime Pointer to Time structure
* @param Format Specifies the format of the entered parameters.
* This parameter can be one of the following values:
* @arg RTC_FORMAT_BIN: Binary data format
* @arg RTC_FORMAT_BCD: BCD data format
* @note You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds
* value in second fraction ratio with time unit following generic formula:
* Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit
* This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS
* @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
* in the higher-order calendar shadow registers to ensure consistency between the time and date values.
* Reading RTC current time locks the values in calendar shadow registers until current date is read.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
{
uint32_t tmpreg = 0U;
/* Check the parameters */
assert_param(IS_RTC_FORMAT(Format));
/* Get subseconds structure field from the corresponding register */
sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);
/* Get SecondFraction structure field from the corresponding register field*/
sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S);
/* Get the TR register */
tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
/* Fill the structure fields with the read parameters */
sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16U);
sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U);
sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16U);
/* Check the input parameters format */
if(Format == RTC_FORMAT_BIN)
{
/* Convert the time structure parameters to Binary format */
sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
}
return HAL_OK;
}
2020-02-17 11:56 AM
OK, so
- set the BYPSHD bit when setting up the RTC, or
- always read date after reading time,
or do both.
JW
2020-02-17 01:06 PM
That is, I was just reading time without read date, now for each time reading operation I make read date operation and this solve the problen.
Thank you very much.