极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 29833|回复: 8

【求助】Arduino软串口出现乱码

[复制链接]
发表于 2014-7-10 15:33:57 | 显示全部楼层 |阅读模式

刚刚接触软串口,用的IDE里面自带的例程文件做的测试。代码如下
/*
  Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
但是软串口反馈的一直是乱码,硬串口正常
回复

使用道具 举报

发表于 2014-7-10 17:03:15 来自手机 | 显示全部楼层
焊接有问题?
回复 支持 反对

使用道具 举报

发表于 2014-7-10 17:20:49 | 显示全部楼层
用 serial port 接到 pin 10, 11 嗎?

Serial.begin(57600);

mySerial.begin(4800);

baud rate 不相同.......
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-7-11 09:23:12 | 显示全部楼层
Super169 发表于 2014-7-10 17:20
用 serial port 接到 pin 10, 11 嗎?

Serial.begin(57600);

57600是对于硬串口的,4800是对于软串口的。这样调节baud rate时候可以接收到不同串口的数据
回复 支持 反对

使用道具 举报

发表于 2014-7-11 09:23:46 | 显示全部楼层
有好好的硬件串口为啥还要弄软件串口哦~~~~
需要多串口可以选择1280或者2560多好。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-7-11 10:41:33 | 显示全部楼层
darkorigin 发表于 2014-7-11 09:23
有好好的硬件串口为啥还要弄软件串口哦~~~~
需要多串口可以选择1280或者2560多好。

板子太大了
回复 支持 反对

使用道具 举报

发表于 2014-7-11 11:22:09 | 显示全部楼层
maxliu 发表于 2014-7-11 09:23
57600是对于硬串口的,4800是对于软串口的。这样调节baud rate时候可以接收到不同串口的数据

因為不太清楚你的設定, 所以我先問了你是否把 serial (即 port 0,1) 接 port 10,11 測試.

那你是用兩塊板測試嗎?  還是一塊板 port 10 接 port 11?
回复 支持 反对

使用道具 举报

发表于 2015-5-7 19:34:01 | 显示全部楼层
我么遇到同样问题,难道是板子焊的有问题?
回复 支持 反对

使用道具 举报

发表于 2015-5-8 15:48:29 | 显示全部楼层
yanglang00 发表于 2015-5-7 19:34
我么遇到同样问题,难道是板子焊的有问题?

俩串口都用9600
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 07:38 , Processed in 0.050359 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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