2020-11-03 06: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
}
}
2020-11-03 02: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.
2020-11-03 03: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
2020-11-03 05: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 */
}
2020-11-09 04:32 AM
Hi Clive thank you for your help
I now have another question, how do I get the GPVTG Sentence without the other?
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
2024-05-28 04:11 AM
https://github.com/cturvey/RandomNinjaChef/blob/main/f746g_disco_gps.c
2024-05-31 03:28 PM
Thank you. I now have this working on an STM32L053