Shop OBEX P1 Docs P2 Docs Learn Events
Need Error checking Ideas for SERIAL/RS485 Data — Parallax Forums

Need Error checking Ideas for SERIAL/RS485 Data

DavidMDavidM Posts: 630
edited 2011-02-23 18:06 in Propeller 1
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

Comments

  • idbruceidbruce Posts: 6,197
    edited 2011-02-23 02:47
    DavidM

    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
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-02-23 04:47
    If you only have a few bytes, keep things simple. I have a simple packet system - nothing special but it works. It was designed to talk to picaxe chips, which only have 14 registers so packets have to be 14 bytes or less.

    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
               Checksum:=0                                  ' start creating the checksum
               repeat i from 3 to 130
                  Checksum:=Checksum+XmodemBuffer[i]         ' create checksum
               Checksum &= 255                              ' bitwise AND with 0000000011111111
    

    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.
  • Ray0665Ray0665 Posts: 231
    edited 2011-02-23 07:32
    I used a similar method in my 433Mhz block send/receive (64 bytes) the difference being I used sum(data) mod 265.
    I have also seen neg sum(data) mode 256. The point being with a data packet that small you don't need anything complicated
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-02-23 09:37
    Looking at some of the environmental sensors I have used--Vaisala ultrasonic anemometers and weather stations for example use CRC16 for their RS485 and SDI12 options, and a simple 8 bit checksum for their NMEA options. They send the CRC16 as 3 ascii characters with 4, 6, & 6 bits ORed with $40.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-02-23 14:32
    The Dynamixel controllers use a similar protocol to what Dr_Acula suggests.

    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.
  • DavidMDavidM Posts: 630
    edited 2011-02-23 18:06
    Thanks everyone for the info,

    Dr_Acula, thanks for the details tips, I will start working on this


    Thanks

    Dave M
Sign In or Register to comment.