in my project I'm trying to implement a Cortex-M0-like UART auto baud rate detection feature on a Cortex-M3, which unfortunately does not have this handy feature on-board.
The idea is that the master uses two sync bits (1-0 sequence) at the beginning of each sent frame which allow the slave to synchronize itself to the (unknown) baud rate by measuring the time between the two falling edges (of the start bit and the high bit).
Basically I got this working with a timer input-capture which is connected to the UART RX pin, but only if my initial baud-rate is close to the actual baud-rate used by the master (+/- 15%).
However, problems arise if I use a slave default baud-rate which is much lower or higher than the actual baud-rate used. I can still measure the duration of the first two (sync) bits, adjust my baud-rate, but still I can't synchronize with the end of the frame/stop bit and thus I'm losing data.
For example, if I set my slave's UART to 9600 B/s per default and my master is actually sending with a much higher baud-rate, let's say 230,400 B/s:
- UART RX will detect the start bit and starts to sample with 9,600 B/s
- At the same time, I will measure the time between the falling edge of the start bit and of the high-bit to detect the actual baud-rate
- When the measurement is done correctly, I will adjust UART baud-rate to 230,400 B/s
- BUT, at that time, UART RX will still be waiting for the first sample to take, since it expects that 1st data bit much later (as it would occur with 9,600 B/s). So after adjusting my baud-rate, there will still be 7 or 8 samples taken although in reality, the first two data bits are already over.
I've tested this with STM32F0's auto baud rate feature and there I can select any default baud-rate value without losing any data. So I guess, since M0-UART "knows" that two sync-bits have already passed it will only sample 6 more data bits after baud-rate measurement to keep synchronized with the stop-bit. But how can I achieve this behaviour manually?
I hope you can get my point, though it's somewhat hard to explain for me, and I appreciate your ideas!