在stop1模式下,设置rtc,gpio中断,usart1都可唤醒mcu,但是在rtc和gpio中断唤醒后,发现串口不能收发数据了,再次休眠后串口能唤醒。但是在由usart1唤醒的情况下,串口还是可以通讯使用,请问哪位高手能指点下!
void PrepareUSARTToStopMode(void)
{
/* Empty RX Fifo before entering Stop mode 1 (Otherwise, characters already present in FIFO
will lead to immediate wake up */
while (LL_USART_IsActiveFlag_RXNE(USART1))
{
/* Read Received character. RXNE flag is cleared by reading of RDR register */
ubReceivedChar = LL_USART_ReceiveData8(USART1);
}
/* Clear OVERRUN flag */
LL_USART_ClearFlag_ORE(USART1);
/* Make sure that no USART transfer is on-going */
while(LL_USART_IsActiveFlag_BUSY(USART1) == 1)
{
}
/* Make sure that USART is ready to receive */
while(LL_USART_IsActiveFlag_REACK(USART1) == 0)
{
}
/* About to enter stop mode: switch off LED */
//LED_G_TogglePin;
/* Configure USART1 transfer interrupts : */
/* Clear WUF flag and enable the UART Wake Up from stop mode Interrupt */
LL_USART_ClearFlag_WKUP(USART1);
LL_USART_EnableIT_WKUP(USART1);
/* Enable Wake Up From Stop */
LL_USART_EnableInStopMode(USART1);
}
void Configure_USART1(void)
{
/* (1) Enable GPIO clock and configures the USART1 pins **********************/
/* (TX on PA.9, RX on PA.10) **********************/
/* Enable the peripheral clock of GPIOA */
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
/* Configure TX Pin as : Alternate function, High Speed, PushPull, Pull up */
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_9, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_9, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_9, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_9, LL_GPIO_PULL_NO);
/* Configure RX Pin as : Alternate function, High Speed, PushPull, Pull up */
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_10, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_10, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_10, LL_GPIO_PULL_NO);
/* (2) NVIC Configuration for USART1 interrupts */
/* - Set priority for USART1_IRQn */
/* - Enable USART1_IRQn */
NVIC_SetPriority(USART1_IRQn, 0);
NVIC_EnableIRQ(USART1_IRQn);
/* (3) Enable the USART1 peripheral clock and clock source ****************/
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
/* Set USART1 clock source as HSI */
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_HSI);
/* (4) Configure USART1 functional parameters ********************************/
/* Disable USART1 prior modifying configuration registers */
/* Note: Commented as corresponding to Reset value */
// LL_USART_Disable(USART1);
/* TX/RX direction */
LL_USART_SetTransferDirection(USART1, LL_USART_DIRECTION_TX_RX);
/* 8 data bit, 1 start bit, 1 stop bit, no parity */
LL_USART_ConfigCharacter(USART1, LL_USART_DATAWIDTH_8B, LL_USART_PARITY_NONE, LL_USART_STOPBITS_1);
/* No Hardware Flow control */
/* Reset value is LL_USART_HWCONTROL_NONE */
// LL_USART_SetHWFlowCtrl(USART1, LL_USART_HWCONTROL_NONE);
/* Oversampling by 16 */
/* Reset value is LL_USART_OVERSAMPLING_16 */
// LL_USART_SetOverSampling(USART1, LL_USART_OVERSAMPLING_16);
/* Set Baudrate to 9600 using HSI frequency set to HSI_VALUE */
LL_USART_SetBaudRate(USART1, HSI_VALUE, LL_USART_OVERSAMPLING_16, 9600);
/* Set the wake-up event type : specify wake-up on RXNE flag */
LL_USART_SetWKUPType(USART1, LL_USART_WAKEUP_ON_RXNE);
// LL_USART_EnableIT_RXNE(USART1); //开启接收中断
/* (5) Enable USART1 **********************************************************/
LL_USART_Enable(USART1);
/* Polling USART initialisation */
//while((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1))))
//{
//}
}
void Stop_Mode_Config(void)
{
__HAL_RCC_PWR_CLK_ENABLE();
/* Ensure that MSI is wake-up system clock */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
/* USER CODE END 2 */
Configure_USART1();
PrepareUSARTToStopMode();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFI);
SystemClock_Config();
uart_init(9600);
IIC_Init();
//HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
共1条
1/1 1 跳转至页
请教stm32L475,stop1模式多种唤醒方式问题
共1条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 | |
【分享评测,赢取加热台】使用8051单片机驱动WS2812被打赏40分 |