Search code examples
testingassemblyembeddedmicrocontrolleruart

How to test Bit-Banged communication's assembly routines


For one MCU I have written some assembly routines performing RX and TX of a proprietary protocol (UART-based) in a bit-bang fashion. How can I test them?

TX might be tested by sending data, and at the same time, with the help of a logic analyzer, checking that all the sampled timings are correct (manually or with some scripts).

RX on the other hand is more difficult. On one hand I can check if I'm receiving what someone else is sending, but on the other hand how do I know that the RX sampling is happening correctly (timing-wise)?
For example, my RX routine may return the correct data by sampling at the edge of the "bit window" instead of the middle.
I thought about toggling a "debug pin" to indicate when the sampling is actually happening, but this introduces delays in the sampling procedure, hence I wouldn't be testing my original routine.

Some things worth clarifying after reading comments:

  • I know that hardware UART is better (it depends, though), but I can't use it. This is not a matter of "have you tried this ...?";
  • I know how to do the bit banging (I have already written the assembly routines);
  • I can't connect TX to RX because I'm only using 1 wire (the communication is half-duplex);
  • I'm asking how to test the RX sampling timings, not how to implement UART.

Solution

  • I thought about toggling a "debug pin" to indicate when the sampling is actually happening, but this introduces delays in the sampling procedure, hence I wouldn't be testing my original routine.

    Test with the instrumentation code, and then leave the instrumentation - or near-equivalent code that doesn't actually twiddle hardware - in place.