你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

M3串口发送不成功可能是什么原因

[复制链接]
千羽猎鹰 提问时间:2015-3-20 08:45 /
片子用的STM32F103C8T6,之前正常,后来板子上的串口位置换了,就把串口换了一下,三个串口都用
串口1和串口3都发送不出去
    USART_SendData(USART1, (u8) ch);
    while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
跑到这里,就一直检测标志位了
串口2能够发送成功,配置一样,试了两块板子,效果一样
可能是哪里的问题呢?
收藏 评论16 发布时间:2015-3-20 08:45

举报

16个回答
回答时间:2015-3-20 08:59:18
有没有重映射端口?最好把使用的是哪个IO口做串口、配置发一下。
zfz0122 回答时间:2015-3-20 09:04:46
板子上的串口位置换了,就把串口换了一下,??没懂 3.gif
千羽猎鹰 回答时间:2015-3-20 09:08:16
void UART1_Configuration(void)
{
        GPIO_InitTypeDef    GPIO_InitStructure;
        USART_InitTypeDef   USART_InitStructure;
        NVIC_InitTypeDef    NVIC_InitStructure;

        Uart1Conf.RXpoint = 0;
        Uart1Conf.RXStart = Uart1Conf.RXpoint;
        Uart1Conf.RXlenth = 0;
        Uart1Conf.TXlenth = 0;
        Uart1Conf.Time    = 0;
        RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);                                //  USART1ʱÖÓʹÄÜ                 
        USART_InitStructure.USART_BaudRate = 38400;
        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);

        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);                                //  I/O¶Ë¿ÚAʱÖÓʹÄÜ
        //Configure the USART1_Tx PA9 as Alternate function Push-Pull
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        //Configure the USART1_Rx PA10 as input power-UP
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                                                //  GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_10;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
               
        RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE);                                //  I/O¶Ë¿ÚAʱÖÓʹÄÜ

        // Configure the RS485DoutEN PA11 as out Push-Pull
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Pin  = RS485OUTEN_PIN;
    GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
    // Configure the RS485RecvEN PA12 as out Push-Pull
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Pin  = RS485INEN_PIN;
    GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);

        RS485DoutDIS();                                                     //  ½ûÖ¹·¢ËÍ
        RS485RecvEN();                                                      //  ½ÓÊÕʹÄÜ
       
        // Enable USART1 Receive  interrupts
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
        // DisEnable USART1 SendEmpt  interrupts
        USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
        // DisEnable USART1 SendComplete  interrupts
        USART_ITConfig(USART1, USART_IT_TC, DISABLE);
//        USART_ClearFlag(USART1,USART_FLAG_TC);                                                                //  ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
        // Enable the USART1
        USART_Cmd(USART1, ENABLE);                                                                                        //  USART1ʹÄÜ
       
        // Enable the USART1 Interrupt
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

        RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);                                //  USART1ʱÖÓʹÄÜ                 
        USART_InitStructure.USART_BaudRate = 38400;
        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);

        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);                                //  I/O¶Ë¿ÚAʱÖÓʹÄÜ
        //Configure the USART1_Tx PA9 as Alternate function Push-Pull
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        //Configure the USART1_Rx PA10 as input power-UP
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                                                //  GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_10;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
               
        RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE);                                //  I/O¶Ë¿ÚAʱÖÓʹÄÜ

        // Configure the RS485DoutEN PA11 as out Push-Pull
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Pin  = RS485OUTEN_PIN;
    GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
    // Configure the RS485RecvEN PA12 as out Push-Pull
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Pin  = RS485INEN_PIN;
    GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);

        RS485DoutDIS();                                                     //  ½ûÖ¹·¢ËÍ
        RS485RecvEN();                                                      //  ½ÓÊÕʹÄÜ
       
        // Enable USART1 Receive  interrupts
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
        // DisEnable USART1 SendEmpt  interrupts
        USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
        // DisEnable USART1 SendComplete  interrupts
        USART_ITConfig(USART1, USART_IT_TC, DISABLE);
//        USART_ClearFlag(USART1,USART_FLAG_TC);                                                                //  ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
        // Enable the USART1
        USART_Cmd(USART1, ENABLE);                                                                                        //  USART1ʹÄÜ
       
        // Enable the USART1 Interrupt
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}
原来用着好好的啊 就是换了一下顺序
串口如果想要发送数据的话 除了允许发送,打开串口 还需要别的不
千羽猎鹰 回答时间:2015-3-20 09:12:53
zfz0122 发表于 2015-3-20 09:04
板子上的串口位置换了,就把串口换了一下,??没懂

原来用串口1实现功能1,串口2实现功能2,串口3实现功能3
换板子以后,用串口1实现功能3,串口3实现功能1,每个串口的引脚也有变化
eurphan 回答时间:2015-3-20 09:23:51
不懂帮顶   
chendiand 回答时间:2015-3-20 10:45:29
正在学习串口
千羽猎鹰 回答时间:2015-3-20 11:06:19
感觉好凄惨 都没人理我
回答时间:2015-3-20 11:17:20
楼主串口1用的还是PA9 PA10吗?
千羽猎鹰 回答时间:2015-3-20 12:13:29
安 发表于 2015-3-20 11:17
楼主串口1用的还是PA9 PA10吗?

嗯 是的 引脚可以确认是对的
12下一页

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版