问题描述:单片机进入Standby模式,wakeup能唤醒,但是时间久了就无法唤醒,不知道什么原因
STM32L496 HAL库
主函数:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
WKUP_Init();
/* USER CODE BEGIN 2 */
while (1)
{
/* USER CODE END WHILE */
HAL_GPIO_WritePin(Debug_GPIO_Port, Debug_Pin, GPIO_PIN_SET);
HAL_Delay(5000);
HAL_GPIO_WritePin(Debug_GPIO_Port, Debug_Pin, GPIO_PIN_RESET);
/* USER CODE BEGIN 3 */
Sys_Enter_Standby();//½øèë′y»úÄ£ê½
}
}
唤醒初始化:
void WKUP_Init(void)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOC_CLK_ENABLE(); //¿aÆôGPIOCê±Öó
GPIO_Initure.Pin=GPIO_PIN_5; //PC5
GPIO_Initure.Mode=GPIO_MODE_IT_RISING;//GPIO_MODE_IT_FALLING; //ÖD¶Ï,ϽμÑØ
GPIO_Initure.Pull=GPIO_PULLDOWN;//GPIO_PULLUP; //éÏà-
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¿ìËù
HAL_GPIO_Init(GPIOC,&GPIO_Initure);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5);//HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_C, PWR_GPIO_BIT_5);
HAL_PWREx_EnablePullUpPullDownConfig();
HAL_NVIC_SetPriority(EXTI9_5_IRQn,0x02,0x02);//ÇàÕ¼óÅÏ輶2£¬×óóÅÏ輶2
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
}
进入待机模式函数:
void Sys_Enter_Standby(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
__HAL_RCC_PWR_CLK_ENABLE(); //ê1ÄüPWRê±Öó
__HAL_RCC_BACKUPRESET_FORCE(); //¸′λ±¸·YÇøóò
HAL_PWR_EnableBkUpAccess(); //oó±¸Çøóò·ÃÎêê1Äü
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); //Çå3yWake_UP±êÖ¾
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN5); //éèÖÃWKUPóÃóú»½DÑ
HAL_PWR_EnterSTANDBYMode(); //½øèë′y»úÄ£ê½
}
中断函数:
void EXTI9_5_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>