Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- library from:
- https://github.com/CMB27/ModbusRTUSlave/tree/main
- */
- #define MAX485_RXD1 27
- #define MAX485_TXD1 26
- const byte dePin=13;
- #include <ModbusRTUSlave.h>
- ModbusRTUSlave modbus(Serial1, dePin); // serial port, driver enable pin for rs-485
- bool coils[2];
- bool discreteInputs[2];
- uint16_t holdingRegisters[2];
- uint16_t inputRegisters[2];
- void setup() {
- Serial1.begin(9600, SERIAL_8N1, MAX485_RXD1, MAX485_TXD1);
- modbus.configureCoils(coils, 2); // bool array of coil values, number of coils
- modbus.configureDiscreteInputs(discreteInputs, 2); // bool array of discrete input values, number of discrete inputs
- modbus.configureHoldingRegisters(holdingRegisters, 2); // unsigned 16 bit integer array of holding register values, number of holding registers
- modbus.configureInputRegisters(inputRegisters, 2); // unsigned 16 bit integer array of input register values, number of input registers
- modbus.begin(1, 9600);
- }
- void loop() {
- modbus.poll();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement