Skip to main content
Visitor II
November 3, 2020
Question

Read NMEA Data via UART STM32

  • November 3, 2020
  • 2 replies
  • 5170 views

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

   } 

 }

    This topic has been closed for replies.

    2 replies

    Super User
    November 3, 2020

    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.

    Graduate II
    November 3, 2020

    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

    Explorer II
    November 4, 2020

    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 */
    }