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

RS232 will not start (reliably)

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



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

RS232 will not start (reliably)
PostPosted: Tue Sep 27, 2005 6:30 pm     Reply with quote

I am using an 18F4680 to receive GPS serial data but can not make it start up every time. The PIC board supplies ground, +12, along with TX/RX on the same cable to the GPS. If I restart the PIC with GPS on, I get no joy. I have put bit-toggle flags in the ISR to check if its even getting there, and it is not.

However, if the GPS is off when I reset the PIC, wait a few seconds, then turn on the GPS, all works as intended. Is there something I need to initialize, or otherwise set up?

As always, help is appreciated

Steve

Code:

//   fuel_gps_test_1.c   Changing to 'F4680

//   Fuel_GPS_test.c
//   This works, BUT:  if GPS quits/powers down, the system will think
//   that the last entry is still current.  Need a way to check whether
//   or not the GPS is working, and if not, set some flag, or other.

#include <18f4680.H>
//#include <16f877a.H>
#device *=16
#FUSES HS,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
#use fast_io(e)

////////////////////////////////////////////////////////////////////////////


#include "noritake_fms_4.h"
#include "ram_address20.h"
#include <stdlib.h>
#include <math.h>

//char gps_text;
//int gps_string_pos;

//char ns_string[5];         //   4 ascii characters + null term to make it a string
//char ew_string[5];

#int_RDA
void RDA_isr(void)
   {
 output_toggle(pin_e0);      //   flag to check entrance to this ISR

    gps_text = getc();          //   char sent from Garmin
    if (gps_text == 0x40)        // 0x40 = @, which is start of gps sentence
      gps_string_pos = 1;      //   start tracking character position   
   else
      gps_string_pos++;
   if(gps_string_pos > 41 && gps_string_pos < 46)
      switch (gps_string_pos)
         {
         case 42: ew_string[0] = gps_text;
                break;
         case 43: ew_string[1] = gps_text;
                break;
         case 44: ew_string[2] = gps_text;
                break;
         case 45: ew_string[3] = gps_text;
                break;
         }

   if(gps_string_pos > 46 && gps_string_pos < 51)
      switch (gps_string_pos)
         {
         case 47: ns_string[0] = gps_text;
                break;
         case 48: ns_string[1] = gps_text;
                break;
         case 49: ns_string[2] = gps_text;
                break;
         case 50: ns_string[3] = gps_text;
                misc_flag.gps_data_in = 1;
                output_toggle(pin_e1);
                break;
         }
   }




void main()
   {
   delay_ms(500);

   vfd_init();
   vfd_putc("\f  GPS receive test");

   set_tris_e(0);
   set_tris_c(0b10100111);
   delay_ms(2000);
   gps_string_pos = 0;
   misc_flag.gps_data_in = 0;

   ns_string[4] = 0x00;         //   write the 'null' character
   ew_string[4] = 0x00;         //   write the 'null' character

   enable_interrupts(global);
   enable_interrupts(int_rda);

   while(TRUE)
      {
    output_toggle(pin_e2);
      if(misc_flag.gps_data_in == 1)      //   both data words are in
         {
         misc_flag.gps_data_in = 0;      //   clear flag
         vfd_gotoxy(1,2);
         vfd_putc("                        ");
         vfd_gotoxy(1,2);
         temp16_1 = atol(ns_string);
         printf(vfd_putc,"%lu",temp16_1);
         vfd_gotoxy(12,2);
         temp16_2 = atol(ew_string);
         printf(vfd_putc,"%lu",temp16_2);
         temp16_1 *= temp16_1;
         temp16_2 *= temp16_2;
         temp16_1 += temp16_2;
         float_1 = temp16_1;
         float_1 /= 10;
         float_2 = sqrt(float_1);
         temp16_1 = float_2;
         }
      }
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 27, 2005 6:39 pm     Reply with quote

Before we do any other analysis, add the ERRORS parameter
to your #use rs232 statement, as shown in bold below

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
cmdrdan



Joined: 08 Apr 2005
Posts: 25
Location: Washington

View user's profile Send private message

PostPosted: Tue Sep 27, 2005 6:45 pm     Reply with quote

In addition to PCM's advice on ERRORS, verify the GPS baud rate. Mine runs at 4800 baud, not 9600....

Dan
eyewonder300



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

PostPosted: Tue Sep 27, 2005 6:52 pm     Reply with quote

OK, I put the 'ERRORS' parameter in the 'use rs232' line, and it seems to work.

I looked at my CCS manual, and it just said that 'ERRORS' will save the receive errors in a variable, and then reset the error condition. This seems to work for my simple, receive-only application, unless there is something else that I should look at.

Thanks, PCM

Also, I have previously tested live reception (after the forced start-up) of the data of interest, and it appears OK

Steve
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