This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPS data is lost during reading

Other Parts Discussed in Thread: TM4C129XNCZAD

Hello,

       I read the characters and stored in buffer using UART0 communication but  i am not able to store the incomming GPS data to buffer  how do i store this data to buffer please help me

Thanks for ur help

  • Hello Basawaraj,

    No code for inspection?

    Regards
    Amit
  • Need to concur with Amit - presenting code would be helpful.

    But also, you need to get a grip on the characteristics on GPS transmissions via serial line (I assume NMEA 183 ASCII format).

    • sentences have a variable length
    • a sentence has a fixed/defined start character ($) and termination character(s) (\r\n)
    • transmissions use to come in bursts - at the defined update rate, all enabled sentences are sent in short succession

    For my application using GPS (NMEA 183, mostly on a competitor's MCU), I used the following strategy:

    • single character UART reception interrupt
    • reception into a buffer sufficient for the longest possible sentence (e.g. 128 byte)
    • on buffer size overflow, reset index pointer to zero (avoid overflow)
    • on sentence start character ($), reset index to zero
    • on 'normal' characters, store and advance index pointer
    • on termination character, check for proper start character, and copy sentence to another buffer for parsing, and set a 'ready' flag

    The last step is important. Otherwise, the next transmission will start to overwrite your buffer while you about to parse it. Remember, those sentences come in bursts. I never do the parsing in the interrupt routine - otherwise you will lose character of following sentences, and thus the whole sentence. Instead, I check a flag in the main application loop, and enter parsing as soon as the interrupt routine reports an available sentence. Except for the proper start/termination character, I do no further syntax checking in the interrupt.

    For the parsing of NMEA 183, there should be plenty of examples around - just ask your favourite search engine. That is not really TM4C specific. You may, however, need to make a choice how much "library support" you want to pull in (for string/integer number/ float number parsing), and what you want to write yourself, to safe Flash memory space.

  • No code for inspection...(i.e. DO my homework...all of it...NOW... ... ... of course...it's urgent)

    As always - if such posters do NOT need their homework done/completed - they (surely) require Guidance!

  • Hello,
    Below is my code for Recieving GPS data but i am getting only '$' character remaining characters are lossing please help me
    #include <stdint.h>
    #include <stdbool.h>
    //#include "stdlib.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_uart.h"
    #include "inc/hw_gpio.h"
    //#include "inc/hw_pwm.h"
    #include "inc/hw_types.h"
    #include "driverlib/adc.h"
    #include "driverlib/timer.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    //#include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "driverlib/ssi.h"
    #include "driverlib/systick.h"
    #include "driverlib/adc.h"
    #include "utils/uartstdio.h"
    #include "utils/uartstdio.c"
    #include<inc/tm4c129xnczad.h>
    #define GPIO_PA0_U0RX 0x00000001
    #define GPIO_PA1_U0TX 0x00000401


    void printchar( char c);
    char readchar();
    void printstring(char *string);

    int main()
    {
    int c;
    char s[30];
    char *string;
    int i=0;
    SYSCTL_RCGCUART_R|=(1<<0);
    SYSCTL_RCGCGPIO_R=(1<<0); //enable clock to porta gpio
    GPIO_PORTA_AHB_AFSEL_R=(1<<1)|(1<<0);
    GPIO_PORTA_AHB_PCTL_R=(1<<0)|(1<<4);
    GPIO_PORTA_AHB_DEN_R=(1<<0)|(1<<1);
    UART0_IFLS_R=(0x4<<2);
    //UART0_IFLS_R
    UART0_CTL_R|=(1<<4);
    UART0_CTL_R&=~(1<<0);
    UART0_IBRD_R=104;
    UART0_FBRD_R=11;
    UART0_LCRH_R=(0x3<<5);
    UART0_CC_R=0X0;
    UART0_CTL_R=(1<<0)|(1<<8)|(1<<9);
    SYSCTL_RCGCGPIO_R |=(1<<14);
    GPIO_PORTQ_DIR_R=(1<<7)|(1<<4);
    GPIO_PORTQ_DEN_R=(1<<7)|(1<<4);
    GPIO_PORTQ_DATA_R &=~(1<<7)|(1<<4);
    printstring("enter \"r\",\"g\",or \"b\":\n\r");
    while(1)
    {
    for(i=0;i<10 && (c=readchar())!='\n';i++)
    {
    s[i]=c;
    }
    if(c=='\n')
    {
    s[i]='\0';
    }
    string=s;
    printstring(s);
    //printchar(c);


    switch(c)
    {
    case 'r':
    GPIO_PORTQ_DATA_R=(1<<7); //red led on
    break;
    case 'g':
    GPIO_PORTQ_DATA_R=(1<<4);
    break;
    case 'b':
    GPIO_PORTQ_DATA_R=(1<<7);
    break;
    case 'A':
    GPIO_PORTQ_DATA_R=(1<<4);
    break;
    case '*':
    GPIO_PORTQ_DATA_R=(1<<7);
    break;
    default:
    GPIO_PORTQ_DATA_R=~((1<<7)|(1<<4));
    break;
    }
    }
    }



    char readchar(void)
    {
    char c;
    while((UART0_FR_R &(1<<4))!=0);

    c=UART0_DR_R;

    return c;
    }
    void printchar(char c)
    {
    while((UART0_FR_R &(1<<5))!=0);

    UART0_DR_R=c;

    }

    void printstring(char *string)
    {
    while(*string!='\0')
    {
    printchar(*(string++));
    }
    }
  • Hello Amit,
    Below is my code for Recieving GPS data but i am getting only '$' character remaining characters are lossing please help me
    #include <stdint.h>
    #include <stdbool.h>
    //#include "stdlib.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_uart.h"
    #include "inc/hw_gpio.h"
    //#include "inc/hw_pwm.h"
    #include "inc/hw_types.h"
    #include "driverlib/adc.h"
    #include "driverlib/timer.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    //#include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "driverlib/ssi.h"
    #include "driverlib/systick.h"
    #include "driverlib/adc.h"
    #include "utils/uartstdio.h"
    #include "utils/uartstdio.c"
    #include<inc/tm4c129xnczad.h>
    #define GPIO_PA0_U0RX 0x00000001
    #define GPIO_PA1_U0TX 0x00000401


    void printchar( char c);
    char readchar();
    void printstring(char *string);

    int main()
    {
    int c;
    char s[30];
    char *string;
    int i=0;
    SYSCTL_RCGCUART_R|=(1<<0);
    SYSCTL_RCGCGPIO_R=(1<<0); //enable clock to porta gpio
    GPIO_PORTA_AHB_AFSEL_R=(1<<1)|(1<<0);
    GPIO_PORTA_AHB_PCTL_R=(1<<0)|(1<<4);
    GPIO_PORTA_AHB_DEN_R=(1<<0)|(1<<1);

    UART0_CTL_R|=(1<<4);
    UART0_CTL_R&=~(1<<0);
    UART0_IBRD_R=104;
    UART0_FBRD_R=11;
    UART0_LCRH_R=(0x3<<5);
    UART0_CC_R=0X0;
    UART0_CTL_R=(1<<0)|(1<<8)|(1<<9);
    SYSCTL_RCGCGPIO_R |=(1<<14);
    GPIO_PORTQ_DIR_R=(1<<7)|(1<<4);
    GPIO_PORTQ_DEN_R=(1<<7)|(1<<4);
    GPIO_PORTQ_DATA_R &=~(1<<7)|(1<<4);
    printstring("enter \"r\",\"g\",or \"b\":\n\r");
    while(1)
    {
    for(i=0;i<10 && (c=readchar())!='\n';i++)
    {
    s[i]=c;
    }
    if(c=='\n')
    {
    s[i]='\0';
    }
    string=s;
    printstring(s);
    //printchar(c);


    switch(c)
    {
    case 'r':
    GPIO_PORTQ_DATA_R=(1<<7); //red led on
    break;
    case 'g':
    GPIO_PORTQ_DATA_R=(1<<4);
    break;
    case 'b':
    GPIO_PORTQ_DATA_R=(1<<7);
    break;
    case 'A':
    GPIO_PORTQ_DATA_R=(1<<4);
    break;
    case '*':
    GPIO_PORTQ_DATA_R=(1<<7);
    break;
    default:
    GPIO_PORTQ_DATA_R=~((1<<7)|(1<<4));
    break;
    }
    }
    }



    char readchar(void)
    {
    char c;
    while((UART0_FR_R &(1<<4))!=0);

    c=UART0_DR_R;

    return c;
    }
    void printchar(char c)
    {
    while((UART0_FR_R &(1<<5))!=0);

    UART0_DR_R=c;

    }

    void printstring(char *string)
    {
    while(*string!='\0')
    {
    printchar(*(string++));
    }
    }
  • Hello Basavaraj,

    DRM is not a recommended method at it brings a lot of ambiguity. I would have expected a TivaWare based approach so that the system clock is defined correctly and so do all the settings of the device.

    Regards
    Amit
  • Hi,
    Please suggest me the appropriate tivaware based tutorials for UART
  • Hello Baswaraj,

    You can refer to the TivaWare Peripheral DriverLib User Guide in TivaWare software installation and the examples in D:\ti\TivaWare_C_Series-2.1.2.111\examples\peripherals\uart

    Regards
    Amit
  • Thanks for suggestion
  • Hello Amit,
    While debugging tivaware UART example i am getting following error Please help for the issue
    Can't find a source file at "/tmp/TI_MKLIBw9rtfe/SRC/_lock.c"
  • Hello Baswaraj,

    I have never seen that issue. Can you make sure that the driverlib.lib is recompiled and then resulting output linked to your project.

    Regards
    Amit