【求助】Arduino软串口出现乱码
刚刚接触软串口,用的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());
}
但是软串口反馈的一直是乱码,硬串口正常
焊接有问题? 用 serial port 接到 pin 10, 11 嗎?
Serial.begin(57600);
mySerial.begin(4800);
baud rate 不相同....... Super169 发表于 2014-7-10 17:20 static/image/common/back.gif
用 serial port 接到 pin 10, 11 嗎?
Serial.begin(57600);
57600是对于硬串口的,4800是对于软串口的。这样调节baud rate时候可以接收到不同串口的数据 有好好的硬件串口为啥还要弄软件串口哦~~~~
需要多串口可以选择1280或者2560多好。 darkorigin 发表于 2014-7-11 09:23 static/image/common/back.gif
有好好的硬件串口为啥还要弄软件串口哦~~~~
需要多串口可以选择1280或者2560多好。
板子太大了 maxliu 发表于 2014-7-11 09:23 static/image/common/back.gif
57600是对于硬串口的,4800是对于软串口的。这样调节baud rate时候可以接收到不同串口的数据
因為不太清楚你的設定, 所以我先問了你是否把 serial (即 port 0,1) 接 port 10,11 測試.
那你是用兩塊板測試嗎?還是一塊板 port 10 接 port 11? 我么遇到同样问题,难道是板子焊的有问题? yanglang00 发表于 2015-5-7 19:34 static/image/common/back.gif
我么遇到同样问题,难道是板子焊的有问题?
俩串口都用9600
页:
[1]