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 support@ccsinfo.com

Setting up multiple UART on one PIC

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



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

Setting up multiple UART on one PIC
PostPosted: Fri Jan 11, 2019 2:30 pm     Reply with quote

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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 3:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 3:21 pm     Reply with quote

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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 3:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 4:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 4:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 4:42 pm     Reply with quote

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 Smile
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 4:48 pm     Reply with quote

Just a note: open and read (or skim Wink ) 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: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 11, 2019 5:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 14, 2019 10:42 am     Reply with quote

newguy wrote:
Just a note: open and read (or skim Wink ) 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

View user's profile Send private message

PostPosted: Mon Jan 14, 2019 10:42 am     Reply with quote

temtronic wrote:
another note..
While you're working on your project, if you press F11, the CCS Compiler manual will 'magically' open !


thank you Smile
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