Page 1 of 1

How to connect 2 usart (USB,GPS) on the same pic?

Posted: 26 Dec 2009 22:13
by Smith_smith
Hello you guys,
I know how to connect the computer to the PIC via USB (PIC18F4550), and also I can connect both PIC and GPS (Parallax GPS - Serial). Both of them I connect to PIN 26(Rx),25(Tx). My question now, how can I connect both of them, meaning to connect the GPS to the Controller, and from the controller to the controller USB???

Any ideas?

Posted: 27 Dec 2009 07:58
by The_RB
Normally you would use a "soft" usart to generate the slower serial data in software.

So you would use the hardware usart for the USB, and make a soft usart for the GPS.

Your MikroC compiler should have soft usart library functions.

Posted: 28 Dec 2009 00:11
by Smith_smith
Thanks "The_RB" for your reply,
When I opened the example pages, to see the soft ware UART, it gave me the following:

Code: Select all

unsigned short data = 0;
unsigned short recOK;
                                 
void main() {
  Soft_Uart_Init(PORTC, 7, 6, 19200, 0);    // initialize Soft UART

  while (1) {                        
    do {
      data = Soft_Uart_Read(&recOK);        // receive data
    } while (recOK);

    Soft_UART_Write(data);                  // send data via UART
   }
}//~!
        
Which pin in port C is TX and which is Rx???

Thanks!

Posted: 28 Dec 2009 05:10
by Sobrietytest
Normally you would use a "soft" usart to generate the slower serial data in software.

So you would use the hardware usart for the USB, and make a soft usart for the GPS.
That's going to be very difficult with GPS data, Soft_Uart functions have no flow control or buffer so there's no way to know when new data has arrived and if you don't read the byte before the next one arrives you will lose it. As GPS data is a constant stream it will be very easy to run into problems.

In the Soft_Uart example, Rx is on pin 7 and Tx is on pin 6, it's in the help files.

Forgive me for asking but on the 4550 the USB lines are on RC4 & 5 and the Uart is on RC6 & 7. Why the conflict?