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

Two Hardware serial ports in PIC18F26K22-Issues

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



Joined: 26 Jan 2011
Posts: 31

View user's profile Send private message

Two Hardware serial ports in PIC18F26K22-Issues
PostPosted: Sat Aug 25, 2018 7:17 am     Reply with quote

I am trying to get GPS data connected to UART1 and print it through the second UART to my serial console.
Do I have to use streams?
I am getting some garbage values in between. What may be the reason?
CCS version is 4.140

Code:

void main()
{
while(True)
{
if (kbhit())
{
printf("%s",getc());
delay_ms(200);
}
temtronic



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

View user's profile Send private message

PostPosted: Sat Aug 25, 2018 7:19 am     Reply with quote

You should use streams AND Interrupt driven serial buffers. See EX_SISR.C as a basic example. Doing that I've run both HWUARTS on the 18F46K22 at 115K200 for weeks with ZERO problems.
Ttelmah



Joined: 11 Mar 2010
Posts: 19554

View user's profile Send private message

PostPosted: Sat Aug 25, 2018 1:26 pm     Reply with quote

If you have more than one serial port, you must use streams. These are what allows the code to know which port you want to talk to.
Now, on your posted code, you don't show your #USE RS232. This is essential data....
How is the connection actually made?.
"Garbage values in between", suggests a connection issue. Poor ground or signal pickup.
temtronic



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

View user's profile Send private message

PostPosted: Sat Aug 25, 2018 2:02 pm     Reply with quote

Something I just thought of....
Any chance you're using a 5 volt PIC and a 3 volt GPS ??
empty



Joined: 13 Jan 2018
Posts: 15

View user's profile Send private message

PostPosted: Sun Aug 26, 2018 11:31 am     Reply with quote

You can use 1 UART module for receiving data from the GPS module and sending data to your console, and if you want to use 2 UARTs you've to specify a stream for each module.
Also, you can connect the GPS module directly to your serial console!
Only connect TX pin of the GPS module to MCU RX pin, there is no need to use GPS RX pin, but if you want to connect it (GPS RX) you've to use a proper voltage divider or level converter because your MCU is 5V and the GPS module is 3V (as I think).
The following link may help you:

https://simple-circuit.com/neo-6m-gps-pic18f4550-interfacing/
temtronic



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

View user's profile Send private message

PostPosted: Sun Aug 26, 2018 11:59 am     Reply with quote

comment:
It'd be best to dedicate one HWUART to the GPS, both xmt and rec and the 2nd HWUART to PC interface.

My reasons are
1) having full access to GPS module allows you (the PIC) to custom configure it, say with UART parameters (baud and handshaking). Without knowing which GPS you're using, some today have a LOT of registers that you can configure.
2) using 2 UARTS simplifies the 'setup' of the PIC, say GPS likes 9600 baud and the PC 115K200. Easy, simple when 2 UARTS are used. If you only use 1 UART and have to reset the UART config, some nasty little timing bug or missed data may crop up.
3) consider that each can interrupt the main PIC program. This along with separate buffers allows for better use of the PIC. Faster code means PIC can do more...if (er, when !) required.
4) debugging the code can be easier.
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