Hi Tex,
I had simulated and understood the provide code function. I also made minor modification to the code in order to simulate properly. Check the attached module, testbench and waveform below.
I had assigned clkMCU with the example period of 10ns. Then given RX in '0' (start bit) + "10000110"(reverse of "01100001" ascii: a) and tx_en goes high start transmitting. Based on the code and simulation, the first uart RX index 0 will take MidSampleCnt about 0 to 4 (50ns **x5 clkMCU**) while the rest uart RX index 1-9 each will take MidSampleCnt about 0 to 7 (80ns **x8 clkMCU). Total duration for 1 cycle from index 0 to 9 will be 770ns.
After four cycles, given RX in '0' (start bit) + "01011110" (reverse of "01111010" ascii: z) and tx_en goes low stop transmitting.
Seems like the code provided worked as mentioned. Have you given '0' (start bit) to RX in? Have you ensure that correct timing of each uart RX index from 0 to 9 given to the RX in?
Thanks,
Best Regards,
Sheng