View previous topic :: View next topic |
Author |
Message |
romanrdgz
Joined: 28 Jan 2011 Posts: 16
|
Best way to use 2 UARTS |
Posted: Mon Nov 14, 2011 2:04 am |
|
|
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
|
|
Posted: Tue Nov 15, 2011 7:57 am |
|
|
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.
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Nov 15, 2011 7:59 am |
|
|
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
|
|
Posted: Tue Nov 15, 2011 12:16 pm |
|
|
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. |
|
|
|