Go Down

Topic: How to create my code CRC for a message??? (Read 631 times) previous topic - next topic

danielvillarrealg

Jul 02, 2013, 11:55 pm Last Edit: Jul 03, 2013, 12:10 am by danielvillarrealg Reason: 1
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.

Graynomad

Quote
the MAX485 and several chips need wait 25ms to enable the Receiver output

That's bollocks in itself, possibly a requirement of a particular protocol but nothing to do with the MAX chips or RS-485.

Quote
I tried use several librarys

What libraries? Are we talking Modbus or just generic comms libraries?

Do you have to use Modbus, or was that just the last thing you tried?

_____
Rob

Rob Gray aka the GRAYnomad www.robgray.com

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.‚

Graynomad

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.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

danielvillarrealg

#4
Jul 03, 2013, 05:06 pm Last Edit: Jul 03, 2013, 05:15 pm by danielvillarrealg Reason: 1

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.

Quote

What libraries? Are we talking Modbus or just generic comms libraries?


I´m talking about the Modbus libraries like:
SimpleModbusMaster.h  ---> https://code.google.com/p/simple-modbus/
MasterModbus.h -----------> https://github.com/2-718/ModbusMaster

And i think start try with RS485_protocol.h -------->http://www.gammon.com.au/forum/?id=11428
but i´m not sure that this library generates CRC code.

Quote
Do you have to use Modbus, or was that just the last thing you tried?

I need use Modbus RTU, for be more specific, i my device is the PM1200  
(http://www.powerlogic.com/literature/PLSED309039EN_PM1000_UG.d15.pdf)

Note: I don´t know if can publish marks, but I prefer avoid it for invalid my post

thanks for you attention Graynomad.

danielvillarrealg


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
Quote

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

#6
Jul 03, 2013, 05:23 pm Last Edit: Jul 03, 2013, 05:29 pm by Graynomad Reason: 1
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.

Quote
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

http://www.ccontrolsys.com/w/How_to_Compute_the_Modbus_RTU_Message_CRC

Looks like you have to hit Google a lot.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

danielvillarrealg

really thanks for you help, i found a blogger with similar problem, [link: http://electronics.stackexchange.com/questions/49097/arduino-as-modbus-master-with-max485-doesnt-get-any-response]
I will try this, and come back with the results

If the results are bad, come back with the CRC code.

I don´t know if can publish marks

I´m refering to Schnaider Elec... XD, i´m sorry the english are not my native language maybe some words are weird.

Quote
Looks like you have to hit Google a lot.

i think the same 

Go Up