嵌入式学习小组
直播中

程玲

7年用户 186经验值
私信 关注

为什么stm32f407zgt6串口接收中断不能全部接收?

       各位有没有遇到这样的问题。就是一帧串口数据过来,只能触发一帧数据中的头一个字符的中断,后来改变数据帧中的字符时间间隔后,能收到更多一点的数据,但是依然不能收全。望各位朋友能帮忙一二。以下是中断函数,NVIC配置和现象的截图以及485的配置代码。void USART_485_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE);
        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_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_USART3);        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;        
        GPIO_Init(GPIOB, &GPIO_InitStructure);                                                                                                                 
        GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_USART3);
        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(USART3,&USART_InitStructure);
        USART_ITConfig(USART3,USART_IT_RXNE,DISABLE);  
        USART_ITConfig(USART3,USART_IT_IDLE,ENABLE);
        USART_Cmd(USART3, ENABLE);
        USART_ClearITPendingBit(USART3, USART_IT_TC);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
        GPIO_Init(GPIOD, &GPIO_InitStructure);   
}

图1 NVIC配置

图2 中断函数配置

图3 接收效果
     图3中的接收效果,最顶上的接收数据为完整的一帧数据,数据帧都以c5开头。

回帖(4)

潘沪城

2019-11-7 07:23:01
自己顶起~
举报

李玲

2019-11-7 07:35:41
中断接收程序好像有问题,
只有IDLE标志满足条件才会保存数据。。。
这对吗?
举报

马超

2019-11-7 07:49:23
这个是可以得啊~它是!= RESET。。RESET为0。中断过来的时候这个位就是1.这样子可以的
举报

杨玲

2019-11-7 07:54:26
上班再把自己的帖子顶起~
举报

更多回帖

发帖
×
20
完善资料,
赚取积分