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 support@ccsinfo.com

Temperamental UART - Help !!!!

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



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

Temperamental UART - Help !!!!
PostPosted: Tue Nov 25, 2008 1:13 am     Reply with quote

Hi, I am using a PIC18F452 and trying to communicate with a GPS chipset using UART. About 1 out of 20 times when I switch the power to the GPS, the PIC receives the information and displays it on the LCD, otherwise only one character is shown and that's it. Could this be timing or a logic level issue or something else? Any help appreciated.

Note: Relevant code below, most of the LCD intitialising cut out, LCD tested and works fine.
Code:

#include <18f452.h>
#include <string.h>
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#use rs232 (baud=4800, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)

void LCD_INIT (int x);
void DATA_MANIP (unsigned int x);
void KEYPAD (void);
void GPS (void);
//

void main (){
   int i, j;
   char c[20], d[20];

   DATA_MANIP (0x00); // ensure all bits are 0
   delay_ms (1000);
   output_high (GREEN_LED);         

   LCD_INIT (0); //Init lcd . Cursor top line
   output_high (RS_LCD); //Data write
   strcpy (c, "LCD DisplayLine1");
   STRING (c);
   delay_us(100);

   if (kbhit()){
         output_low (GREEN_LED);
         GPS ();
   }
}

void GPS (void){
   char r;

   while(TRUE){
      r=getc();
      DATA_MANIP (r);
   }
}


void LCD_INIT (int x){
..............
}

void DATA_MANIP (unsigned int x){
    output_high (EN_LCD);
    output_bit ( D0_LCD, x & 0x01 );
    output_bit ( D1_LCD, x & 0x02 );
    output_bit ( D2_LCD, x & 0x04 );
    output_bit ( D3_LCD, x & 0x08 );
    output_bit ( D4_LCD, x & 0x10 );
    output_bit ( D5_LCD, x & 0x20 );
    output_bit ( D6_LCD, x & 0x40 );
    output_bit ( D7_LCD, x & 0x80 );
    output_low (EN_LCD);
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 25, 2008 1:46 am     Reply with quote

Quote:
when I switch the power to the GPS

Does this mean the PIC is always on ? Only the GPS is being switched
off and then on again ?


Quote:
#use rs232 (baud=4800, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

At a minimum, you need to add the ERRORS parameter to the #use rs232
statement as shown. You have a big delay before you ever call getc().
If you get an overrun error, the ERRORS parameter will allow it to be
cleared automatically and prevent the UART from locking up.
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Wed Nov 26, 2008 3:24 am     Reply with quote

Cheers. Works mint now!!!
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