gd32f103zet6芯片,come和单片机通信不上

[复制链接]
1378|10
AProgrammer 发表于 2025-11-24 19:56 | 显示全部楼层 |阅读模式
通过串口/dev/ttyAMA1, come这边通过python脚本往串口写,单片机收到消息后会回应,现在come这边一直收不到消息。。。。很奇怪。


    while True:
        try:
            send_msg(ser, 'check link')
            nw_mgr_logger.info('send message')
            time.sleep(0.01) #old is 0.1
            str100 = ser.readline()
            nw_mgr_logger.info('check link:%s' % str100)
            if str100 != '':
                break
        except serial.SerialException:
            nw_mgr_logger.error('Faild to read data from %s', SERIAL_PORT)
            time.sleep(1)
        except Exception as e:
            nw_mgr_logger.error(e)
            time.sleep(1)

现在单片机这边收到消息后给come发的信息,在python里面readline没有,很奇怪,可能啥原因呢?
下面是单片机发的消息(通过printf 接口,写的串口)


appeal initialization!
The link is normal.
The link is normal.
The link is normal.
The link is normal.
appeal initialization!
The link is normal.
The link is normal.
The link is normal.
The link is normal.
appeal initialization!
The link is normal.
The link is normal.
The link is normal.
The link is normal.
appeal initialization!
The link is normal.
The link is normal.
The link is normal.
The link is normal.
appeal initialization!
The link is normal.


solty 发表于 2025-11-26 16:26 | 显示全部楼层
检查串口的基本配置是否正确
spicy 发表于 2025-11-26 17:27 | 显示全部楼层
检查数据是否以换行符结尾,调整读取逻辑。
stormwind123 发表于 2025-11-26 17:27 | 显示全部楼层
换行符缺失?
classroom 发表于 2025-11-26 19:28 | 显示全部楼层
波特率、数据位、停止位、奇偶校验等参数是否与单片机端一致。
cr315 发表于 2025-11-26 20:28 | 显示全部楼层
readline()方法默认会阻塞直到接收到换行符或超时。如果超时时间设置过短,可能导致数据未被读取。用户代码中未设置超时时间,可能需要调整ser.timeout参数。
duo点 发表于 2025-11-26 21:29 | 显示全部楼层
串口接收缓冲区可能存在数据未被及时读取,或者数据被分割成多个部分。使用ser.in_waiting检查是否有数据待读取,或者使用ser.read(size)读取固定字节数,避免依赖换行符。
elephant00 发表于 2025-11-26 16:29 | 显示全部楼层
如果启用了硬件流控制,而单片机端未正确配置,可能导致数据传输阻塞
flycamelaaa 发表于 2025-11-26 22:30 | 显示全部楼层
数据编码是否一致,如UTF-8或其他编码,可能导致解码错误。
jcky001 发表于 2025-11-26 22:30 | 显示全部楼层
数据编码是否一致,如UTF-8或其他编码,可能导致解码错误。
onlycook 发表于 2025-11-26 16:51 | 显示全部楼层
可能串口参数不匹配
您需要登录后才可以回帖 登录 | 注册

本版积分规则

46

主题

393

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部
0