Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Multidrop communication using PIC

Status
Not open for further replies.
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
 
Also can you please help me with the following problem:

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

Latest threads

Back
Top