打印
[STM32F1]

STM32串口2怪异问题

[复制链接]
940|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mochou|  楼主 | 2016-1-1 00:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在调试STM32F105的串口1,发现开接收中断后,没有数据发给给USART1,接收缓冲区中数据也在变化,并在上位机发数据,进入中断,缓冲区中不是上位发的数据,请问怎么解决?谢谢。void SGL_USART1_Init(void)
{   
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    USART_DeInit(USART1);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
    USART_InitStructure.USART_BaudRate = 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;
    USART_Init(USART1, &USART_InitStructure);
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
    USART_Cmd(USART1, ENABLE);
   /* USART1 GPIO Configuration */
  /* Configure USART1 Tx (Pb.06) as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* Configure USART1 Rx (Pb.7) as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* USART1 NCIV Interrupt Configuration */
    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
   }


void USART1_IRQHandler(void)
{  
  if(USART_GetITStatus(USART1, USART_IT_RXNE)!=RESET)
  { /* Read one byte from the receive data register */
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);
    SGL_SCI1_RcvData[RxCounter++] = USART_ReceiveData(USART1);//USART1->DR;//(USART_ReceiveData(USART1) & 0x8F);  
    /* Clear the USART1 Receive interrupt */
  }
         if(USART_GetFlagStatus(USART1,USART_FLAG_ORE)!=RESET)
    {
        USART_ClearFlag(USART1,USART_FLAG_ORE);    //?SR
        USART_ReceiveData(USART1);                //?DR
   }

}




沙发
haoyupei| | 2016-1-1 01:41 | 只看该作者
本帖最后由 haoyupei 于 2016-1-1 01:43 编辑

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

你得优先级分组了么,抢占式优先级 有设为0的么?
GPIOA的端口时钟好像也没有看到 开启的代码

使用特权

评论回复
板凳
airwill| | 2016-1-1 07:47 | 只看该作者
先检查一下端口情况,上拉正常吗?有没有杂波类的波形出现?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:原理图及多层PCB设计,嵌入式程序开发(MPC5634,MPC5604,STM32,9S12,9S08,AVR,51,ARM7等),擅长汽车电子开发。联系QQ:1754281889.上海。

58

主题

1427

帖子

8

粉丝