cancel
Showing results for 
Search instead for 
Did you mean: 

Can't communicate properly with X-NUCLEO-GNSS1A1

PTsen
Associate III

Hi, as the title said, I am having the hard time communicating with X-NUCLEO-GNSS1A1

The GNSS module is communicate via USART (can't communicate via I2C, but this is the other problem)

the code is written as follow:

void usart_setup(void)
{
       // some setup .....
}
 
volatile char gnss[180];
 
 
void gnss(void* args __attribute__((unused)))
{
    for(;;)
    {
        int i = 0;
		for (char a = usart_recv_blocking(USART1); a != '\r' || i < 180; a = usart_recv_blocking(USART1), ++i)
		{
			gnss[i] = a;
		}
    }
}
 
void usart_status_updater(TimerHandle_t xTimer)
{
	printf("%s\n\r", gnss);
}
 
int main(void)
{
        usart_send_stat_timer = xTimerCreate("USART_TIM", STATUS_UPDATE_PRD, pdTRUE, (void *) 0, usart_status_updater);
        xTaskCreate(gnss, "gnss", 1024, NULL, configMAX_PRIORITIES - 1, NULL);
 
	xTimerStart(usart_send_stat_timer, 0);
	vTaskStartScheduler();
}

For some reason, I cannot use HAL/LL library, and I'm using opencm3, but I think this is not the reason, also, there is some freeRTOS stuff inside, but it also should not be the reason, the result is shown in the picture

0690X000006CuzcQAC.jpg

As one can see, the command of the message doesn't show properly, e.g. "$SA" instead of $GPGSA "", having a larger buffer does not solve the problem. What should I do to fix the problem?

I have read the src code in CubeMS, and it is really hard to understand it, also there is a little example online, so I am literally in the dark, the software manual is not that clear IMO, even though I know those command, but I simply can't produce expected result.

This is only one of the problems, any advice or idea will be appreciated, thank you

1 ACCEPTED SOLUTION

Accepted Solutions

The GNSS streams ASCII data, it is not complex. You have no synchronization between multiple tasks. Waiting for characters to arrive will block, printing characters/strings will block. The stream does not stop to make things convenient for you, and the USART hardware will not buffer data.

>>What should I do to fix the problem?

Decide how you're going to handle the data and the inter-task communication. Decide if you understand the dynamics sufficiently to use multiple tasks, and if not handle it more linearly.

I've posted NMEA examples to the forum on multiple occasions, I'd recommend collecting lines in the USART IRQ handler, and then queuing the complete sentences to a task that then parsing and prints the lines.

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

View solution in original post

6 REPLIES 6

The GNSS streams ASCII data, it is not complex. You have no synchronization between multiple tasks. Waiting for characters to arrive will block, printing characters/strings will block. The stream does not stop to make things convenient for you, and the USART hardware will not buffer data.

>>What should I do to fix the problem?

Decide how you're going to handle the data and the inter-task communication. Decide if you understand the dynamics sufficiently to use multiple tasks, and if not handle it more linearly.

I've posted NMEA examples to the forum on multiple occasions, I'd recommend collecting lines in the USART IRQ handler, and then queuing the complete sentences to a task that then parsing and prints the lines.

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

Hi, thanks for your quick response, I'll try using IRQ tomorrow. I'll update the result asap.

Hi, this is my result, is this the thing that I should expect? There seems to have some weird new line.​

0690X000006Cv27QAC.jpg

​I'm using USART IRQ now, the result look a lot more better than previous one, but I'm not sure if this is correct or not.

The code now becomes

volatile char gnss[200];
 
void gnss(void* args __attribute__((unused)))
{
 
	for (;;)
	{
		ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
 
		printf("%s\n", gnss);
	}
}
 
 
void usart1_isr(void)
{
	BaseType_t woken = pdFALSE;
	char c = usart_recv(USART1);
 
	static int i = 0;
 
	gnss[i++] = c;
 
	if (c == '\n' || i >= 200)
	{
		i = 0;
		vTaskNotifyGiveFromISR(gnss_task_handler, &woken);
	}
}

Thank you very much!

PTsen
Associate III

OK, after re-read the software manual, I found that most of the new line is part of the format, so those are normal result.

However, I can't find $PPGLL $PSGLL on the software manual, and also $PSTMCPU has strange format which is different from the one I saw one the software manual.

Hi

Sorry to say but during run-time your are loosing chars in your code.

> $PPGLL $PSGLL

What are they?

Every NMEA message which begins with '$P' is a proprietary message.

The ST proprietary messages begin with '$PSTM'

Sorry but $PPGLL and $PSGLL are not ST message and you'l never see them from Teseo-LIV3F.

> $PSTMCPU has strange format which is different from the one I saw one the software manual.

As said you are losing chars.

Hope this helps

Regards

Francesco

PTsen
Associate III

Hi, in the beginning it looks like I'm losing chars, however, those chars appear because I did not clean the array after receiving the line, the problem was resolved if I clear the array right after line transmission done.

Anyway, thanks for your advice!