UART not receiving as expected
Hello, I am completely new to STM32. I am using a RAK3172 based on the stm32wle5ccu6 chip. I have already tested some basic codes on it and works fine. I am trying to write a code to perform modbus communication with a certain device. So i started with implementing UART in the chip. Transmitting the data works exactly as intended. However I am not able to receive data more than once. I have started testing using this documentation: Getting Started with UART .
Code:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_UART_Transmit(&huart2, tx_buff, 10, 1000);
if(HAL_UART_Receive(&huart2, rx_buff, 10, 10000)==HAL_OK) //if transfer is successful
{
__NOP(); //You need to toggle a breakpoint on this line!
} else {
__NOP();
}
}
I have connected the USART tx,rx line to USB-TTL converter and opened the connection in Arduino Serial monitor. I am able to transmit from the stm properly, however, when I send data from the Arduino serial monitor to the stm, the very first time it receives data properly, but after that no matter how many times i send data from the serial monitor it never reaches the breakpoint.
I am also facing similar issue when using interrupt mode for UART.
this code doesn't work:
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, rx_buff, 10);
/* USER CODE END 2 */
.
.
.
.
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart1, rx_buff, 10); //You need to toggle a breakpoint on this line!
}
/* USER CODE END 4 */
but this code kinda works:
while (1)
{
HAL_UART_Receive_IT(&huart1, rx_buff, 10);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
..
.
.
.
.
.
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart1, rx_buff, 10); //You need to toggle a breakpoint on this line!
}
/* USER CODE END 4 */
The first interrupt code is facing the exact same problem as the blocking code. It receives exactly once and never after that. But I saw i another post here that we shouldnt use the
HAL_UART_Receive_IT(&huart1, rx_buff, 10);
withing a while loop. Any help is appreciated Thank you.
