Reliable Serial Communication

Hi, Sorry if this is somewhere I haven't found but I am trying to find a simple way to send serial data through software serial to a srf shield.
I am currently getting garbage data on occasions which mess's my data up and other times it will change numbers and letters.

Any help or links would be appreciated.

Thanks in advance, Chris.

Any help or links would be appreciated.

Seeing your code would help.

Typically, computing a checksum, and sending that, and computing the checksum of the received data, and comparing that to the sent checksum will let you discard invalid packets.

There are various ways to compute a checksum. It doesn't really matter which you use, as long as you use the same method on both ends.

Could you give an example of various ways of computing a checksum I don't want to go to complicated as memory and ram are not exactly at premium.

My issue however is its a multipoint network and also packets are dropped very frequently I mean about 5 of 6 packets are invalid.

I'm sending this string 0-1-5-42, where the first number is the destruction second is who sent it and third is a command code the fourth is my checksum which I get by adding the numbers and multiplying by the string length.

I am using serial.println to send this and reading chars into a string on the opposite end.

I don't have a code example as I'm on my Sony phone currently but will post later if I can hope this helps.

Thanks in advance, Chris.

Shandy:
Could you give an example of various ways of computing a checksum I don't want to go to complicated as memory and ram are not exactly at premium.

Chris,

Here is a 16bit CRC function you could use to verify each datapacket.

// 16bit CRC 
// Chuck Todd <ctodd@cableone.net>

uint16_t CalcCRC(byte * data, uint8_t datlen){
uint16_t CRC=0xFFFF; // Init CRC
uint8_t xor_flag;
for(uint8_t n=0; n<datlen;n++){
  CRC = CRC ^ data[n];
  for(uint8_t i=0;i<8;i++){
    if(CRC & 0x0001) {
      xor_flag = 1;
      }
    else {
      xor_flag = 0;
      }
    CRC = CRC >> 1;
    if (xor_flag) {
      CRC = CRC ^ 0xA001;
      }
    }
  }
return CRC;
}

Just call CalcCRC() and append the result to the data packet, the receiver would recalc the CRC and discard the packet if the CRC comparison failed, possibly send a NAK, or request resend.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

My issue however is its a multipoint network and also packets are dropped very frequently I mean about 5 of 6 packets are invalid.

Is your setup wired or wireless? Do you have any type of flow control on your network? What type of environment does your setup exist in?

Thank you so much Chuck that's very helpful.

Zoomkat my project is wireless its using a SRF shield you can buy on ebay which works on 868mhz I am using this for a laser tag project to send data between the weapons and a controller linked to a laptop with custom software.

My issue is mainly that data is corrupted so often so I almost need to send packets 3 or 4 times before it gets through.

Thanks in advance, Chris.