STM32掉电检测

void PVD_Iint(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
EXTI_ClearITPendingBit(EXTI_Line16);
EXTI_InitStructure.EXTI_Line = EXTI_Line16;// 
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//µçѹÉÏÉý»òϽµÔ½¹ýÉ趨·§ÖµÊ±¶¼²úÉúÖжϡ£
EXTI_InitStructure.EXTI_LineCmd = ENABLE; 
EXTI_Init(&EXTI_InitStructure);// ³õʼ
PWR_PVDLevelConfig(PWR_PVDLevel_2V9); 
PWR_PVDCmd(ENABLE);// ʹÄÜPVD

// 
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÖжϷÖ×éÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void PVD_IRQHandler(void)
{
CPU_SR_ALLOC();
YELLOWON;
if(EXTI_GetITStatus(EXTI_Line16) != RESET)
{
OS_CRITICAL_ENTER(); 
recordAddrtemp[0]=(u8)(recordAddr>>8);
recordAddrtemp[1]=(u8)recordAddr;
SPI_FLASH_BufferWrite(recordAddrtemp,2,sizeof(recordAddrtemp));
OS_CRITICAL_EXIT();  
EnableSend3();
delay_us(100);
USART_SendData(USART3,0xBB);
while (USART_GetFlagStatus(USART3,USART_FLAG_TC) !=SET);
EnableRec3();
delay_us(100);
EXTI_ClearITPendingBit(EXTI_Line16);
}
}

转载于:https://www.cnblogs.com/red-123/p/5457282.html

你可能感兴趣的:(嵌入式)