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

Best way to use 2 UARTS

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



Joined: 28 Jan 2011
Posts: 16

View user's profile Send private message

Best way to use 2 UARTS
PostPosted: Mon Nov 14, 2011 2:04 am     Reply with quote

I have a 18F46K80 with 2 hardware uarts. I'll be using one to sending/receiving Bluetooth commands whenever the user wants to (so maximum priority), and the other one to receive GPS data all the time.

What would be the best structure to program this? Do anyone have an example of 2 UARTS to have a look at.

Thanks in advance
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Nov 15, 2011 7:57 am     Reply with quote

do you have NO ideas on how to do this??

is so perhaps you might choose another,
safer to your reputation, line of endeavor?

otherwise consider having a try at it first.

Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 15, 2011 7:59 am     Reply with quote

There is no 'best' structure. Code is 'creative', subject to the whims of the cutter.
Overall you'll need to use 2 ISRs for the UARTs, buffered data and possibly some form of 'state machine'. CCS kindly provides examples of all of the above in their 'examples' folder.
I suggest you cut code in 'sections'. Starting with the GPS code, then adding a non-Bluetooth interface (aka simple RS232) to a PC. Once that's working then add the Bluetooth code. 1-2-3 easy steps. Done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 15, 2011 12:16 pm     Reply with quote

You would define the two hardware UARTS with two #use rs232()
statements. Give each statement a "stream" name. Then use fputc(),
fgetc(), fprintf(), etc., and always put the desired stream name with those
functions, to tell the compiler which stream to use.

Then you could take the code examples in Ex_sisr.c and convert it to
use streams, and then make two copies of it. In the 2nd copy, you will
have to rename all the functions. One receive interrupt routine would be
for #int_rda, and the other one would be for #int_rda2.

When you're done, you will have two interrupt-driven receive fifo buffers,
one for each hardware UART.
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