cancel
Showing results for 
Search instead for 
Did you mean: 

why i couldn't receive continuous data of GPS over UART?

VPras
Associate II

Hi,

I am trying to get the NMEA data over UART and print it over another uart .But when i try read in loop after writing data to PC ,I'm not receiving any data. what could be the issue?

any ideas ??

22 REPLIES 22
Trevor Jones
Senior

just use this function to make the pointers the same

void clearRxBuffer(void) {

U1RxBufferPtrIN = U1RxBufSize - huart1.hdmarx->Instance->CNDTR;

U1RxBufferPtrOUT = U1RxBufferPtrIN;

}

then readable will return a zero, until a byte is received.

T J
Lead

actually, you should never clear the buffer.. just keep reading bytes from the circular DMA buffer like this:

I use this to check a frame... initialise haveGPSstringbytes = false;

if( ! haveGPSstringbytes){
                int length =  readableU1();       
                if (length >= 2)
                {
                    char firstByte =  peekRxU1(0);
                    char secondByte =  peekRxU1(1);
                
                    char readByte =  readU1();   // read and dump byte if not start of frame
               
                    if ((firstByte == '$') && (secondByte == 'G'))
                    {
                        GPSlength = 0;
                        haveGPSstringbytes = true;
                        GPSstring[GPSlength++] =  readByte; 
                    }
                }    
       }else{ 
         char readByte =  readU1();
         GPSstring[GPSlength++] =  readByte;
         
          //read in frame to end         
         // when you have a complete frame
          haveGPSstringbytes = false; //start new frame detector
          flagGPSFrameReceived = true;
        }

VPras
Associate II

Thanks TJ,

code is working ,before i was using normal mode instead of circular mode.