Skip to main content
Visitor II
April 23, 2024
Question

STM8S103 UART1 latency issue (delay between event and interrupt execution)

  • April 23, 2024
  • 1 reply
  • 1865 views

Hi, I bought me some mini mp3/wav players frome china. Serial communication is executed at a fixed baudrate of 9600baud. Messages to and from the unit do both have a size of 10 bytes. Transmitting serial messages works perfect. Receiving messages do not work. I use the UART1 RX interrupt vector 18 which is executed if the receive data byte buffer (UART_DR) is not-empty. I put a PC3 pin-toggle in the receive interrupt handler after the data (UART_DR) register is read. On my logic analyser I see that the pin toggle takes more time per received byte. I measure the time between the end of the first received STOP bit and the PC3 toggle being 354us which to my opinion is awfully long... With each received byte the time between de end of the STOP bit and a PC3 toggle increases. At byte 6 it is 870us and then PC3 starts oscillating (9us) as if the data (UART_DR) register is not read anymore and contains an unread value. I disabled all other interrupts. What could be going on?

    This topic has been closed for replies.

    1 reply

    Graduate II
    April 24, 2024

    Show code, and plots.

    Might oscillate if other errors are flagging and not cleared. Perhaps OR, NF, FE, PE ?

    sthvwAuthor
    Visitor II
    April 24, 2024

    Hi, you are right at the OR/NF/FE/PE oscillation case as with byte 7 an OR is reported but the SR is not read to clear the OR. But still it does not explain why it takes that long before the interrupt handler is called. In the interrupt handler I disable all interrupts and re-enable the RIEN. I finally found the cause. I need 2 UARTs so I implemented a soft-uart which uses for-loop delays during reception and this soft-uart was running during uart1 reception. All works fine now and latency (byte received versus interrupt handler called) is about 9us! Thanks for your comment.

    Graduate II
    April 24, 2024

    Not sure. You have any other higher priority interrupts firing? Something with a multi KHz rate, like a TIM?

    What does the assembler code look like for the handler, buffering, processing, etc.

    Code optimized? MCU running at expected frequency?