Advertisement
RuiViana

ModBus_Slave_Teste

Feb 11th, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <SimpleModbusSlave.h>
  2. #define LED 9
  3. #define LUZ 13
  4.  
  5. enum
  6. {
  7. ADC_VAL,
  8. LUZ_VAL,
  9. XPTO_VAL,
  10. HOLDING_REGS_SIZE // leave this one
  11. };
  12.  
  13. unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
  14.  
  15. void setup()
  16. {
  17. modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);
  18. modbus_update_comms(9600, SERIAL_8N2, 2);
  19. pinMode(LED, OUTPUT);
  20. pinMode(LUZ, INPUT_PULLUP);
  21. }
  22.  
  23. void loop()
  24. {
  25. modbus_update();
  26. holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
  27. holdingRegs[LUZ_VAL] = digitalRead(13); // update data to be read by the master to adjust the PWM
  28. // holdingRegs[LUZ_VAL] = analogRead(A1); // update data to be read by the master to adjust the PWM
  29. holdingRegs[XPTO_VAL] = 0x0228; // update data to be read by the master to adjust the PWM
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement