2014-10-09 11:24 PM
I'm upgrading to the new HAL libraries and got struck with UART interrupt when trying to implement ECHO,
I generated code using STMcubeMX for UART3 added in the msp init of the uartHAL_NVIC_SetPriority(USART3_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USART3_IRQn);
Added in the stm32xx_it.c
void USART3_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart3);
}
Created callbacks in the main.c
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
if (huart->Instance == USART3);
{
buffsize = huart->RxXferSize;
HAL_UART_Receive_IT(huart, Datarx, buffsize);
for (int i = 0; i<buffsize;i++)
{
Datatx[i] = Datarx[i];
}
HAL_UART_Transmit_IT(huart, Datatx, buffsize);
}
}
And adding the below in the USART init
__HAL_UART_ENABLE_IT(&huart3,UART_IT_RXNE);
after running there is nothing on the UART. can anyone guide me in this please?
2014-10-10 04:00 AM
Hi Rakesh,
The HAL_UART_Receive_IT has to be called in your main function not in the reception complete callback.Please check some examples in the STM32Cube package. If you are using the STM32F4 discovery board, you should look for USART example under STM32Cube_FW_F4_V1.3.0\Projects\STM32F4-Discovery\Examples\UART\UART_TwoBoards_ComIT.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2014-10-10 05:38 AM
Mayla ,
Thanks for the quick reply. I saw that example and it works. But you need to wait till the USART reception is complete . In the example there is while (UartReady != SET){} which waits for all the usart bytes are received. if in case if the no of bytes needed are not known and it has to happen as an interrupt this is not clear. Usually when the interrupt comes the below operation should happen Interrupt -> check the IT flag -> read the byte -> write the byte -> clear the IT flag. I believe adding it in the main(), the purpose gets defeated as the main has to wait till the HAL_UART_Receive_IT. I might be wrong. Could you please clarify if there is another method with which this works ? Thanks for the prompt reply.2014-10-11 11:17 AM
Mayla,
Thanks, As you said receive has to be called periodically in the main and not in callback. transmit has to be called in the receive callback . final code looks like this in main.while (1)
{
HAL_UART_Receive_IT(&huart3, Data, 1);
}
In the receive callback add the tx_IT like this.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
if (huart->Instance == USART3)
{
HAL_UART_Transmit_IT(huart, Data, 1);
}
}
And it works !!
2016-12-12 07:27 AM
Hello Rakesh,
I am also trying to do Echo program on STM32F207 Nucleo 144 board. Unfortunately i can just send data while receiving part is not operating. Any Suggestion or idea?? I have configured UART2 over PD5,PD6 Pins. I have attached my program file below. No error while Debugging but i am not receiving data in Receiver buffer.
________________ Attachments : UART2_Nucleo144.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hz04&d=%2Fa%2F0X0000000bFl%2F85OjDIpEYiUNdG5Yj8CVFt2xzMsQ55oWKBzRoj4EU0c&asPdf=false