Searching \ for '[PIC:] USART - how to generate Even parity?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=usart
Search entire site for: 'USART - how to generate Even parity?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] USART - how to generate Even parity?'
2004\01\11@171221 by Peter Moreton

flavicon
face
hi, I'm working on a project that needs RS232 data with even parity -
and having read the USART doc's, I couldn't see a way to get the USART
hardware to generate the parity data, so I am presuming that the correct
approach is to take each 7 bit ASCII character that I need to send,
calculate what the 8th (parity) bit should be, and adjust the character
I load into the USART accordingly.

Is this right, or am I missing something obvious?

Thanks.

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\01\11@172250 by

picon face
Peter Moreton wrote :

> hi, I'm working on a project that needs RS232 data with even parity -
> and having read the USART doc's, I couldn't see a way to get the USART
> hardware to generate the parity data, so I am presuming that
> the correct
> approach is to take each 7 bit ASCII character that I need to send,
> calculate what the 8th (parity) bit should be, and adjust the
> character I load into the USART accordingly.
>
> Is this right, or am I missing something obvious?


Just checked one data sheet (PIC16F62X, DS40300B, page 78)
where it says "Parity is not supported by the hardware,
but can be implemented is software...)

Pretty clear, isn't it :-)

Jan-Erik.
PS. Note that the parity bit could be sent as the 9'th bit
(using the TX9D bit in the TXSTA reg...

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu

2004\01\11@180928 by Olin Lathrop

face picon face
Peter Moreton wrote:
> hi, I'm working on a project that needs RS232 data with even parity -
> and having read the USART doc's, I couldn't see a way to get the USART
> hardware to generate the parity data, so I am presuming that the
> correct approach is to take each 7 bit ASCII character that I need to
> send, calculate what the 8th (parity) bit should be, and adjust the
> character I load into the USART accordingly.

Sounds right.  Upon receiving it's up to your code to check the parity of
the received byte, if you care.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu

2004\01\12@083631 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,

Peter Moreton wrote:
<snip>
> the correct
> approach is to take each 7 bit ASCII character that I need to send,
> calculate what the 8th (parity) bit should be, and adjust the
> character I load into the USART accordingly.

In principle you are correct, at reception store the incomming byte, calculate the parity on an copy,
an match should yield zero in lowest bit for even parity and correct match if you use the macro below.
Also rember to clear the parity bit in the incomming bytes before you use/store them.

For transmission it's similar, clear the parity bit (make sure it's cleared), make an copy to use for parity calculation, and then set the pairity bit accordingly before you store it in buffer or send it.


This is from the piclist site, I think the original author is John Payson:
;++++++++++++
;
; CALC_PARITY - Calculates parity of one byte pointed to by argument, result in lowest bit the rest of the byte is
; trashed, Uses W.
; LSB = '1' means ODD and '0' means EVEN
; CALC_PARITY MACRO ARG_BYTE
       SWAPF   ARG_BYTE,W         XORWF   ARG_BYTE,F         RRCF     ARG_BYTE,W         XORWF   ARG_BYTE,F         BTFSC   ARG_BYTE,2         INCF    ARG_BYTE,F         ENDM


/Tony

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@084712 by

picon face
Tony Kubek wrote :

> Also rember to clear the parity bit in the incomming bytes
> before you use/store them.

When you send 7-bit + parity, isn't the parity bit
the LSB in the 8-bit "byte" received ?

And so, isn't the correct way to do a RRF/RRCF (after clearing
the C bit !) ? If you just clear the LSB of in incomming byte,
you get a character in the d'128' - d'255' range, not ?

Jan-Erik.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@100745 by Peter Moreton

flavicon
face
Thanks Tony, I'm beginning to understand....

The peripheral I'm communicating with is documented as using :

                               "Data length 8 bit
                               Stop bit         1 bit
                               Parity   even
                               Baudrate         4800 bps"

I'm unsure whether this means I have to send 8 bits of data plus a 9th
bit of parity, or 7 bits of data plus an 8th bit of parity?  Any
thoughts?

Needless to say, I'm having no luck at the moment getting my PIC to talk
to this device, so am trying to reduce the number of variables!

Thanks, Peter Moreton



{Original Message removed}

2004\01\12@101407 by

picon face
Peter Moreton wrote :

> The peripheral I'm communicating with is documented as using :
>
>                                 "Data length 8 bit
>                                 Stop bit         1 bit
>                                 Parity   even
>                                 Baudrate         4800 bps"
>
> I'm unsure whether this means I have to send 8 bits of data plus a 9th
> bit of parity, or 7 bits of data plus an 8th bit of parity?  Any
> thoughts?
>
> Needless to say, I'm having no luck at the moment getting my
> PIC to talk
> to this device, so am trying to reduce the number of variables!
>
> Thanks, Peter Moreton


To find out the comm params, connect something else
(as an ordinary VT-terminal or a terminal emulator
on a PC) and then play around with the settings until
you get contact.

It's much harder to use the PIC to find out the protocol...

Jan-Etik.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@101821 by Bob Ammerman

picon face
> When you send 7-bit + parity, isn't the parity bit
> the LSB in the 8-bit "byte" received ?

No, it is in the MSB

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@102408 by Bob Ammerman

picon face
>The peripheral I'm communicating with is documented as using :
>
>                              "Data length 8 bit
>                                Stop bit         1 bit
>                                Parity   even
>                                Baudrate         4800 bps"

It is a bit unusual to use both parity and 8 data bits, but certainly not
unheard of. I am guessing that you should try it both ways. Can you do some
quick testing using HyperTerminal to find out which it is, and eliminate any
possibility that it is your hardware.

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@104145 by Olin Lathrop

face picon face
Peter Moreton wrote:
>                                 "Data length 8 bit
>                                 Stop bit         1 bit
>                                 Parity   even
>                                 Baudrate         4800 bps"
>
> I'm unsure whether this means I have to send 8 bits of data plus a 9th
> bit of parity, or 7 bits of data plus an 8th bit of parity?

8 data bits plus an additional 9th bit for parity.

*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@120722 by Alan B. Pearce

face picon face
>                                 "Data length 8 bit
>                                 Stop bit         1 bit
>                                 Parity   even
>                                 Baudrate         4800 bps"
>
> I'm unsure whether this means I have to send 8 bits of data plus a 9th
> bit of parity, or 7 bits of data plus an 8th bit of parity?  Any
> thoughts?

Unfortunately it depends on the person writing the spec. I have seen this
meaning 7 bit + parity, and also on other equipment 8 bit + parity. However
as a first attempt I would try it as 8 bit + parity. As an initial attempt
rather than generate parity in the PIC I would suggest you set it to 9 bit
mode, and leave the 9th bit clear, and send a rotating character set, i.e.
all characters from 0x20 to 0x7e, and see if the characters display
(remember set up like this every second character has correct parity), and
see if it attempts to notify you of incorrect parity. If this does not work,
or comes up with framing errors, then change the code to 8 bit data, and run
it again, and see what the results are - same note about every second
character having correct parity.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@122801 by Peter Moreton

flavicon
face
> Unfortunately it depends on the person writing the spec. I have seen
this
> meaning 7 bit + parity, and also on other equipment 8 bit + parity.

Oh good - I thought maybe I was just being dense; it's pleasing to know
that it's another one of those 'fuzzy' standards - that makes me wasting
2 days on it seem less of a problem somehow.  Anyhow, it turned out to
be 8 data bits plus 1 parity bit.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@123630 by David VanHorn

flavicon
face
At 05:07 PM 1/12/2004 +0000, Alan B. Pearce wrote:

>>                                 "Data length 8 bit
>>                                 Stop bit         1 bit
>>                                 Parity   even
>>                                 Baudrate         4800 bps"
>>
>> I'm unsure whether this means I have to send 8 bits of data plus a 9th
>> bit of parity, or 7 bits of data plus an 8th bit of parity?  Any
>> thoughts?

That's very odd.
Normally parity is used with less than 8 data bits, as in 7E1 or 7O1 Everything I've worked with that was 8 bit, was 8N1.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@124912 by Wouter van Ooijen

face picon face
> That's very odd.
> Normally parity is used with less than 8 data bits, as in 7E1
> or 7O1 Everything I've worked with that was 8 bit, was 8N1.

Not in my experience. I have seen (and was hence forced to use) 8/N,
8/E, and 8/O, and of course the various 7/x. The number before the slash
is definitely the number of data bits, exclusing parity. When 8/E is
used to mean 7 data bits + even parity that is simply a documentation
error.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...