Multidrop communication using PIC

Status
Not open for further replies.
Most of the time it is easier to NAK bad packets rather then try to repair them.

3v0
 
You've go to be kidding me. Its so lengthy and confusing.

I think parity check method would be way easier
 
If you can not manage CRC just sum each word in a packet and store that value as the last byte in the packet.

3v0
 
I have to revert back to an old thread i opened. I have to add the error detection mechanism in my RS-485 Library. 3v0, can you please advice the simplest error detection (not correction) algorithm consuming few bytes.

What i have in my mind is to generate some kind of a hash which i will transmit at the end of data bytes (From transmitter to Receiver node). Then once the Receiver has all the bytes, it will again generate the hash and compare both of them. If the hash matches, there is no error in bytes, otherwise it will request the complete frame again.

Now i am unable to write a hash function in C to accomplish this which takes about like 1 or two bytes.

Also one more problem is that if i send Address 1 in my frame (here 1 goes in 9 bit UART mode) the receiver doesn't respond. For anyother address it responds okay. Now i checked the ASCII table and 1 means SOH (Start Of Heading). Can there be anything wrong with sending SOH character in UART as first character?
 
Last edited:
I have done a simple XOR on the bytes for a CRC check before for 485 only for a small protocol though.

Code:
char dataByte[5] = dataByte[0] ^ dataByte[1] ^ dataByte[2] ^ dataByte[3] ^ dataByte[4];

Send the data byte.

Other end:
Code:
char CRC = dataByte[0] ^ dataByte[1] ^ dataByte[2] ^ dataByte[3] ^ dataByte[4];
if(CRC == dataByte[5])
{
    //Good CRC
}

Something similar to the above would do you providing you are not using huge data arrays.

Wilksey
 
thank you wilksey, will try it out.

The max data bytes going trough in one frame are 100. Do you think it would still work for this much load ?
 
thank you wilksey, will try it out.

The max data bytes going trough in one frame are 100. Do you think it would still work for this much load ?


sure but add the data bytes using a loop on both ends.
Why do you want to use this rather then a crc, Are you out of memory ?
 
No issue, i do not just understand CRC at the moment and i want a simple error detection scheme.
 
Also can you please help me with the following problem:

 
thank you wilksey, will try it out.

The max data bytes going trough in one frame are 100. Do you think it would still work for this much load ?


sure but add the data bytes using a loop on both ends.
Why do you want to use this rather then a crc, Are you out of memory ?
 
I found a CRC16 code library written in C. However it calculates the CRC for one byte.

Will it still be any good if i calculate CRC for all the data bytes and then XOR them together and send it or will it ruin the CRC calculated all together?
 
okay i have implemented the CRC16 algorithm into my RS-485 library. It is working quite well now.

I do have a small stupid question though. When we send a value from an integer variable, are the first 8 bits truncated (because serial data go in bytes and since int is 16 bits)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…