|
|
View previous topic :: View next topic |
Author |
Message |
ELINAP
Joined: 05 Sep 2013 Posts: 14
|
stop bit on UART |
Posted: Wed Nov 18, 2015 4:54 am |
|
|
Hi everybody,
I'm using an 18F67K22 and I want to know if it's possible to configure the number of stop bit for the UART1 without using the "#USE RS232(....)" ?
THX |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9219 Location: Greensville,Ontario
|
|
Posted: Wed Nov 18, 2015 5:50 am |
|
|
Yes, you can directly access the hardware UART configuration registers, just remember you only have 3 choice 0,1, 2 stop bits.
I'd like to ask why as usually UART config has to match the 'other side of the wire' and never changes.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Wed Nov 18, 2015 6:45 am |
|
|
Er. No.
The PIC _hardware_ only generates 1 stop bit. To do 2 stop bits you either have to send 9 bit data, and set this bit to 0 to give an extra 'stop', or switch to using a software UART.....
The hardware cannot generate 0 stop bits on async, so again only software UART's possible.
So even if you use #USE RS232, you cannot physically select anything other than 1 stop bit for UART1. The compiler will cheat and program 9 bit mode and generate a stop bit using bit 9, if this is selected using #use, but anything else will force a switch to using a software UART. |
|
|
ELINAP
Joined: 05 Sep 2013 Posts: 14
|
solved |
Posted: Wed Nov 18, 2015 7:37 am |
|
|
Thanks. It's clear now |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Wed Nov 18, 2015 8:14 am |
|
|
Also, as a comment, 0 stop bits on async, is extremely uncommon. Only ever used at low rates like 300bps. Usually with a PLL to generate a synchronous clock to the data stream. Problem is that without a stop, maintaining synchronisation on async data is almost impossible, unless you are guaranteeing that the last bit in the data is either a 0 or a 1, so this effectively becomes the stop. I've seen some Chinese GPS modules claiming to use 0 stop bits, but this turned out to be a Chinglish mis-translation. The NMEA $PSRF10x configuration, uses 0/1 for 1/2 stop bits, and they were saying the unit came set for $PSRF100. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9219 Location: Greensville,Ontario
|
|
Posted: Wed Nov 18, 2015 8:50 am |
|
|
I actually read the datasheet,section 22 and MR. T is right, the hardware UART only can do one stop bit.silly me I assumed that today's UARTs were backward compatible to the 'old school' 1602s and such....
Now I'm assuming it's a 'cost saving' reason...mainly due to 99.999% of the serial communications with UARTs is 8-N-1 ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19482
|
|
Posted: Wed Nov 18, 2015 9:04 am |
|
|
Thing to remember, is that using x,n,1, you can happily receive data that is x,n,1 x,n,1.5 or x,n,2. For sending, you just need to add a delay, which can be done with an extra bt. So if you set the PIC UART up to 9,n,1, and sent a 0 9th bit, this would be acceptable to a device at the other end expecting 8,n1, 8,n,1.5 or 8,n,2.
So it is possible to use the PIC UART for most formats without problems.
However the UART does take the 'line of least cost' here, to cover the 95% of cases that only use one stop bit.
In fact if you set the PIC UART to use 9,n,1 and then set the ninth bit to 0, this will accept for receive 8,n,1 8,n,1.5 & 8,n,2. For transmit, the output will be accepted by devices wanting 8,n,1 8,n,1.5 & 8,n,2, so there is no need to ever switch. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|