View previous topic :: View next topic |
Author |
Message |
ratheeshbr
Joined: 26 Jan 2011 Posts: 31
|
Two Hardware serial ports in PIC18F26K22-Issues |
Posted: Sat Aug 25, 2018 7:17 am |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 25, 2018 7:19 am |
|
|
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: 19546
|
|
Posted: Sat Aug 25, 2018 1:26 pm |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Aug 25, 2018 2:02 pm |
|
|
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
|
|
Posted: Sun Aug 26, 2018 11:31 am |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Sun Aug 26, 2018 11:59 am |
|
|
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. |
|
|
|