This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Filtering $GPRMC string

Dear all
I am filtering $GPRMC string but i can't able to get any data in the hyperterminal please suggest me my problem in the code.

/*------------------------------------------------------------------------------
Serial.c
------------------------------------------------------------------------------*/
#include <reg52.H>                /* special function register declarations  */
#include <stdio.h>                /* prototype declarations for I/O functions */
  sbit mybit=P1^1 ;

unsigned char RMC_Pos,GPSReceiveCtr,GPSData,Ctr;
unsigned char  GPSArray[110];
void main(void)
{
RMC_Pos=0;
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFA; /* TH1: reload value for 4800 baud @ 11.0592 MHz */
TR1 = 1; /* TR1: timer 1 run */
ES=1;  /* Serial interrupt Enable*/
EA=1;  /* global interrupt enable*/
while(1)
{
if(RMC_Pos==7)
{
  for(Ctr=0;Ctr>GPSReceiveCtr;Ctr++)
  {
    SBUF=GPSArray[Ctr];
  }
}
RMC_Pos=0;
}
}

void serial (void) interrupt 4

{
  mybit=1;
if(RI)
{
      RI=0;
      GPSData = SBUF;
      if(RMC_Pos!=7)
      {
          if( GPSData== '$' && (RMC_Pos == 0) )
          RMC_Pos=1;
          else if( GPSData == 'G' && (RMC_Pos == 1) )
          RMC_Pos=2;
          else if( GPSData == 'P' && (RMC_Pos == 2) )
          RMC_Pos=3;
          else if( GPSData == 'R' && (RMC_Pos == 3) )
          RMC_Pos=4;
          else if( GPSData == 'M' && (RMC_Pos == 4) )
          RMC_Pos=5;
          else if( GPSData == 'C' && (RMC_Pos == 5) )
          {
                        RMC_Pos=6;
            GPSReceiveCtr=0;
          }
          else if( GPSData != '*' && (RMC_Pos == 6) )
          GPSArray[GPSReceiveCtr++]=GPSData;
          else if( GPSData == '*' && (RMC_Pos == 6) )
          RMC_Pos=7;
          else
          RMC_Pos=0;
          if(GPSReceiveCtr > 100) GPSReceiveCtr=100;
                  mybit=0;
        }
    }
if(TI)TI=0;
}

  • Am expecting to get $GPRMC string
    i connected gps module in the rx pin of 89c51 as gps module gives $GPRMC, $GPGGV, $GPRMA, data's, i need to filter only $GPRMC string and send to tx pin of 89c51 controller.

  • 1) What value would GPSReceiveCtr have when RMC_Pos reaches 7?

    2) If you emit multiple characters into the transmit buffer - do you think they are instantly sent, or do you have a processor with send FIFO?

      for(Ctr=0;Ctr>GPSReceiveCtr;Ctr++)
      {
        SBUF=GPSArray[Ctr];
      }
    

    3) How do you expect RMC_Pos to ever reach 7?

    How much time have _you_ spent trying out your code? Do you think that programming is about writing a couple of lines of code, and then contact a forum for getting it to work?

    It looks like the comments you have is from code you have copied from another project. But why don't you document your own code lines? Are they really doing what you think/expect?

  • Hello per westermark,

    Do you think that i copied this code from somebody else ?
    I myself wrote this code, as am the beginner am facing problem while writting the code, i was guided by a logic from someone.

    Please if you can able ro guide me i will be very much thankful for you.
    according to my view there is no problem in the code.

  • There's a whole section on it at http://www.8052.com/faqs

    In particular, see: www.8052.com/.../120308

    There are also examples included with your Keil installation.

    you need to understand the basics of the 8051 architecture - see: www.8052.com/.../120112

  • It is a reasonable assumption that the lines:

    /*------------------------------------------------------------------------------
    Serial.c
    ------------------------------------------------------------------------------*/
    #include <reg52.H>                /* special function register declarations  */
    #include <stdio.h>                /* prototype declarations for I/O functions */
      sbit mybit=P1^1 ;
    
    unsigned char RMC_Pos,GPSReceiveCtr,GPSData,Ctr;
    unsigned char  GPSArray[110];
    void main(void)
    {
    RMC_Pos=0;
    SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
    TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
    TH1 = 0xFA; /* TH1: reload value for 4800 baud @ 11.0592 MHz */
    TR1 = 1; /* TR1: timer 1 run */
    ES=1;  /* Serial interrupt Enable*/
    EA=1;  /* global interrupt enable*/
    


    are part of a datasheet, an application example or any of the samples installed with Keil. Nothing wrong with that. These are the only lines in your program that contains any comments. The rest of the code - that is 100% specific to your needs - are totally void of any comments. And this part of the code contains big logic errors. Read my comments from the previous post, and spend time trying to simulate this code. What would happen - step by step - with the contents of the variables?

    I think you should separate your problem into two - one is a working serial communication with send and receive. And test what happens if you send 5-10 characters instantly after each other, without synchronizing with the serial port. The sample code available (Andy gave you several links, and you got examples with the compiler installation) will show solutions for:
    - interrupt-driven input/output, in which case you can insert multiple characters into the output buffer.
    - polled input/output, where you have to poll before each character sent.

    Then work with the second step. Look for magic characters (such as '$' or the line break) to figure out the start of an NMEA string. Make sure that the state machine will always restart if you get to a synchronization character. Process characters one at a time until you have found your character. Then make sure that you know how many characters to you have available - and also that you continue to emit characters until you have received and forwarded the full line.

  • 1) What value would GPSReceiveCtr have when RMC_Pos reaches 7?
    

    GPSReceiverCtr will be 70 character when it reaches RMC_Pos reaches 7

  • On one hand - what happens if you try to send 70 characters to the transmit register of your serial port more or less instantly? Do you think the serial port can send out one character every microsecond?

    But are you really sure about your 70?

    What do you think happens here?

              else if( GPSData == 'C' && (RMC_Pos == 5) )
              {
                            RMC_Pos=6;
                GPSReceiveCtr=0;
              }
    


    To get RMC_Pos=7, it first have to be 6.

    Think again about the meaning of the GPSReceiveCtr=0 line.

  • Hi Per Westermark,

    Please gothrough this code,

    while(1);
    }
    void serial (void) interrupt 4
    {
    if(RI)
    {
      RI=0;
      uc=SBUF; // receives the data from rx into the buffer
      SBUF=uc; // transmits the data to tx from the buffer
    }
    if(TI)TI=0;
    }
    

    This code is to receive the gps data and transmitts the gps data from the controller. IN 1hertz gps will be sending $GPRMC, $GPGGA, $GPGTA, $GPRMA datas so if the microcontroller can able to receive and transmitt those data's in one second

    whats strong with the second code that i wrote for filtering the $GPRMC string, it is going to send only the Gprmc string. In previous code it was sending all the strings, there was no problem occured while sending all the strings from the buffer. In one second more than 300 characters was send to the hyperterminal from 89c51 TX pin.

    Please correct me if am wrong.

  • I don't think there's anything particularly "strong" about it - but it certainly looks wrong!

    Have you actually looked at the FAQs list that I suggested earlier about 8051 serial comms?

    In particular, have you actually looked at the Tutorial that I suggested earlier about 8051 serial comms?

    Your ISR tests both RI and TI, and yet you do nothing in the TI section - do you think that's right...?

  • Your GPS sends data serially. If you are able to retransmit with at least the same baudrate as the GPS, then you don't gain anything by filtering away all lines but the $GPRMC - but you do lose the information about the number of satellites, and any signal strengths etc. That is a significant loss, so I wouldn't call your optimization a "strong" solution. With only the $GPRMC, you will not even know if the GPS is in 2D or 3D mode.

  • Please can you rectify the code for me, its already too late i need to submit the project, my college is going to open next week, please do help me, am electrical student, i know only "C" but embedded c is quite complicated for me, as this project technical sounded good i choosed this project, but if i can't able to complete it my team members will sout me. please understand my pressure and complete the code for me.

    Than you.

  • Sorry, it's your task - the object of the exercise is for you to demonstrate your competence in the subject.

    To do it for you would be cheating.

    If you can't complete the required assignment, then you need to discuss the matter urgently with your tutors...

  • Please andy,

    I know this is cheating but there is no time in my hand, i gothrough your faq and tutorial links, but i can able to understand nothing, i have learned about armature, generators, magnetic flux, ac and dc but i never go through buffer, timers, tI, RI, interrupts, in my life time. My tutors also not well sound for guiding me in coding, They guided my in designing hardware by GODs grace i made it sucessfully. The code logic that i wrote was guided by my senior, but he also can't able to solve this problem.
    Please slove this problem to me i will be very much thankful to you.

  • So just don't do it!

    Come clean and admit that you cannot complete the assignment.
    If you bluff this assignment, how will you cope with the next assignment?

    "i have learned about armature, generators, magnetic flux, ac and dc but i never go through buffer, timers, tI, RI, interrupts, in my life time."

    So why on earth are you doing a project that so totally depends upon it?!

    If you really feel that you have followed all the course requirements, and this assignment is totally unrelated to any of the course content, then you need to appeal to your school authorities.

    "Please slove this problem to me i will be very much thankful to you."

    Actually, you probably won't: If you cheat this assignment, then it will be assumed that you can do this stuff - so you will receive more and harder programming tasks!