Read NMEA Data via UART STM32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-03 6:37 AM
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
}
}
- Labels:
-
STM32L0 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-03 2:45 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-03 3:08 PM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-03 5:08 PM
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 */
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-09 4:32 AM
Hi Clive thank you for your help
I now have another question, how do I get the GPVTG Sentence without the other?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-27 10:26 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-28 4:11 AM
https://github.com/cturvey/RandomNinjaChef/blob/main/f746g_disco_gps.c
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-31 3:28 PM
Thank you. I now have this working on an STM32L053
