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

multiple uarts with gps
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri May 17, 2013 7:59 pm     Reply with quote

Hi andys,

Receiving garbage data is usually indicative of a baud rate mis-match between the 'sender' (the GPS) and the 'receiver' (your PIC). You have the GPS baud rate set to 4800. Are you sure that is correct? I don't think you told us which GPS you are using. Can you post a link?

Receiving 'something' is progress, so let's figure out how to make it receive the correct data!

John
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multiple uarts with gps
PostPosted: Sat May 18, 2013 6:34 am     Reply with quote

according the specification of the module ,
the baud rate is :4800 ~ 115200 bps.


I have a module like this :
http://www.ebay.com/itm/280851205239?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

The manuals are here.

http://www.gtop-tech.com/en/product/MT3339_GPS_Module_03.html


If you want i can sent you the detail datasheet .
temtronic



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

View user's profile Send private message

PostPosted: Sat May 18, 2013 7:49 am     Reply with quote

had a quick look at the website...
1) you'll have to confirm the default baudrate is set for 4800.....

2) that unit needs close to a minute to get good readings..
so you should delay a minute to be sure data is good.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 20161

View user's profile Send private message

PostPosted: Sat May 18, 2013 9:25 am     Reply with quote

I think that's based on a Mediatek chip. If so the _default_ baud rate is 9600bps.

Best Wishes
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat May 18, 2013 4:32 pm     Reply with quote

Hi All,

More importantly, that module appears to have a TTL serial interface, so andys does not need the MAX232 between the GPS and the PIC!

Connect the GPS Tx pin to the PIC Rx pin. Connect the GPS Rx pin to the PIC Tx pin. Hopefully there is no damage incurred by the use of the MAX232!

John
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multiple uarts with gps
PostPosted: Sat May 18, 2013 8:25 pm     Reply with quote

Hello ezflyr,
Quote:

that module appears to have a TTL serial interface, so andys does not need the MAX232 between the GPS and the PIC!

Where did you find it ? Because i tried it but unfortunately is not working.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat May 18, 2013 8:36 pm     Reply with quote

Hi andys,

In the 1st link you sent (for eBay), it shows the connection of the GPS to a microcontroller, with no MAX232 device. The page also mentions that the baud rate is 115200!

What's happening with the GPS and the PIC connected directly together? Are you still receiving garbage?

John
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multiple uarts with gps
PostPosted: Wed May 22, 2013 6:39 pm     Reply with quote

I tried the code

Code:

#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600,STREAM=COM_A)


#PIN_SELECT U2TX=PIN_B13
#PIN_SELECT U2RX=PIN_B12
#USE RS232(UART2,ERRORS,BAUD=115200,STREAM=COM_B)


#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc()
{
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}


int main() {
 char comandoGPR;
int i;
 enable_interrupts(int_rda);
enable_interrupts(intr_global);

fprintf(COM_A,"Online\n\r");
      while(1)
      {
   delay_ms(10000);
    while(bkbhit)
   putc( bgetc() );
   printf("\r\nBuffered data => ");
   
      }

return 0;
}





and when i used it i get the results :
Buffered data =>
Buffered data =>
Buffered data =>
Buffered data =>
Buffered data =>
Buffered data =>
Buffered data =>
Buffered data =>
jeremiah



Joined: 20 Jul 2010
Posts: 1426

View user's profile Send private message

PostPosted: Wed May 22, 2013 8:07 pm     Reply with quote

When using streams for uarts, you need to use:

instead of getc, use fgetc
instead of printf, use fprintf
instead of putc, use fputc

Those are in the manual.

And specify the correct stream, otherwise you don't know which stream is being used in your code.
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multiple uarts with gps
PostPosted: Wed May 22, 2013 8:34 pm     Reply with quote

jeremiah, what do you mean by "specify the correct stream" ???
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu May 23, 2013 6:37 am     Reply with quote

Hi andys,

Look up the fputc(), fgetc(), and fprintf() functions in the CCS manual. You'll see that these functions require that you specify the serial 'stream' that you want to use for input/output. When you have multiple streams, this ensures that your data is following to/from the intended serial device.

For example, this sample code will retrieve a byte of data from the 'COM_B' serial stream:

Code:

       buffer[next_in]=fgetc(COM_B);


CCS Manual: http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

John


Last edited by ezflyr on Sat May 25, 2013 7:17 am; edited 1 time in total
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multiple uarts with gps
PostPosted: Sat May 25, 2013 7:05 am     Reply with quote

I did the following changes :

Code:

   buffer[next_in]=getc(COM_B);
   
   putc(getc(COM_B),COM_A);


but i still have problems .

I used a 20M crystal (Is this enought?)
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat May 25, 2013 7:21 am     Reply with quote

Hi andys,

Sorry, I made a typo, it's 'fgetc()'

Post your entire new code, and I'll have a look. From what you posted, it appears that you may be trying to retrieve GPS data using two conflicting methods....

20Mhz is more than enough for what you are trying to do?

John
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

multiple uarts with gps
PostPosted: Sat May 25, 2013 6:03 pm     Reply with quote

My code is presented below:
Code:

#include <33fj128GP202.h>
#include <string.h>
#include <ctype.h>

#fuses HS, NOWDT, PR, NOPUT,NOPROTECT
#use delay (clock=20M)

#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600,STREAM=COM_A,ERRORS)

#PIN_SELECT U2TX=PIN_B13
#PIN_SELECT U2RX=PIN_B12
#USE RS232(UART2,ERRORS,BAUD=115200,STREAM=COM_B,ERRORS)

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=fgetc(COM_B);
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc()
{
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main() {
 enable_interrupts(int_rda);
enable_interrupts(intr_global);

fprintf(COM_A,"Online\n\r");
output_high(pin_A0);
delay_ms(50);
      while(1)
      {

    while(bkbhit)
   fputc(fgetc(COM_B),COM_A);
   delay_ms(50);
   }

}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat May 25, 2013 9:00 pm     Reply with quote

Hi andys,

You aren't getting data correctly from circular receive buffer. You are using fgetc() correctly inside your serial interrupt, but you need to use bgetc() inside Main() to extract characters from the receive buffer as they come in.

Try these changes, and see if they make a difference:

Code:

 void main()
{

char Temp;

enable_interrupts(int_rda);
enable_interrupts(global);

fprintf(COM_A,"Online\n\r");
output_high(pin_A0);

      while(1)
      {

          if (bkbhit)
          {
              Temp = bgetc();
              fputc(Temp, COM_A);
          }
      }

}   



I assume that your serial communications are working with the PC, and that you can see the "Online" message? If you still don't receive data from the GPS, you might connect the MAX232 and the PC to the 2nd PIC UART, and see if you can successfully send data. If you are receiving data from the GPS, but it's garbage, you should try different baud rates...

John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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