2023-10-08 04:08 AM
I am very new to STM32 platform and this is our first project on STM32. We are facing issues with STM32LCVT6TR RTC.
This RTC has Alarm A and Alarm B set at predefined times and go into the shutdown mode and they should wake up on predefined alarms A and B. Alarms A work perfectly but processor does not wake up on Alarm B.
We are using Shutdown mode of the STM32 where processor goes into the shutdown mode. We have also found that when processor wakes up on Alarm A, the minute value of Alarm B is sets the wrong value even if we ensured in debug correct value is passing to the function.
Here is my code:
/* This function calls in main.c while initialise */
void InitialiseApplication(void)
{
uint8_t WakeupStatus;
RTC_AlarmTypeDef RTC_AlarmTime_A;
RTC_AlarmTypeDef RTC_AlarmTime_B;
RTC_TimeTypeDef RTC_CurrentTime;
HAL_RTC_GetAlarm(&hrtc, &RTC_AlarmTime_A, RTC_ALARM_A, RTC_FORMAT_BIN);
HAL_RTC_GetAlarm(&hrtc, &RTC_AlarmTime_B, RTC_ALARM_B, RTC_FORMAT_BIN);
HAL_RTC_GetTime(&hrtc, &RTC_CurrentTime, RTC_FORMAT_BIN);
LoadDefaultParameters(); /* Loading configuration data from the memory */
/* This function checks whether there is wake up RTC Alarm A or Alarm B or GPIO on */
WakeupStatus= CheckWakeUpStatus(configData.Alarm_A_Hour,configData.Alarm_A_Minute,configData.Alarm_B_Hour,configData.Alarm_B_Minute);
/* Sends default transmit commands and get the ack and stops the action and comes back to shutdown */
transmit_AT_commands();
/* If wake up on RTC alarm B, then set next alarm as A and shutdown*/
if (WakeupStatus == AUTO_B)
{
set_alarm_A(configData.Alarm_A_Hour, configData.Alarm_A_Minute);
ApplicationShutdown(); //Goes to shutdown mode of MCU
}
/* if wake up on Alarm A and two alarms are configured, then set next alarm as B */
else if(WakeupStatus == AUTO_A && configData.set_two_alarm == true)
{
set_alarm_B(configData.Alarm_B_Hour, configData.Alarm_B_Minute);
HAL_Delay(200);
HAL_RTC_GetAlarm(&hrtc, &RTC_AlarmTime_B, RTC_ALARM_B, RTC_FORMAT_BCD);
HAL_Delay(200);
ApplicationShutdown();
}
else
/* Wake up on GPIO */
{
StartConfigurationMode();
}
}
uint8_t CheckWakeUpStatus(uint8_t Alarm_A_Hr,uint8_t Alarm_A_Min,uint8_t Alarm_B_Hr,uint8_t Alarm_B_Min)
{
uint8_t WakeUPMode;
HAL_RTC_GetTime(&hrtc, &RTC_CurrentTime, RTC_FORMAT_BIN);
if(((Alarm_A_Hr) == (RTC_CurrentTime.Hours)) && ((Alarm_A_Min)==(RTC_CurrentTime.Minutes)))
{
WakeUPMode = AUTO_A;
}
/* Here is a problem when we check here for minute value, it value comes wrong even though we set the right minute value */
else if((Alarm_B_Hr==RTC_CurrentTime.Hours) && (Alarm_B_Min==RTC_CurrentTime.Minutes))
{
WakeUPMode = AUTO_B;
}
else
{
WakeUPMode = MANUAL;
}
return WakeUPMode;
}
void ApplicationShutdown(void)
{
/* setting off few I/Os before shutdown */
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_2,GPIO_PIN_RESET);
HAL_Delay(50);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(500);
/* go to shutdown */
enter_shutdown_mode();
}
void enter_shutdown_mode(void)
{
/** Now enter the standby mode **/
/* Clear the WU FLAG */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* clear the RTC Wake UP (WU) flag */
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
/* Set TAMP back-up register TAMP_BKP31R to indicate
later on that system has entered shutdown mode */
HAL_PWREx_DisableInternalWakeUpLine();
HAL_PWREx_EnableInternalWakeUpLine();
WRITE_REG( TAMP->BKP31R, 0x1 );
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_C, GPIO_PIN_13);
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_A, GPIO_PIN_0);
HAL_PWREx_EnablePullUpPullDownConfig();
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
HAL_PWR_DisableWakeUpPin( PWR_WAKEUP_PIN1 );
HAL_PWR_EnableWakeUpPin( PWR_WAKEUP_PIN1_LOW );
/* Enter the Shutdown mode */
HAL_PWREx_EnterSHUTDOWNMode();
}
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
static void MX_RTC_Init(void)
{
/** 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.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
}
2023-10-08 04:27 AM
My Apologies:
Our processor is STM32L412CBTX
Please help in solving the same.
Regards,
Vinod Joshi