2019-10-03 05:12 AM
Hello,
Target : NUCLEO-L432KC board
IDE : STM32Cube IDE
OS : Windows
I want to get information from a GPS chip with an UART communication (TX/RX). It works when I use non-interrupt mode with HAL_UART_Receive function form HAL library.
However I want to optimize the code using the function HAL_UART_Receive_IT from HAL library. For now it is not working.
My UART configuration is here :
I only added this code to the generated main.c :
/* USER CODE BEGIN 0 */
uint8_t rx_buff[20];
/* USER CODE END 0 */
and
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT (&huart1, rx_buff, 20);
/* USER CODE END 2 */
and
/* USER CODE BEGIN 4 */
void HAL_UART_RxCplt_Callback(UART_HandleTypeDef * huart)
{
__NOP();
}
void HAL_UART_TxCplt_Callback(UART_HandleTypeDef * huart)
{
__NOP();
}
/* USER CODE END 4 */
Then I compiled the code, and I expected to see parts of the data form the GPS in my rx_buff variable. But there is no data in this variable according to the "live expression" debugging tool.
Do you have any idea why it doesn't work ?
Best regards,
Valentin Gros
2019-10-03 05:57 AM
__HAL_UART_ENABLE_IT(&huart1,UART_IT_RXNE);
HAL_UART_Receive_IT(&huart1, (uint8_t *)RX_Buffer, sizeof(RX_Buffer));
while debugging your code check uart data register you get any thing or not.
also check priority of uart interrupt.
retry after changing optimization setting(no optimize code) or use volatile.
clean whole project and rebuild project.
2019-10-03 07:39 AM
Hello Parth Kothiya,
First of all, thanks for you help.
I updated my program, so now I have this code (before the while(1){} loop) :
/* USER CODE BEGIN 2 */
__HAL_UART_ENABLE_IT(&huart1,UART_IT_RXNE);
HAL_UART_Receive_IT(&huart1, (uint8_t *)rx_buff, sizeof(rx_buff));
/* USER CODE END 2 */
2019-10-03 10:05 AM
When are you looking at the receive buffer? Are you looking immediately after calling HAL_UART_Receive_IT(), say by setting a breakpoint or single-stepping in the debugger? If so, there won't be anything there YET. You should add code to your HAL_UART_RxCplt_Callback() to set a global (and volatile) flag saying that you have received 20 bytes. Then in your main loop, wait for that flag to be set and THEN look at the receive buffer.
Another question - does the GPS send data automatically (like once per second or something like that)? Or do you need to send something to the GPS first?
2019-10-03 11:59 AM
> __HAL_UART_ENABLE_IT(&huart1,UART_IT_RXNE);
No, you don't have to enable the U(s)ART interrupt this way before calling HAL_UART_Receive_IT.
HAL_UART_Receive_IT will do this itself.
> Priority of UART interrupt is set to 0,0 (see screenshot)
This should instruct Cube to generate NVIC enable interrupt call for the UART . Have you checked that it is generated and called?
-- pa
2019-10-03 08:49 PM
code optimization setting found in your compiler settings
KEIL IDE:
http://www.keil.com/support/man/docs/armclang_intro/armclang_intro_fnb1472741490155.htm
TRUE STUDIO:
You can change that setting under build configuration (hammer with a blue icon) -> C/C++ Build -> Settings -> Tool settings -> C Compiler -> Optimization.
try this if it not work then backup your project and make new project then 1st try uart receive data in interrupt mode it successfully receive data then change code according to your application.
NOTE: check TX RX PINS and your gsm module send any data better to use any serial port software(cool term) to send data to mcu debug code and you can find what is going wrong.
2019-10-03 08:57 PM
receive your rx_buff in the receive it callback function. It will work
2019-10-07 05:53 AM
Hello Parth Kothiya,
Thanks for you help.
2019-10-07 05:58 AM
Hello Bob,
Thanks for you help.
2019-10-07 06:02 AM
Hello Pavel,
Thanks for your help.