Pages: [1]   Go Down
Author Topic: Handling serial parity errors  (Read 1200 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry if this isn't the correct subforum.

Arduino 1.0.2 gives me the option to use parity error detection on serial connections. Does anyone know if I need to manually handle parity errors, or does the Arduino automatically request retransmission?

Thanks!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Would really depend on your sketch, wouldn't it?
I am betting manually, not all sending devices would be capable of resending.
The protocol you are using would define what happens when parity error is detected.
The data may have error correction built in for example, allowing the receiver to correct the error.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the quick reply!

I don't suppose you know if there's a function I can call to determine if a parity error has been detected? I'm using SERIAL_8E1 (8 data bits, even parity, 1 stop bit) if that makes any difference.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've not used anything except Serial.begin() library, no experience with parity detecting code.
What's your environment that you expect parity errors to occur?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the confusion. As of Arduino 1.0.2, Serial.begin() takes an extra (optional) parameter that defines the configuration of the serial connection.

Since it's so new, the only information I could find on it was some discussion on Google Code, and the Serial/Begin page.

I also tried snooping around the HardwareSerial code, but it's mostly over my head.

I'm not expecting parity errors, but if they happen I'd like to be able to handle them gracefully.
« Last Edit: November 26, 2012, 07:27:42 am by MCDO » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You're right, not much documented as to what happens when there is an incoming error. Have to get one of the real programmers involved.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's the best way to get in contact with them?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try a PM to someone like Coding Badly
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 332
Posts: 16566
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think what you will find is that you will have to study the datasheet for the AVR chip and learn how the various options for parity checking are enabled and how actual received parity errors are detected and signaled. Once you do understand how the underlining hardware functions, then you have to see how you will go about either modifying the existing hardware serial library to integrate this new 'feature' or write your own custom serial library. The fact that the existing hardware serial library utilizes buffered interrupt driven on received characters makes this not so simple a feature to implement.

 First you have to ask yourself what you want to happen if and when a character is received that has bad parity detected? Your choices are fairly limited, either just throw the character away or via a protocol you work out with the sender of the characters, send them a signal that you received a bad character and to resend the character or the complete message. So you see it can get quite complex quite quickly and it is very much just a part of the overall serial protocol you wish to utilize between the sender and receiver of serial data.

Good luck;

Lefty
« Last Edit: November 29, 2012, 06:54:48 pm by retrolefty » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The '328p datasheet (here: http://www.atmel.com/Images/doc8161.pdf), section 19, page 176, is the place to start in understanding parity support in the hardware.

It looks like it both generates the parity bit on output and checks it on input.  See 19.7.4 for Receiver Error flags.

One issue with the Arduino buffered serial input (since you're not managing it yourself) will be knowing _which_ character was in error when the error flag lights up.

Good luck with your project.

-br
Logged

Finland
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I do not know about parity errors. When I have tried to transfer data from Arduino to WindowsXP computer  with as high speed as possible, it is quite seldom that the received character is wrong. Rather, there are more omissions of one or more characters the higher speed I try (up to about 1 megabaud).

Those omission errors should be detected also. A lot of work!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all your help guys!

I've decided to chicken out and implement a checksum-based error detection protocol instead of trying to do it with serial parity checking. I suspect that the new Serial.begin() function was implemented so that the Arduino could easily be connected to devices with fixed data & parity settings, (instead of people having to roll their own HardwareSerial library to support a particular device).
Logged

Pages: [1]   Go Up
Jump to: