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

General discussion on mikroC.
Post Reply
Author
Message
Smith_smith
Posts: 9
Joined: 01 Nov 2009 23:41

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

#1 Post by Smith_smith » 26 Dec 2009 22:13

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?

The_RB
Posts: 172
Joined: 18 Jan 2008 05:32
Location: Australia
Contact:

#2 Post by The_RB » 27 Dec 2009 07:58

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.
Using; EasyPic4, EasyPIC6, BigPic4, MikroC. MPLab, MPASM.
C since 1991, PIC asm since 1998. Author of many freeware and open-source goodies; www.RomanBlack.com Designer of the www.TalkBotBrain.com talking PIC project.

Smith_smith
Posts: 9
Joined: 01 Nov 2009 23:41

#3 Post by Smith_smith » 28 Dec 2009 00:11

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!

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

#4 Post by Sobrietytest » 28 Dec 2009 05:10

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?

Post Reply

Return to “mikroC General”