Hi everybody, i´m lastly working with a project about of communication RS485.
I´m trying comunicate a arduino with a device with RS485, using a MAX485 and a Arduino Mega 2560.
I tried use several librarys but the communication always is failed, and i don´t have a response of the device, i notice that the librarys not are the problem, i confirm this using same librarys but with a Arduino-Master and Arduino-Slave, and thereby this work´s excelent.
I read in somewhere that the MAX485 and several chips need wait 25ms to enable the Receiver output (RE=LOW), and i think that the message (query) don´t is sending correctly becouse if i don´t wait the 25ms, and i try to read the response maybe i read my last bits of the query or simply the query is don´t sending completly.
Then i want check this generating my own code and send the query with serial port1(e.g.Serial1.write) with the respective MAX485, and then immediately read the response with serial port2(e.g.Serial2.read) with the respective MAX485, thereby i don´t need wait 25ms and read immediately.
My problem for this is that the query on MOUDBUS RTU Protocol need CRC error check, and i don´t understand how generate this, i read about of some librarys but i don´t know what parameter assign.
maybe my solution is really laborious and maybe the last suitable, but is this only one idea that I have,
any suggestion is grateful.
XOR is one way, that's really a "checksum", nowhere near as good as a CRC but often good enough.
If you have to conform to an existing protocol (like ModBus) then you have to implement the same checksum/CRC algorithm that they use. If not then you can DIY and XORing is a nice simple thing to do.
Graynomad:
That's bollocks in itself, possibly a requirement of a particular protocol but nothing to do with the MAX chips or RS-485.
ok, if this is like you say, my test is in vain because my goal on this test is avoid that.
Then I don´t have idea for what is my problem with the respons of device.
What libraries? Are we talking Modbus or just generic comms libraries?
Gfast:
I think you should use "XOR" to get the value. I'm also working on some kinda of the same project, that use RS-485
Hope the Info can help.‚
So thanks Gfast, is a really good suggestion, but i need follow the protocol Modbus, and think is more like said Graynomad
If you have to conform to an existing protocol (like ModBus) then you have to implement the same checksum/CRC algorithm that they use. If not then you can DIY and XORing is a nice simple thing to do.
Nick's code does include a CRC, but if you have to talk to that PM1000 I can see no point in playing with another protocol as it requires Modbus RTU.
So I guess you have no option but to get one of those libraries working, unfortunately I know nothing about ModBus or those libraries so I can't help much.
It's possible however that 25mS you mentioned is something to do with ModBus, although I can find no mention of it in the few spec documents I have.
I don´t know if can publish marks
What are "marks"?
EDIT:
To write a CRC code you need to know the number of bits and the polynomial used by the protocol you are talking to. It looks like Modbus uses a 16-bit CRC with a poly of 0xA001. Here's some example code