#include <M5Stack.h> #define RX_PIN 16 #define TX_PIN 17 #define X_OFF 160 #define Y_OFF 30 int i=0,s=0; void setup() { M5.begin(); M5.Power.begin(); M5.Lcd.setTextSize(1); M5.Lcd.drawString("RS485 Unit test", 75, 3, 4); Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN); //Set the baud rate of serial port 2 to 115200,8 data bits, no parity bits, and 1 stop bit, and set RX to 16 and TX to 17. 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为16,TX为17 } void loop() { if(Serial2.available()){ M5.Lcd.print(char(Serial2.read())); } delay(100); }
可以正常显示出向串口发送的数据;可是使用如下的代码向串口写(不改变接线),llcom读不到任何内容
#include <M5Stack.h> #define RX_PIN 16 #define TX_PIN 17 #define X_OFF 160 #define Y_OFF 30 int i=0,s=0; void setup() { M5.begin(); M5.Power.begin(); M5.Lcd.setTextSize(1); M5.Lcd.drawString("RS485 Unit test", 75, 3, 4); Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN); //Set the baud rate of serial port 2 to 115200,8 data bits, no parity bits, and 1 stop bit, and set RX to 16 and TX to 17. 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为16,TX为17 } void loop() { Serial2.write("Hello\n"); if(Serial2.available()){ M5.Lcd.print(char(Serial2.read())); } delay(100); }
llcom读不到任何内容,但是依然能显示出来
改成下面这样,llcom依旧读不到
#include <M5Stack.h> #define RX_PIN 16 #define TX_PIN 17 #define X_OFF 160 #define Y_OFF 30 int i=0,s=0; void setup() { M5.begin(); M5.Power.begin(); M5.Lcd.setTextSize(1); M5.Lcd.drawString("RS485 Unit test", 75, 3, 4); Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN); //Set the baud rate of serial port 2 to 115200,8 data bits, no parity bits, and 1 stop bit, and set RX to 16 and TX to 17. 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为16,TX为17 } void loop() { Serial2.write("Hello\n"); delay(100); }
不知道是为什么