STOP模式:
static void RCC_Close(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB
|RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD |RCC_APB2Periph_GPIOE
|RCC_APB2Periph_ADC1 |RCC_APB2Periph_AFIO |RCC_APB2Periph_ADC2
|RCC_APB2Periph_SPI1, DISABLE );
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_UART4
|RCC_APB1Periph_TIM2 | RCC_APB1Periph_SPI2
|RCC_APB1Periph_CAN1 | RCC_APB1Periph_CAN2, DISABLE );
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE );
ADC_Cmd(ADC1, DISABLE); ADC_Cmd(ADC2, DISABLE);
ADC_DMACmd(ADC1, DISABLE); DMA_Cmd(DMA1_Channel1, DISABLE);
USART_Cmd(UART4, DISABLE);USART_Cmd(USART2, DISABLE);
SPI_Cmd(SPI2,DISABLE);
TIM_Cmd(TIM2,DISABLE);TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
CAN_DeInit(CAN1);CAN_DeInit(CAN2);
ADC_DeInit(ADC1);
USART_DeInit(USART2);USART_DeInit(UART4);
SPI_I2S_DeInit(SPI1);SPI_I2S_DeInit(SPI2);
DMA_DeInit(DMA1_Channel1);
TIM_DeInit(TIM2);
}
static void RTC_Config(u16 value)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
BKP_DeInit();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE);
RCC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//Ñ¡ÔñÄÚ²¿40KRC
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_WaitForLastTask();
RTC_SetPrescaler(39999);
RTC_WaitForLastTask();
RTC_SetAlarm(RTC_GetCounter() + value);
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_ALR,ENABLE);
RTC_WaitForLastTask();
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearFlag(EXTI_Line17);
EXTI_ClearITPendingBit(EXTI_Line17);
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void RTCAlarm_IRQHandler(void)
{
// ÇåEXTI_Line17¹ÒÆðλ
EXTI_ClearITPendingBit(EXTI_Line17);
// ¼ì²é»½ÐѱêÖ¾ÊÇ·ñÉèÖÃ
if(PWR_GetFlagStatus(PWR_FLAG_WU) != RESET)
{
PWR_ClearFlag(PWR_FLAG_WU);// Çå³ý»½ÐѱêÖ¾
}
RTC_WaitForLastTask();
RTC_ClearITPendingBit(RTC_IT_ALR);// ÇåRTC±¨¾¯ÖжϹÒÆð
}
typedef void (*pFunction) (void );
void jump(unsigned long add)
{
pFunction pMyaddr = (pFunction)add;
pMyaddr();
}
void STM32StopMode(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
u32 jmp_add;
if(!EnterStopMode_Flag)
{
EnterStopMode_Flag = 1;//1±íʾÒѾ½øÈëµÍ¹¦ºÄ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 0Xfffe;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_Close();
RTC_Config(10);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE);
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
// System_Reset() ;
// jmp_add=*(unsigned long*)(0x8008004);
// __set_MSP(*(__IO uint32_t*)0x8008000);
// jump(jmp_add);
}
}
void RTC_IRQHandler(void)
{
while(1);
}
STOP模式唤醒后是从停止的地址开始运行,仿真和实际运行不同,仿真时不会进入低功耗,相当于 进入低功耗又被唤醒了。
上一篇:STM32的HardFault_Handler问题调试方法
下一篇:STM32F105VC SPI3的重映射使用
推荐阅读最新更新时间:2024-03-16 16:17