Forum: System Workbench for STM32

RTC Alarm doesn't work second time.. Please Help me..

I’m a rookie. I designed that RTC alarms works every 5 seconds and toggles LED. (SMT32F7)
but first handler works. but second one doesn’t work. how to make it

int main(void)
{

CPU_CACHE_Enable();

HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_RTC_ENABLE();
MX_GPIO_Init();
MX_RTC_Init();

while (1)
{
}
}

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
RTC_AlarmTypeDef sAlarm;
uint8_t tmpSeconds;

HAL_RTC_GetAlarm(hrtc, &sAlarm, RTC_ALARM_A, FORMAT_BIN);
if(sAlarm.AlarmTime.Seconds>50){
sAlarm.AlarmTime.Seconds=0;
}
else {
tmpSeconds = sAlarm.AlarmTime.Seconds;
sAlarm.AlarmTime.Seconds=tmpSeconds+0x05;
}

//sAlarm.AlarmTime.Minutes=sAlarm.AlarmTime.Minutes + 1;

HAL_GPIO_TogglePin(GPIOI, LED_ON_Pin);
while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BCD)!=HAL_OK)
{__NOP();}
}

void RTC_Alarm_IRQHandler(void)
{
HAL_RTC_AlarmIRQHandler(&hrtc);
}

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
/* Prevent unused argument(s) compilation warning */
UNUSED(hrtc);

/* NOTE : This function Should not be modified, when the callback is needed,
the HAL_RTC_AlarmAEventCallback could be implemented in the user file
*/
HAL_RTC_DeactivateAlarm(&hrtc,RTC_ALARM_A);
//__HAL_RCC_RTC_DISABLE();

MX_RTC_Init();
__HAL_RCC_RTC_ENABLE();

}