I will share some of my experiences with mod-bus libraries test that I have done so far, kindly ask suggestion for a problem that I having right now with particle photon.
My intention is pulling some data from holding register on VFD Control techniques.
For some reason i din’t have success using this library,Smarmengol-Modbus Library, the problem I have no idea how to address a holding register like this one 401811, if i try to set 1811 register the arduino or photon
hangs and do nothing.
With this library “4-20ma” work fine with arduino… I use software serial to connect the MAX485, and that work perfect, I was able to read any register the VFD… I tried that same library with the ESP8266 and works too… the problem… if one disconnect the max485 from the ESP8266 or simple disconnect the cable from slave, the ESP8266 crash after a few intents of read the registers…timeouts…
I tried to determine the problem… but I am not so advanced programmer to dig into the library … so I gave up … I read somewhere thi is because the library Software Serial + mod-bus disable the GPIO pin interrupts very often . Now I move to try with Particle photon. initially I was having a problem very often got timeout while trying to read 10 holding registers… mysteriously solved
for my test I just used the “4-20ma” library without any modification.
this is the sample code:
We're using a MAX485-compatible RS485 Transceiver.
Rx/Tx is hooked up to the hardware serial port at 'Serial'.
The Data Enable and Receiver Enable pins are hooked up as follows:
#define MAX485_DE A3
#define MAX485_RE_NEG A2
#define CT_VFD(m,n) (m *100+ n-1) // formula to acces VFD registers
// instantiate ModbusMaster object
#define reg_qty 11
// Init in receive mode
// Modbus communication runs at 115200 baud
// Modbus slave ID 1, Serial1 on the Particle Photon
// Callbacks allow us to configure the RS485 transceiver correctly
bool state = true;
// Toggle the coil at address 0x0002 (Manual Load Control)
//result = node.writeSingleCoil(0x0002, state);
//state = !state;
// Read 16 registers starting at 0x3100)
//result = node.readInputRegisters(0x3100, 16);
// read holding register VFD Control_techniques starting at Pr 1811 ( modbus 401811- 401814)
if (result == node.ku8MBSuccess)
for (uint8_t j = 0; j < reg_qty; j++) Serial.println(node.getResponseBuffer(j),DEC);
Serial.println("NO- RESPONSE"); // i got not response very oftem
Questions that I have so maybe some one can provide some advise
-The modbus master library ported by @peekay123 do not work for me . i got some errors… I see this library was ported 3 years ago… so maybe that is the reason… Not clear if 4-20ma library specially ported for spark has any advantage over the un-ported 4-20ma master library.
-this is another diferent library Modbus_RS485 that seems pretty interesting… but as is it right now I can’t get it to read any modbus registers on the VFD using photon not sure if i did right to addressee the register using this line -->telegram.u16RegAdd = 1811; // start address in slave