2020-06-26 12:35 AM
Hi, i did some research and when i do send and receive seperately then everything went smoothly, im using HAL_UART_Receive with RxCpltCallback:
if(huart->Instance == USART2 && newDataFromPC == 0)
{
/*Receive data*/
HAL_UART_Receive_IT(&huart2, (uint8_t *)rx_data, 1);
/**/
if(rx_data[0] == startMarker)
{
bytesRecvd =0;
readInProgress = 1;
}
if(readInProgress == 1)
{
inputBuffer[bytesRecvd] = rx_data[0];
bytesRecvd++;
if(bytesRecvd == buffSize)
{
bytesRecvd = buffSize - 1;
}
}
if(rx_data[0] == endMarker)
{
readInProgress = 0;
newDataFromPC = 1;
inputBuffer[bytesRecvd] = 0;
}
}
this is used for returning data only if it is cover in "< >", i put a flag "newdata" in main to begin the receive
if(newDataFromPC == 1)
{
newDataFromPC = 0;
}
then i put the receive_it before while function. However, when i start transmitting using HAL_UART_Transmit the receive function stop and wont receive a thing.I did google and apparently the HAL_UART_Transmit is a blocking command. So is there anyway to fix this or i have to set up a HAL_UART_Transmit_IT?
Thanks.
2020-06-27 02:46 PM
Yes, HAL_UART_Transmit is blocking. Try HAL_UART_Transmit_IT, or the DMA variant.
Look at these examples: https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx
-- pa