Advertisement
mikroavr

modbus_slave

Sep 26th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. library from:
  3. https://github.com/CMB27/ModbusRTUSlave/tree/main
  4. */
  5.  
  6. #define MAX485_RXD1 27
  7. #define MAX485_TXD1 26
  8. const byte dePin=13;
  9.  
  10. #include <ModbusRTUSlave.h>
  11. ModbusRTUSlave modbus(Serial1, dePin); // serial port, driver enable pin for rs-485
  12. bool coils[2];
  13. bool discreteInputs[2];
  14. uint16_t holdingRegisters[2];
  15. uint16_t inputRegisters[2];
  16.  
  17. void setup() {
  18.  
  19.   Serial1.begin(9600, SERIAL_8N1, MAX485_RXD1, MAX485_TXD1);
  20.  
  21.   modbus.configureCoils(coils, 2);                       // bool array of coil values, number of coils
  22.   modbus.configureDiscreteInputs(discreteInputs, 2);     // bool array of discrete input values, number of discrete inputs
  23.   modbus.configureHoldingRegisters(holdingRegisters, 2); // unsigned 16 bit integer array of holding register values, number of holding registers
  24.   modbus.configureInputRegisters(inputRegisters, 2);     // unsigned 16 bit integer array of input register values, number of input registers
  25.  
  26.   modbus.begin(1, 9600);
  27. }
  28.  
  29. void loop() {
  30.   modbus.poll();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement