View previous topic :: View next topic |
Author |
Message |
picj1984
Joined: 01 Mar 2010 Posts: 73
|
Setting up multiple UART on one PIC |
Posted: Fri Jan 11, 2019 2:30 pm |
|
|
I've been searching around but I've had no luck. Are there any examples floating around of how to set up multiple UARTs on the same PIC?
I tried using two #use RS232 declarations but that seems to be a no go on compile.
Any help is greatly appreciated. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 3:18 pm |
|
|
OK... you should post which PIC you want to use. Years ago I settled on the PIC18F46K22 as my goto PIC. It has 2 HW UARTS, plus lots of other 'stuff'.
CCS shows how in the FAQ section of the manual or the Q&A area.
There is a HUGE difference in SW vs HW UARTS ! If you need to transmit data to several devices, then SoftWare UARTS may work for you. keep in mind they will be 'bitbanged'( TOTALLY driven in software) unlike HW UARTS. Also if you need to RECEIVE data, you'll have to be clever and use a pin with an interrupt, one for each serial port.
Speed and data are important concerns, HW UARTS are the only sane way to have several ports. A better descripion of your project will help us 'finetune' our replies.
2 decades ago I made a 5 chnl RS-232 box(1 in , 4 out) using a 16C84, 4MHz xtal.Only needed 300 Baud though.
Jay |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Fri Jan 11, 2019 3:21 pm |
|
|
temtronic wrote: | OK... you should post which PIC you want to use. Years ago I settled on the PIC18F46K22 as my goto PIC. It has 2 HW UARTS, plus lots of other 'stuff'.
CCS shows how in the FAQ section of the manual or the Q&A area.
There is a HUGE difference in SW vs HW UARTS ! If you need to transmit data to several devices, then SoftWare UARTS may work for you. keep in mind they will be 'bitbanged'( TOTALLY driven in software) unlike HW UARTS. Also if you need to RECEIVE data, you'll have to be clever and use a pin with an interrupt, one for each serial port.
Speed and data are important concerns, HW UARTS are the only sane way to have several ports. A better descripion of your project will help us 'finetune' our replies.
2 decades ago I made a 5 chnl RS-232 box(1 in , 4 out) using a 16C84, 4MHz xtal.Only needed 300 Baud though.
Jay |
Very cool, thank you Jay! I'm using a PIC16F1527, so I'm hoping to use 2 HW UARTs |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 3:32 pm |
|
|
I just downloaded the datasheet, it has 2 HW UARTs and they're on fixed pins so easy to use providing your compiler version has it. Simply read about #use RS232( streams=....)
Jay |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Fri Jan 11, 2019 4:18 pm |
|
|
temtronic wrote: | I just downloaded the datasheet, it has 2 HW UARTs and they're on fixed pins so easy to use providing your compiler version has it. Simply read about #use RS232( streams=....)
Jay |
amazing! is there a way to separate interrupts for separate streams?
I'm trying #INT_RDAx but it is saying Invalid Pre-Processor directive. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 11, 2019 4:26 pm |
|
|
This compiles with no errors or warnings:
Code: |
#include <16F1527.h>
#fuses NOWDT
#use delay(internal=4M)
#use RS232(UART1, baud=9600, ERRORS, stream=STR1)
#use RS232(UART2, baud=9600, ERRORS, stream=STR2)
//------------------------
#int_rda
void rda_isr(void)
{
char c;
c = getc(STR1);
}
//------------------------
#int_rda2
void rda2_isr(void)
{
char c;
c = getc(STR2);
}
//===============================
void main(void)
{
while(TRUE);
} |
|
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Fri Jan 11, 2019 4:42 pm |
|
|
PCM programmer wrote: | This compiles with no errors or warnings:
Code: |
#include <16F1527.h>
#fuses NOWDT
#use delay(internal=4M)
#use RS232(UART1, baud=9600, ERRORS, stream=STR1)
#use RS232(UART2, baud=9600, ERRORS, stream=STR2)
//------------------------
#int_rda
void rda_isr(void)
{
char c;
c = getc(STR1);
}
//------------------------
#int_rda2
void rda2_isr(void)
{
char c;
c = getc(STR2);
}
//===============================
void main(void)
{
while(TRUE);
} |
|
it worked!! Thank you |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Jan 11, 2019 4:48 pm |
|
|
Just a note: open and read (or skim ) the processor's header file. This would be the 16F1527.h for example. Near the bottom (usually) is a list of all supported interrupts. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 5:20 pm |
|
|
another note..
While you're working on your project, if you press F11, the CCS Compiler manual will 'magically' open ! |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Mon Jan 14, 2019 10:42 am |
|
|
newguy wrote: | Just a note: open and read (or skim ) the processor's header file. This would be the 16F1527.h for example. Near the bottom (usually) is a list of all supported interrupts. |
ahhh... thank you. that's going to be really helpful for me moving forward. |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Mon Jan 14, 2019 10:42 am |
|
|
temtronic wrote: | another note..
While you're working on your project, if you press F11, the CCS Compiler manual will 'magically' open ! |
thank you |
|
|
|