static void Delay(__IO uint32_t nCount) //延时函数
{
for(; nCount != 0; nCount--);
}
static void SYSCLKConfig_STOP(void) //停机唤醒后配置系统时钟
{
/* After wake-up from STOP reconfigure the system clock */
/* 使能 HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* 等待 HSE 准备就绪 */
while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
/* 使能 PLL */
RCC_PLLCmd(ENABLE);
/* 等待 PLL 准备就绪 */
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
/* 选择PLL作为系统时钟源 */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* 等待PLL被选为系统时钟源*/
while (RCC_GetSYSCLKSource() != 0x08);
}
void USARTx_Config(uint32_t BAUDRATE)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(USARTx_TX_Clk | USARTx_RX_Clk | USARTx_AFIO_Clk,ENABLE);
GPIO_InitStructure.GPIO_Pin = USARTx_TX_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(USARTx_TX_Port,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = USARTx_RX_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USARTx_RX_Port,&GPIO_InitStructure);
USART_DeInit(USARTx);
USART_InitStructure.USART_BaudRate = BAUDRATE;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USARTx,&USART_InitStructure);
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USARTx,ENABLE);
}
void EXTI_PA10_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource10);
EXTI_InitStructure.EXTI_Line = EXTI_Line10;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
EXTI_Init(&EXTI_InitStructure);
}
int main(void)
{
LED_GPIO_Config();
USARTx_Config(115200);
EXTI_PA10_Config();
printf("
停止模式实验
");
while(1)
{
Delay(0x1FFFFF); // 延时,不那么快进入停止模式
printf("
进入停止模式,LED灯亮
");
LED(ON);
/* 进入停止模式,设置电压调节器为低功耗模式,等待中断唤醒 */
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
//从停止模式下,被唤醒后使用的是HSI时钟,此处重启HSI时钟,使用PLLCLK
SYSCLKConfig_STOP();
Delay(0x0FFFF); //延时
printf("
已退出停止模式
");
}
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line10) != RESET)
{
LED(OFF);
EXTI_ClearITPendingBit(EXTI_Line10);
}
}
//接收字符
void USART1_IRQHandler(void)
{
uint8_t ucTemp;
if(USART_GetITStatus(USARTx,USART_IT_RXNE)!=RESET)
{
ucTemp = USART_ReceiveData(USARTx);
printf("串口发送字符为:");
printf("%c
",ucTemp);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>