mcuyangyifan 发表于 2015-11-12 15:32:53

STM32F401RE NUCLEO求助,串口一直不能进中断

用STM32F401RE NUCLEO串口中断收发,配置函数如下:
void UARTConfiguration(void)
{
      GPIO_InitTypeDef GPIO_InitStructure;
      USART_InitTypeDef USART_InitStructure;
      NVIC_InitTypeDef      NVIC_InitStructure;      
      USART_ClockInitTypeDef USART_ClockInitStruct;

         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC,ENABLE);
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);

      GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_USART2);
      GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_USART2);
      
      GPIO_StructInit(&GPIO_InitStructure);      
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
      GPIO_Init(GPIOA,&GPIO_InitStructure);
      
//      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
//      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
//      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
//      GPIO_Init(GPIOA,&GPIO_InitStructure);

//      USART_DeInit(USART2);
//      USART_OverSampling8Cmd(USART2,ENABLE);
      USART_StructInit(&USART_InitStructure);
      USART_InitStructure.USART_BaudRate = 9600;
      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(USART2, &USART_InitStructure);
      USART_ClockStructInit(&USART_ClockInitStruct);   
USART_ClockInit(USART2, &USART_ClockInitStruct);
      USART_Cmd(USART2, ENABLE);
//      USART_ClearFlag(USART2,USART_FLAG_TC);
      USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
      
      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);      
      NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
      NVIC_Init(&NVIC_InitStructure);
}

串口一直不能进中断,而且如果在主函数中发数据,串口调试助手中也没有数据,求大神指点一下,或者直接给我一个STM32F401RE NUCLEO串口的例程

废鱼 发表于 2015-11-12 16:32:35

IO配置问题,TX为输出,RX为输入.

mcuyangyifan 发表于 2015-11-12 18:49:50

安 发表于 2015-11-12 16:32
IO配置问题,TX为输出,RX为输入.

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;这里配置为OUT??

拉肚肚 发表于 2015-11-12 19:12:02

只为领金币。。。:P

废鱼 发表于 2015-11-13 08:53:15

TX配置为输出,RX配置为输入。

lettingGO 发表于 2016-5-13 13:56:55

同问,楼主解决了吗?

nashchen17 发表于 2016-8-10 11:42:48

我最近也遇到類似問題,不知樓主加時間是否解決

学习痴狂 发表于 2017-7-11 15:39:14

楼主解决了吗?我也是这个问题

学习痴狂 发表于 2017-7-11 15:57:02

nashchen17 发表于 2016-8-10 11:42
我最近也遇到類似問題,不知樓主加時間是否解決

请问您解决了吗

学习痴狂 发表于 2017-7-11 15:57:20

lettingGO 发表于 2016-5-13 13:56
同问,楼主解决了吗?

请问您解决了吗

Land.lan 发表于 2018-9-14 14:26:55

我最近使用原子的例程也是同样的问题,有什么解决的方案了吗

寻觅左岸 发表于 2018-9-14 16:29:49

TX与RXmode设置不对啊

阳光少年LSL 发表于 2023-5-6 10:26:12

STM32F401RE NUCLEO的串口2和STINK接在了一起,硬件问题,可以把那个电阻焊下来,或者那串口助手的端口选择为STM32的那个端口。

阳光少年LSL 发表于 2023-5-6 10:29:22

STM32F401RE NUCLEO的串口2和STNIK接在了一起,这是硬件问题,可以把那个0电阻焊下来,或者用串口调试助手时,选择端口号,选择你那个STM32的端口,不要选择串口2 端口。

页: [1]
查看完整版本: STM32F401RE NUCLEO求助,串口一直不能进中断