CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

stop bit on UART

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ELINAP



Joined: 05 Sep 2013
Posts: 14

View user's profile Send private message

stop bit on UART
PostPosted: Wed Nov 18, 2015 4:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 18, 2015 5:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 18, 2015 6:45 am     Reply with quote

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

View user's profile Send private message

solved
PostPosted: Wed Nov 18, 2015 7:37 am     Reply with quote

Thanks. It's clear now
Ttelmah



Joined: 11 Mar 2010
Posts: 19482

View user's profile Send private message

PostPosted: Wed Nov 18, 2015 8:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 18, 2015 8:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 18, 2015 9:04 am     Reply with quote

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. Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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