|
|
本帖最后由 frankpian 于 2016-4-10 17:40 编辑
如题,我有一块2560作为发送,一块nano作为接收。希望2560用串口调试助手发送一个字节,nano收到就可以直接打印出来。可是最后结果是nano一直打印255。上面是2560代码,下面是NANO的
- void setup() {
- Serial.begin(9600);
- Serial1.begin(9600);
- }
- void loop() {
- int a;
- while (Serial.available()>0){
- a=Serial.read();
- Serial.println(a);
- }
- Serial1.write(a);
- }
复制代码
- #include <SoftwareSerial.h>
- SoftwareSerial senSerial(8,9); //软串口RX,TX
- void setup() {
- //打开串口调试
- Serial.begin(9600);//调试串口
- while(!Serial){
- ;//等待调试串口连接
- }
- senSerial.begin(9600);//传感器串口
- }
- void loop() {
- int i;
- while (senSerial.available()>0){
- i=senSerial.read();
- Serial.println(i);
- }
- }
复制代码 |
|