/***************************************************
ESP32 talking to a pretty dumb MAX485 chip (github:iconnor/max485-chip)
Written by Ian Connor.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <SPI.h> // this is needed for display
#include <Wire.h> // this is needed for FT6206
#include <HardwareSerial.h>
constexpr int BOARD_485_RX = 32; // yellow wire to RO (Receiver Output)
constexpr int BOARD_485_TX = 33; // brown wire to DI (Driver Input)
constexpr int MAX485_DE = 23; // blue wire to RE (Receiver Enable)
constexpr int MAX485_RE = 23; // and can be tied to DE (Driver Enable)
constexpr int MODBUS_BAUD_RATE = 9600;
const String firmware_version = "v0.0.1";
#define Serial485 Serial1
void setup(void) {
Serial.begin(115200);
Serial.println(F("Wake up"));
Serial485.begin(MODBUS_BAUD_RATE, SERIAL_8N1, BOARD_485_RX, BOARD_485_TX);
auto modbus_read_request = {
0x01, 0x03, 0x00, 0x01, 0x00, 0x02, 0x05, 0xCB
};
for (int b : modbus_read_request) {
Serial485.write(b);
}
Serial.println(F("Sent 485 data"));
}
void loop() {
while (Serial485.available()) {
byte b = Serial485.read();
Serial.printf("Incoming MAX485 data: %02X\n", b);
}
}