2025-07-18 7:05 AM
Dear ST's experts,
I want to send/receive data through UART between STM32 and PC. The data must be sent to PC every 500ms and then STM32 receive data from PC. I have configured UART2 with DMA in circular mode. I am using the function HAL_UART_TxCpltCallback to pause the UART (HAL_UART_DMAPause(&huart2);) to send data every 500ms. My problem is that when I use the above function, receiving data does not work properly.
How I can solve the problem?
Should I use DMA in normal mode for TX?
2025-07-18 7:51 AM
Hello @Davood_Kesha
Please refer to the example below:
2025-07-18 8:33 AM
USART Rx/Tx DMA can occur concurrently.
Don't pause or block in interrupt handlers, or callbacks generated from interrupts, ie within interrupt context.
Blocking in interrupt context is very bad form.
If you want to initiate transfers on a periodic basis, start them in TIM callbacks, or count off time related to SysTick, ie initiate every 500 calls to SysTick_Handler()
Or pace within your main() loop
uint32_t start = HAL_GetTick();
while(1)
{
if ((HAL_GetTick() - start) >= 500)
{
// Do 500ms Task
start += 500;
}
}