Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <SimpleModbusSlave.h>
  2.  
  3.  
  4. #define TOTAL_REGS_SIZE 50
  5. unsigned int holdingRegs[TOTAL_REGS_SIZE]; // function 3 and 16 register array
  6. ////////////////////////////////////////////////////////////
  7.  
  8. void setup()
  9. {
  10. randomSeed(analogRead(0));
  11. /*
  12. * arguments are:
  13. * baude rate
  14. * slave id
  15. * tx enable pin (not relevant on arduino)
  16. * max number of registers
  17. * low latency
  18. */
  19. modbus_configure(38400, 1, 2, TOTAL_REGS_SIZE, 0);
  20. }
  21.  
  22. void loop()
  23. {
  24. for (byte i = 0; i < TOTAL_REGS_SIZE; i++)
  25. {
  26. holdingRegs[i] = (i%2 ? 1 : 0);
  27. }
  28.  
  29. modbus_update(holdingRegs);
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement