OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3150|回复: 2

f4串口3无法示波器看发送有返回接收,但是不进中断

[复制链接]

55

主题

474

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2374
金钱
2374
注册时间
2017-8-7
在线时间
207 小时
发表于 2018-1-18 10:01:59 | 显示全部楼层 |阅读模式
5金钱
附上代码,是我配置问题吗,还是怎么回事,电源供电充足,硬件应该是没有问题的
void USART_Configuration(void)
{
       
        GPIO_InitTypeDef GPIO_InitStructure;//定义GPIO_InitTypeDef类型的结构体成员GPIO_InitStructure

        USART_InitTypeDef USART_InitStructure;
        USART_ClockInitTypeDef USART_ClockInitStruct;
        //使能USART1 时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);//Usart1
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//Usart2
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//Usart3
        ///复位串口1
        USART_DeInit(USART1);
       
        USART_StructInit(&USART_InitStructure);//载入默认USART参数
        USART_ClockStructInit(&USART_ClockInitStruct);//载入默认USART参数        
        //配置串口1的管脚 PA8 USART1_EN PA9 USART1_TX PA10 USART1_RX   
        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_9;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);        //管脚PA9复用为USART1
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;        
        GPIO_Init(GPIOA, &GPIO_InitStructure);                                                                                                                 
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
       
        USART_ClockInit(USART1,&USART_ClockInitStruct);

        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_ClearITPendingBit(USART1, USART_IT_TC);//清除中断TC位
        USART_Cmd(USART1,ENABLE);//最后使能串口

        ///复位串口2
        USART_DeInit(USART2);
       
        USART_StructInit(&USART_InitStructure);//载入默认USART参数
        USART_ClockStructInit(&USART_ClockInitStruct);//载入默认USART参数        
        //配置串口2的管脚 PD5 USART1_TX PD6 USART1_RX   
        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_5;
        GPIO_Init(GPIOD, &GPIO_InitStructure);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_USART2);        //管脚PD5复用为USART2
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;        
        GPIO_Init(GPIOD, &GPIO_InitStructure);                                                                                                                 
        GPIO_PinAFConfig(GPIOD,GPIO_PinSource6,GPIO_AF_USART2);
       
        USART_ClockInit(USART2,&USART_ClockInitStruct);

        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_ITConfig(USART2, USART_IT_RXNE, ENABLE);        //接收中断使能
        USART_ClearITPendingBit(USART2, USART_IT_TC);//清除中断TC位
        USART_Cmd(USART2,ENABLE);//最后使能串口


        ///复位串口3
        USART_DeInit(USART3);
       
        USART_StructInit(&USART_InitStructure);//载入默认USART参数
        USART_ClockStructInit(&USART_ClockInitStruct);//载入默认USART参数        
        //配置串口3的管脚 PB10 USART3_TX PB11 USART3_RX   
        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(GPIOC,GPIO_PinSource10,GPIO_AF_USART3);        //管脚PD5复用为USART2
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;        
        GPIO_Init(GPIOB, &GPIO_InitStructure);                                                                                                                 
        GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_USART3);
       
        USART_ClockInit(USART3,&USART_ClockInitStruct);

        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_RTS;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_Init(USART3,&USART_InitStructure);

        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);        //接收中断使能
        USART_ClearITPendingBit(USART3, USART_IT_TC);//清除中断TC位
        USART_Cmd(USART3,ENABLE);//最后使能串口
}

void USART3_IRQHandler(void)  
{
        if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
        {       
                UART3_Rbuff[UART3_rec_counter] = USART3->DR;//
                UART3_rec_counter ++;

                g_Uart3_Timer=1;
                if(UART3_rec_counter > UART3_REC_BUFF_SIZE)//超过接收缓冲区大小
                {
                        UART3_rec_counter = 0;
                }
                USART_ClearITPendingBit(USART3, USART_IT_RXNE);
        }
        if (USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
        {
        USART_ClearITPendingBit(USART3, USART_IT_TXE);           /* Clear the USART transmit interrupt                  */
    }       
}

void UART3_Send_Data(unsigned char *send_buff,unsigned int length)
{
        unsigned int i = 0;
        for(i = 0;i < length;i ++)
        {                       
                USART3->DR = send_buff[i];
                while((USART3->SR&0X40)==0);       
        }       
}

最佳答案

查看完整内容[请看2#楼]

问题已解决,nvic配置在另一边,忘记添加串口三中断,还有端口要复用,用pb10,pb11
qq1950361006,互帮互助,共同进步。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

55

主题

474

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2374
金钱
2374
注册时间
2017-8-7
在线时间
207 小时
 楼主| 发表于 2018-1-18 10:02:00 | 显示全部楼层
问题已解决,nvic配置在另一边,忘记添加串口三中断,还有端口要复用,用pb10,pb11
qq1950361006,互帮互助,共同进步。
回复

使用道具 举报

55

主题

474

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2374
金钱
2374
注册时间
2017-8-7
在线时间
207 小时
 楼主| 发表于 2018-1-18 10:39:00 | 显示全部楼层
问题已解决
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-19 22:10

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表