My friend ran into an issue with an RS485 based serial interface where it seemed to drop bytes when receiving, but only when he was manually typing out data to it. Bulk transfers using a program were fine. What I found and believe to be the issue was actually in the transmit code from the STM32.
Effectively, the transmit complete interrupt was triggering before the 1 byte made it out. Writing to DR clears the TC interrupt, but USARTv1 didn't reread SR or clear out the TC flag. Since the queue was now empty (the one byte was sent), the TC event was fired.
Logic analyzer capture of the problem:
And after the proposed fix:
The zip contains the patch along with a demo of how I tested this on the F407-Disco board demo. The patch just yanks the TX looping code from USARTv2. There is also the small benefit of skipping an interrupt when starting to send more than 1 byte.
USARTv2 isn't affected because of the loop while transmitting.
Early TC event with 1 byte using serial STM32 USARTv1 driver
Early TC event with 1 byte using serial STM32 USARTv1 driver
- Attachments
-
- usartv1_early_tc_fix.zip
- (6.29 KiB) Downloaded 143 times
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Who is online
Users browsing this forum: No registered users and 20 guests