Need Error checking Ideas for SERIAL/RS485 Data
DavidM
Posts: 630
HI,
So I am making progress with my RS485 object,/project.
I need to send messages in 2 different ways
1) BROADCAST
2) POINT TO POINT ( Node to node with a response )
Regardless of the above two ways I am communicating, one thing I want to do is to MAKE SURE that the data gets sent without errors. ( In some situations I may need to "BREAK" the RS485 line with an RF Link using Aerocomm modem)
So In broadcast mode, The MASTER will send data to all slaves, and each slave will read the massages, but it must determine if each message has been sent without error.
Usually my messages will consist of only a few bytes, say 4 to 10, ( I haven't decided yet)
I have heard of "CRC" and "CHECKSUM" etc, But I have no idea how these work, I have read up a little about these ideas and most explanation seem very technical.
One way I thought of is to send small messages TWICE ( in the same "packet") in broadcast mode , then the slave would compare the first half to the second half and if different would ignore it. This may have to be a fixed length for each message to keep it simple.
Has anyone done things like this before?
Thanks
Dave M
So I am making progress with my RS485 object,/project.
I need to send messages in 2 different ways
1) BROADCAST
2) POINT TO POINT ( Node to node with a response )
Regardless of the above two ways I am communicating, one thing I want to do is to MAKE SURE that the data gets sent without errors. ( In some situations I may need to "BREAK" the RS485 line with an RF Link using Aerocomm modem)
So In broadcast mode, The MASTER will send data to all slaves, and each slave will read the massages, but it must determine if each message has been sent without error.
Usually my messages will consist of only a few bytes, say 4 to 10, ( I haven't decided yet)
I have heard of "CRC" and "CHECKSUM" etc, But I have no idea how these work, I have read up a little about these ideas and most explanation seem very technical.
One way I thought of is to send small messages TWICE ( in the same "packet") in broadcast mode , then the slave would compare the first half to the second half and if different would ignore it. This may have to be a fixed length for each message to keep it simple.
Has anyone done things like this before?
Thanks
Dave M
Comments
This is not exactly what you are looking for, but I am sure you could get some good ideas from it. It includes CRC and various other things
Bruce
1) Start byte, I chose ascii 02 because this is "start of text"
2) Number of bytes in the message, including the start byte, and end byte
3) Source. One byte.
4) Destination. One byte
5) Data bytes.
6) Checksum
7) End byte. Ascii 03 because this is "end of text"
So - wait until a 02 arrives.
Read the next byte. Subtract 1 and read this many bytes into a buffer
Last byte should be a 03. If not then go back to the start and wait for 02 again
Add up all the bytes in the packet. See if equal to checksum.
Check packet is for me - if yes then process.
For a checksum, I copied the xmodem protocol. In spin this is very simple
Start with a checksum equal to zero. Add all the bytes. Then bitwise and with $FF
This is the same as repeatedly subtracting 256 until the answer is >= 255. Bitwise and is quicker as it is just one spin command.
I have also seen neg sum(data) mode 256. The point being with a data packet that small you don't need anything complicated
I figure it's a given that you need to know the length of the data packet to use a checksum?
One field I add to wireless transmissions is a counter that increments with each packet. That way the receiver knows if the transmission is a resend of a previous transmission of an identical transmission based on identical data.
With wireless communication the receiver sends an acknowledgment that includes the data count so the transmitter knows which packets have safely arrived.
Dr_Acula, thanks for the details tips, I will start working on this
Thanks
Dave M