-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModbusSlaveArduino.ino
More file actions
41 lines (33 loc) · 977 Bytes
/
Copy pathModbusSlaveArduino.ino
File metadata and controls
41 lines (33 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Modbus slave example 3:
* The purpose of this example is to link a data array
* from the Arduino to an external device through RS485.
*
* Recommended Modbus Master: QModbus
* http://qmodbus.sourceforge.net/
* CONEXIONES FÍSICAS E/ ARDUINO - RS485
DE/RE (en serie)-> pin 4
RO -> RX
DI -> TX
*/
#include <ModbusRtu.h>
// assign the Arduino pin that must be connected to RE-DE RS485 transceiver
#define TXEN 4
// data array for modbus network sharing
uint16_t au16data[16] = {
3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };
/**
* Modbus object declaration
* u8id : node id = 0 for master, = 1..247 for slave
* port : serial port
* u8txenpin : 0 for RS-232 and USB-FTDI
* or any pin number > 1 for RS-485
*/
Modbus slave(1,Serial,TXEN); // this is slave @1 and RS-485
void setup() {
Serial.begin( 19200 ); // baud-rate at 19200
slave.start();
}
void loop() {
slave.poll( au16data, 16 );
}