[READ-ONLY] Mirror of https://github.com/SantaClaas/embedded-fan-control.

Hold the RS-485 driver until the frame has actually left master

The fans answered nothing at all, to reads and to writes alike: every exchange ended in a header timeout with zero bytes received. The line was being handed back mid-frame. `blocking_flush` on a `BufferedUart` only waits for the software buffer to drain, and that empties as soon as the interrupt handler has copied the frame into the 32 byte hardware FIFO, where all 8 bytes of a Modbus frame fit at once. So it reported the request written while none of it had reached the wire, and the fixed 800 µs wait that followed covered about one and a half of the 573 µs characters. The driver went low after the first byte or two and the rest was shifted out with the transceiver in receive mode. The fan saw a stub, dropped it on the checksum, and said nothing. No constant can be right there. The wait has to cover the whole frame rather than the single leftover character a plain `Uart` would have, and the frame length is not fixed. Poll BUSY instead, which deasserts only once the FIFO has drained and the last character has left the shift register. This also explains the 5 ms the constant started out as: that was long enough for the frame to get out, and never reached into the fan's answer the way the comment assumed, because the fan does not start replying until 3,5 characters after the frame ends. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>


+13 -24
1 changed file