各位大佬我按照例程初始化串口1,2和第三个低功耗串口,都作为普通串口使用,1,2两个串口可以中断接收和发送,第三个低功耗串口初始化后可以发送但进不了接收中断。这个串口的初始化偶什么特殊要求吗?希望可以得到指点。谢谢各位西边是初始化代码。 void Configure_USART_2(void) { /* (1) Enable GPIO clock and configures the USART pins *********************/ /* Enable the peripheral clock of GPIO Port */ LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB); /* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetAFPin_8_15(GPIOB, LL_GPIO_PIN_10, LL_GPIO_AF_4); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_10, LL_GPIO_OUTPUT_PUSHPULL); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_10, LL_GPIO_PULL_NO); /* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_11, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetAFPin_8_15(GPIOB, LL_GPIO_PIN_11, LL_GPIO_AF_4); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_11, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_11, LL_GPIO_OUTPUT_PUSHPULL); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_11, LL_GPIO_PULL_NO); /* (2) NVIC Configuration for USART interrupts */ /* - Set priority for USARTx_IRQn */ /* - Enable USARTx_IRQn */ NVIC_SetPriority(LPUART1_IRQn, 0); NVIC_EnableIRQ(LPUART1_IRQn); /* (3) Enable USART peripheral clock and clock source ***********************/ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPUART1); /* Set clock source */ LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI); /* (4) Configure USART functional parameters ********************************/ /* Disable USART prior modifying configuration registers */ /* Note: Commented as corresponding to Reset value */ // LL_USART_Disable(USARTx_INSTANCE); /* TX/RX direction */ LL_USART_SetTransferDirection(LPUART1, LL_USART_DIRECTION_TX_RX); /* 8 data bit, 1 start bit, 1 stop bit, no parity */ LL_USART_ConfigCharacter(LPUART1, LL_USART_DATAWIDTH_8B, LL_USART_PARITY_NONE, LL_USART_STOPBITS_1); LL_LPUART_SetBaudRate(LPUART1, HSI_VALUE, 115200); /* (5) Enable USART *********************************************************/ LL_USART_Enable(LPUART1); /* Polling USART initialisation */ while((!(LL_USART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_USART_IsActiveFlag_REACK(LPUART1)))) { } /* Enable RXNE and Error interrupts */ LL_USART_EnableIT_RXNE(LPUART1); //UART_HWCONTROL_NONE LL_USART_EnableIT_ERROR(LPUART1); } 中断接收程序 void LPUART1_IRQHandler(void) { /* Check RXNE flag value in ISR register */ if(LL_USART_IsActiveFlag_RXNE(LPUART1) && LL_USART_IsEnabledIT_RXNE(LPUART1)) { USART_CharReception_Callback_2(); } else { /* Call Error function */ Error_Callback_2(); } } 接收处理部分 void USART_CharReception_Callback_2(void) { __IO uint32_t received_char; /* Read Received character. RXNE flag is cleared by reading of RDR register */ received_char = LL_USART_ReceiveData8(LPUART1); if(received_char==0x55) { datasp=0; data_r[datasp]=received_char; datasp+=1; // } else if(datasp!=0) { data_r[datasp]=received_char; datasp+=1; if(data_r[2] == (datasp-4)) { switch(data_r[3]) { case 0xf0: ADD++; if(ADD==1) { //LED_On(); flag=1; } if(ADD==2) { //LED_Off(); flag=0; ADD=0; } break; case 0xf1: //LED_Off(); break; case 0xf2: break; default : break; } } } /* Echo received character on TX */ LL_USART_TransmitData8(LPUART1, received_char); //·¢ËÍ } |
谁可以指点下啊! |
仿真了下找到问题了,中断函数名错了,总是进入.S文件中的无限循环。把.S文件中的中断函数名改了下就可以了。 |
STM32L011D4芯片用SWD无法下载程序
求助:STM32L0系列标准库哪里下?
STM32L051低温时LPUART串口波特率异常
STM32L051单片机ADC如何彻底关闭?
STM32L051C8进入低功耗模式电流偏大
STM32L052C8T6通过I2C模拟读16位数
STM32L0的VLCD外接5V会有问题吗
求助!!使用STM32L073 IO口模拟IIC接口读写AT24CM01 程序不停...
STM32L072RB写Bank2 EEPROM不响应中断
STM32L031无法进入boot