串口配置程序如下,NVIC已經正確配置,GPIO也正確配置,
但是還是始終無法進入串口接收中斷。
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
/* USART1 configuration ----------------------------------------------- -------*/
/* USART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
- USART Clock disabled
- USART CPOL: Clock is active low
- USART CPHA: Data is captured on the middle
- USART LastBit: The clock pulse of the last data bit is not
output to
the SCLK pin
*/
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
/* Configure the USART1 synchronous paramters */
USART_ClockInit(USARTx, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = bound;//115200;
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;
/* Configure USART1 basic and asynchronous paramters */
USART_Init(USARTx, &USART_InitStructure);
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE);
USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);
/* Enable USART1 */
USART_Cmd(USARTx, ENABLE);
經查,注掉串口發送中斷使能就可以了。
//USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);
應該是二者不能同時使能吧。