2020-08-04 04:27 AM
Hi,
I am using stm32l431 and work with LPTIM in stop2mode.
When the mcu wake up after stop mode, i2c stop working, so I need to restart mcu.
It's strange because in some cases the i2c work in the next 3 wake up, but after this dont work anymore. Should I init i2c after all wake up stop2mode ? I am using Alarm to wake up.
void sleep() {
if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUFI)) {
/* Clear Internal WU Flag (RTC) */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);
}
__HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
EXTI->PR1 = 0x00000000;
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
SystemClock_Config();
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
HAL_UART_Transmit(&huart3, (uint8_t*)"alarme callback\n\n", 17 ,HAL_MAX_DELAY);
}
2020-08-04 06:24 AM
Please do this code after wakeup and SystemClock_Config().
__HAL_I2C_DISABLE(&hi2c1);
__HAL_I2C_ENABLE(&hi2c1);
HAL_I2C_MspInit(&hi2c1);