目前在做STM32F030休眠及唤醒调试.
使用的方式是多个外部中断唤醒+RTC定时周期唤醒
主要相关休眠代码如下:
void LowPower_CloseAllClcok(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_TS | RCC_AHBPeriph_CRC | RCC_AHBPeriph_FLITF | RCC_AHBPeriph_DMA1 ,DISABLE);
RCC_APB2PeriphClockCmd(/*RCC_APB2Periph_SYSCFG |*/ RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1 | RCC_APB2Periph_SPI1 | RCC_APB2Periph_USART1 |
RCC_APB2Periph_TIM15 | RCC_APB2Periph_TIM16 | RCC_APB2Periph_TIM17 | RCC_APB2Periph_DBGMCU,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM6 | RCC_APB1Periph_TIM14| RCC_APB1Periph_WWDG |
RCC_APB1Periph_SPI2 | RCC_APB1Periph_USART2 | RCC_APB1Periph_I2C1 | RCC_APB1Periph_I2C2 | RCC_APB1Periph_PWR | RCC_APB1Periph_DAC | RCC_APB1Periph_CEC,DISABLE);
}
/*==================================================================
* Function : LowPower_Enter
* Description :
* Input Para :
* Output Para :
* Return Value:
==================================================================*/
void LowPower_Enter(void)
{
DEBUG_MSG(LOWPOWER_DEBUG,("LowPower_Enter******* \r\n"));
SysTimer_DeInit();
LowPower_CloseAllClcok();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
LowPower_ConfigWakeUp();
g_sLowPowerInfo.LowPowerBits.Bits.bIsLowPower = 1;
EXTI_ClearITPendingBit(EXTI_Line0 | EXTI_Line1 | EXTI_Line4 | EXTI_Line6 | EXTI_Line7 | EXTI_Line9 | EXTI_Line11 | EXTI_Line15 | EXTI_Line17);
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}
/*==================================================================
* Function : LowPower_Exit
* Description :
* Input Para :
* Output Para :
* Return Value:
==================================================================*/
void LowPower_Exit(void)
{
if(!g_sLowPowerInfo.LowPowerBits.Bits.bIsWakeUp)
return;
g_sLowPowerInfo.LowPowerBits.Bits.bIsWakeUp = 0;
if(!g_sLowPowerInfo.LowPowerBits.Bits.bIsLowPower)
return;
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
LowPower_DisableWakeUp();
SystemInit();
g_sLowPowerInfo.LowPowerBits.Bits.bIsLowPower = 0;
}
void LowPower_SetWakeUp(void)
{
g_sLowPowerInfo.LowPowerBits.Bits.bIsWakeUp = 1;
}
================================================================================================================
主函数的大概处理
void Main(void)
{
.............
while(1)
{
............
LowPower_Exit();
...............
}
}
=======================================================================================================================
中断服务程序的处理,
void EXTI0_1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET){
EXTI_ClearITPendingBit(EXTI_Line0);
LowPower_SetWakeUp();
}
else if(EXTI_GetITStatus(EXTI_Line1) != RESET){
EXTI_ClearITPendingBit(EXTI_Line1);
LowPower_SetWakeUp();
}
}
void EXTI4_15_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line11) != RESET){
EXTI_ClearITPendingBit(EXTI_Line11);
LowPower_SetWakeUp();
}
else if(EXTI_GetITStatus(EXTI_Line15) != RESET){
EXTI_ClearITPendingBit(EXTI_Line15);
LowPower_SetWakeUp();
}
else if(EXTI_GetITStatus(EXTI_Line9) != RESET){
EXTI_ClearITPendingBit(EXTI_Line9);
LowPower_SetWakeUp();
}
else if(EXTI_GetITStatus(EXTI_Line7) != RESET){
EXTI_ClearITPendingBit(EXTI_Line7);
LowPower_SetWakeUp();
}
else if(EXTI_GetITStatus(EXTI_Line6) != RESET){
EXTI_ClearITPendingBit(EXTI_Line6);
LowPower_SetWakeUp();
}
else if(EXTI_GetITStatus(EXTI_Line4) != RESET){
EXTI_ClearITPendingBit(EXTI_Line4);
LowPower_SetWakeUp();
}
}
void RTC_IRQHandler(void)
{
if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
LowPower_SetWakeUp();
/* Clear the Alarm A Pending Bit */
RTC_ClearITPendingBit(RTC_IT_ALRA);
/* Clear EXTI line17 pending bit */
EXTI_ClearITPendingBit(EXTI_Line17);
}
}
测试发现,可以产生外部中断唤醒及RTC定时唤醒.
但是,MCU有时候进入STOP模式后,就无法再唤醒.(RTC也无法自动唤醒,外部中断也失效了.)
不知道大家对使用STM32 STOP模式后,多中断唤醒的方式是如何处理的?
|