View previous topic :: View next topic |
Author |
Message |
sindyme
Joined: 05 Aug 2009 Posts: 37
|
How to change PARITY in run-time ? |
Posted: Thu May 08, 2014 10:07 pm |
|
|
Good day for everyone.
I have question need help !
The CCS library have provided "set_uart_speed( )" function to change baud rate in run-time but I also hope to change PARITY and data bits (5-9) of RS232.
Any syntax can achieve this function ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Fri May 09, 2014 12:26 am |
|
|
You have to use multiple streams.
However be aware, that the hardware only supports 8 or 9 bits total data. So 7 bits with parity, 8 bits with parity, 8 bits no parity and 9 bits no parity are the only versions that can actually be generated by the hardware UART. Whether parity is actually generated correctly, depends then on the compiler version (a lot don't). The chip itself does not support or understand parity at all, it is a software solution used. Hence the next paragraph.
The easiest way is to just have two streams supporting 8, or 9 bit modes, and generate the parity yourself (efficient routines to do this have been published here). You then avoid any compiler issues regarding parity.
However the need for different data lengths has almost totally vanished in recent years, with 99.9% of systems using 8bit, with or without parity only. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 09, 2014 2:33 pm |
|
|
Who wants to use parity anyway?
It creates 12,5% extra data overhead but can only detect a limited set of communication errors (only when an odd number of bits is flipped).
Other error detecting mechanisms like CRC have much less overhead and will detect a wider range of practical communication errors. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Fri May 09, 2014 5:47 pm |
|
|
also...
...it's not very common to NOT know what the other device's communications specs are BEFORE you connect to it.Without knowing the specs, you'll always get errors.
While there are 'autobaud' detect algorithms I've never needed them or parity 'trees' in the past 20+ years and I've connected to a lot of 'interesting' stuff.
hth
jay |
|
|
|