This commit is contained in:
Tinyu
2021-08-30 14:32:52 +08:00
parent b0ca2180a9
commit 0eeeef69fa
2 changed files with 62 additions and 19 deletions
+43
View File
@@ -0,0 +1,43 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/unit/iso485
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/iso485
*
* describe: iso485.
* date2021/8/30
*******************************************************************************
Please connect to PortC,Pressed ButtonA :send "hello world"
请连接端口C,Pressed ButtonA :send "hello world"
*/
#include <M5Stack.h>
String str = "";
void setup() {
M5.begin();
M5.Lcd.drawString("ISO485", 20, 0, 2);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
M5.Lcd.setCursor(0, 20);
}
void loop() {
if (M5.BtnA.wasPressed())
{
Serial2.write("Hello World\r\n");
}
if (Serial2.available()) {
char ch = Serial2.read();
str += ch;
if (str.endsWith("\r\n")) {
Serial.print(str);
M5.Lcd.print(str);
str = "";
}
}
M5.update();
}
+19 -19
View File
@@ -1,42 +1,42 @@
/*
Description: Use RS485 Unit for serial communication, continuously send "Hello", and display the received content on the screen.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/unit/rs485
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/rs485
*
* describe: rs485.
* date2021/8/30
*******************************************************************************
Please connect to Port C,Use RS485 Unit for serial communication, continuously send "Hello", and display the received content on the screen.
请连接端口 C,采用RS485单元串行通信,连续发送“Hello”,接收到的内容显示在屏幕上。
*/
#include <M5Stack.h>
#define RX_PIN 16
#define TX_PIN 17
#define TX_PIN 17
#define X_OFF 160
#define Y_OFF 30
int i=0,s=0;
void header(const char *string, uint16_t color){
M5.Lcd.fillScreen(color);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE);
M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE);
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.drawString(string, 160, 3, 4);
}
void setup() {
M5.begin();
M5.Power.begin();
header("RS485 Unit test", TFT_BLACK);
M5.Lcd.setTextFont(2);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
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()));
M5.Lcd.print(char(Serial2.read()));
}
delay(100);
}