Author Topic: CRC method for error detection and correction  (Read 10003 times)

vikram_t80

  • Member
  • ***
  • Posts: 13
CRC method for error detection and correction
« on: November 07, 2011, 03:58:42 am »
Dear Jan,

I have successfully completed the USB HID communication. Now I want to add the CRC method for error detection and correction of the data that will be send from the host to device over USB and vice-a-versa.

I am new to CRC. I have read through the webblogs on CRC and also the wikepedia weblink about CRC.
But none of them practically describes how to decide the generator polynomial i.e. the length and the value of the polynomial for CRC.

Can you help to get some practicall tutorials or examples on this?

Thanks and regards,
Vikram

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2596
    • Lakeview Research
Re: CRC method for error detection and correction
« Reply #1 on: November 07, 2011, 09:39:31 am »
I have two examples here:

http://www.janaxelson.com/usbfaq.htm

Jan
« Last Edit: June 27, 2015, 09:54:39 am by Jan Axelson »

vikram_t80

  • Member
  • ***
  • Posts: 13
Re: CRC method for error detection and correction
« Reply #2 on: November 08, 2011, 10:50:50 pm »
Sorry Jan it seems I missed out on the other discussion.

I will look into it today.

Thanks and Regards,
Vikram

vikram_t80

  • Member
  • ***
  • Posts: 13
Re: CRC method for error detection and correction
« Reply #3 on: November 10, 2011, 02:03:53 am »
Hi Jan,

Thankyou for the example code. I have modified my code and it is working fine now.

How will my code tell that the value of CRC calculated is correct for given data?
I mean to say that on the PC (host side) i have generated the CRC value through a small visual C code and that CRC value matches what the device is generating.
But what if the data sent gets corrupted and i get a different CRC value then how do I implement in the code to resend the data.

Can you please guide me?

What comes in my mind is to write an if condition stating that (if CRC value  == FALSE)
then the receive buffer interrupt should not go low.

Is there something like this possible?

Thanks and regards,
vikram

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2596
    • Lakeview Research
Re: CRC method for error detection and correction
« Reply #4 on: November 10, 2011, 10:15:45 am »
If the CRC doesn't match, the receiver doesn't return ACK and the sender knows it has to resend.

Jan

vikram_t80

  • Member
  • ***
  • Posts: 13
Re: CRC method for error detection and correction
« Reply #5 on: November 11, 2011, 06:33:38 am »
Sorry Jan it seems I am still confused.
What I am doing in my code is as below:
Firstly through the PC utility (USB demonstrator) I am sending 64 bytes.
Of these 64 bytes the first byte is my report ID,  next 4 bytes are of CRC value and next byte is the size of data to be transmitted from host to device. All the rest 58 bytes are data bytes.
Once the entire 64 bytes are received in the internal buffer of device I am seperating the 4 CRC bytes and then applying the CRC check function on last 58 bytes to get the CRC value.

To check whether this 58 data bytes are correct or not I am comparing the CRC value that is generated at the device side with the one send from host side.

Now the point is say I alter the data bytes which are sent from host and get the CRC of this new bytes.
After comparing with the original CRC that is send along with data. obviously it will show an error stating data bytes are incorrect.

What now needs to be done in the code to get these 58 bytes resend? I am stuck once the data bytes were sent earliar the receive status queue level interrupt must have been cleared indicating no more bytes are left to be received.

Please help and sorry for such a long forum

Thanks and Regards

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2596
    • Lakeview Research
Re: CRC method for error detection and correction
« Reply #6 on: November 11, 2011, 10:13:23 am »
The CRC check is normally done in hardware because the receiving end has to know the result in time to decide whether to ACK the data.

If the receiving end doesn't return ACK, the sender resends.

What device hardware are you using?

Jan

vikram_t80

  • Member
  • ***
  • Posts: 13
Re: CRC method for error detection and correction
« Reply #7 on: November 14, 2011, 04:59:09 am »
Thanks Jan for clarifying the doubt.

It seems that the issues are still there.

I am looking to design a PC utility one like the USB HID demonstrator.
I don't need the graphical view that shows the led select and the Button select or Variable value as it shows i n USB HID demonstrator.

I would need the first view that is the Device descriptor view.
Second I would need a page which will have 3 separate buttons as below:
1) select the binary file( file that needs to be uploaded in the USB device)
2) upload/write the file into device
3) progress status bar

Can u please let me know any way of designing a PC utility as I have never designed one before.
Or at least any tutorials.
I am familiar with C.

Thanks and regards,
Vikram

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2596
    • Lakeview Research
Re: CRC method for error detection and correction
« Reply #8 on: November 15, 2011, 12:57:46 pm »
For reading the file, see my response here:

http://www.janaxelson.com/forum/index.php?topic=667.0

For writing data to the HID, see my HID example code:

http://www.janaxelson.com/hidpage.htm#MyExampleCode

You'll also need to provide device firmware that knows what to do with the received data.

Jan
« Last Edit: June 27, 2015, 09:54:56 am by Jan Axelson »