Associate II
March 4, 2026
Question
UART TX inconsistent/delayed timing NUCLEO-F413ZH
- March 4, 2026
- 10 replies
- 1434 views
Hi,
I'm working on a piece of code using UART, where I need to send a byte of information right after the negative edge of that line is detected. Basically, my dev kit is connected to a 1-wire device through a simple 2 N-FET transistor for the TX side and directly to RX. Additionally, I have another GPIO connected to the 1-wire interface to detect, via interrupt, when the 1-wire device pulls the line down (start bit). The 1-wire device releases the bus right after the start bit.
The problem that I'm facing is that the timing at which the byte is sent by the MCU is very inconsistent, with a delay that is not tolerable by the application. I've tried several things with no improvements:
- Send UART command using non-blocking mechanisms (interrupt and DMA)
- Making the GPIO interrupt the one with the highest priority
- Disable interrupts before sending UART command and enabling afterwards i.e.: __disable_irq() and __enable_irq()
- Send commands in the GPIO edge callback
- Send commands in main after checking a flag set in the edge callback
For the sake of simplicity, I tried all the above with a different setup. Instead of using a UART to 1-wire interface, I made a completely separate project, with the dev kit by itself, not connected to anything, where I'd send the UART command after detecting the edge of the user button in the dev kit. The results were the same.
Just for reference, find below the simple piece of code of this last scenario I mentioned:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(ready)
{
ready = 0;
__disable_irq();
HAL_GPIO_TogglePin(GPIOB, LD1_Pin);
HAL_UART_Transmit_IT(&huart3, smsg, sizeof(smsg));
__enable_irq();
}
}
/* USER CODE END 3 */
}where ready is set in the user button GPIO callback.
The piece of code above uses UART3, but the result is the same using UART5 for example.
Find attached the clock setup and logic analyzer captures that show the inconsistency of the timing.
I'd appreciate your help on this matter. Thanks!
