cancel
Showing results for 
Search instead for 
Did you mean: 

Read NMEA Data via UART STM32

MSchmutz
Associate II

Hello

I am currently working on a microcontroller project I am building a GPS tachometer which transfers the NMEA data of the GNSS 4 Click Module from Mikroe via UART to my STM32L052K6T6 and outputs it to a display

I have so far UART initialized with the BAUD rate and so on my question is now how can I read the NMEA data correctly from the USART1->DRD (data register) so that I can store a readable string in a variable and output it to a display

I have as far as the data register is stored in a char this is correct ? how can I read the NMEA data from it ? I am still a beginner in this topic...

Below you can see my code, which I already have

I would be very grateful for any help :D

void USART1_IRQHandler(void) 

{

   char data;

   //check if we are here because of RXNE interrupt

   if ((USART1->ISR & USART_ISR_RXNE) == USART_ISR_RXNE) //if RX is not empty (Received character ?)

   {

     data = (uint8_t)USART1->RDR;           //Receive data, clear flag 

     while (!(USART1->ISR & USART_ISR_TC));

     // ... make your stuff with the received byte(s)

     USART1->ICR = USART_ICR_TCCF; // Clear TC flag

     USART1->CR1 = USART_CR1_TCIE; // Enable TC interrupt

      

     lcdWriteNumberPos(2, 9, "%.2f", data);

     lcdWriteStringPos(2, 12, "km/h");

   }

   //check if we are here because of TXEIE interrupt

   if (USART1->ISR & USART_ISR_TXE)  //if TX is not empty

   {

   //handle transmit completion here

   } 

 }

7 REPLIES 7
TDK
Guru

So you're able to receive individual characters? You need to set up a buffer which you can then process when you receive the ending characters (CRLF). And don't start storing into the buffer until a starting character ($) is received. The buffer should track how many characters are currently stored.

If you feel a post has answered your question, please click "Accept as Solution".

You probably don't have time to take excursions to write to the lcd in the handler, you have only a single byte time.

Here's a more complete example I posted for the F746I-DISCO

https://community.st.com/s/contentdocument/0690X000008B85YQAS

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Just curious why you used this construct in your code vs "while(1)" as you did in the other functions

void _sys_exit(int return_code)
{
label:  goto label;  /* endless loop */
}

Hi Clive thank you for your help

I now have another question, how do I get the GPVTG Sentence without the other?

Hi Tesla,

I've tried to follow the link you provided, but as the thread is so old it has disappeared.

Any chance you could let me know what that linked contained?

Regards

Sean

 

https://github.com/cturvey/RandomNinjaChef/blob/main/f746g_disco_gps.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you. I now have this working on an STM32L053