Closed skydancerbg closed 2 years ago
Hello. Thanks.
The library should work with any Arduino board.
I guess, I'll need some help to make it work.
In CONTROLLINO the SN65HVD08 chip Tx and Rx pins are connected to Serial3.
The chip has DE and RE (negated) inputs, which are defined in the CONTROLLINO librarry as: ` #define CONTROLLINO_RS485_DE 75
In their example of RS485 communication, the pins are set as outputs:
pinMode(CONTROLLINO_RS485_DE, OUTPUT); pinMode(CONTROLLINO_RS485_nRE, OUTPUT);
To make RS485 serial communication, they use the pins like this:
`voidControllino_RS485TxEnable( void)
{
/disable receiver, enable transmitter /
digitalWrite(CONTROLLINO_RS485_DE, HIGH);
digitalWrite(CONTROLLINO_RS485_nRE, HIGH);
return;
}
voidControllino_RS485RxEnable( void) { /disable trasmitter, enable receiver / digitalWrite(CONTROLLINO_RS485_DE, LOW); digitalWrite(CONTROLLINO_RS485_nRE, LOW); return; } ` I tried looking at the Modbus-ESP8266 library code, but I cant figure out how to use the DE and RE for the Modbus communication. How do I set and use DE, RE in this sample code?
ModbusRTU mb; bool coils[20];
bool cbWrite(Modbus::ResultCode event, uint16_t transactionId, void* data) { Serial.print("Request result: 0x"); Serial.println(event, HEX); return true; } void setup() { Serial.begin(115200); Serial3.begin(9600, SERIAL_8N1); mb.begin(&Serial3); mb.setBaudrate(9600); mb.master(); }
void loop() { if (!mb.slave()) { mb.readCoil(1, 1, coils, 20, cbWrite); } mb.task(); yield(); delay(1000); }` ... Request result: is 0xE4
If it's possible to connect RE and DE together
mb.begin(&Serial3, RE_DE);
if not, nconmment in ModbusSettings.h line
#define MODBUSRTU_REDE
then independent pins may be used:
mb.begin(&Serial3, DE, RE);
Not possible to connect RE and DE together. Unconmmented #define MODBUSRTU_REDE USING mb.begin(&Serial3, CONTROLLINO_RS485_DE, CONTROLLINO_RS485_nRE); Still no connection: Request result: is 0xE4
Try to change RE and DE parameters order.
Still no connection: Request result: is 0xE4
Using HTerm and 485 to USB adapter, I can see the librarry sending 01 03 00 01 00 07 55 C8 which is correct when an atempt to read 7 holding registers is made. The problem is, it does not recerive the response of ModbusSlave simulator in some reason...
Check these initialisation variants:
mb.begin(&Serial3, DE, RE, true);
and
mb.begin(&Serial3, DE, RE, false);
It works with: mb.begin(&Serial3, DE, RE, true);
mb.begin(&Serial3, CONTROLLINO_RS485_DE, CONTROLLINO_RS485_nRE, true);
Thank you very much for your help! You've saved me a lot of time trying to read and understand the details in the library code myself...
Hello, Great librarry! I use it all the time with my ESP based projects.
Now i need to make a project with CONTROLLINO MEGA. Is it possible to use the librarry with CONTROLLINO MEGA? - It has the SN65HVD08 chip bulit in. Dоes the librarry suport this chip? If yes, how to setup and use?
I understand it is more of a CONTROLLINO question, but in their examples they use some outdated librarry, which has potential problem with buffer overflow. So i better use your librarry if possible.