When I added the SSC-32 forwarding code to the Arduino Mega version of the phoenix code it was a piece of cake as I had the SSC and the DBG and XBEE all on UARTS, where the hardware would detect characters coming in and buffer them for me. At times it would be great to do this with the Bap28 or Arc32. The problem is that we don’t have that many uarts. Side but interesting note is that with one set of libraries for the AVR processors (webbotlib), he added software UARTS for specific pins. These are pins that are connected up to to timers. That made me think about doing something similar to that on the Baps. I have not done any coding yet, but I don’t think it would be very difficult.
Pins 9-12 of the Bap28 are connected to the H8 pins FTIOA-FTIOD when can be directly controlled (either input or output) by TimerW.
Example suppose we wish to capture input from the SSC-32 on pin 11. We would setup the TImerW such that we have input capture on this pin and assuming that the signal is high until we receive a stop bit we setup to capture the input when the signal goes low and we set it such that we receive an interrupt.
When this interrupt arrives the register GRB will have the exact time when then start bit started. We then have a couple of choices how to handle it. Probably the easier one to implement would then to set an interrupt at the time the start bit started plus 1.5 bit periods (minus maybe some fudge factor for interrupt latency). When this interrupt happens we grab the IO state and interrupt again in one clock cycle… repeat until we get to the stop bit and we add the byte we received to an input queue…
A possible different handling of the first interrupt would be to then setup the interrupt to again wait for another transition and then calculate how many bit periods were between the transitions. But there is an issue of potentially knowing when a stop bit comes as the previous bits may already be in that state. Options to handle this include: use timer overflow interrupt to catch it and/or know when the next start bit comes, or if the user asks for characters have it detect that a partial character is pending and enough time has elapsed… I think this approach would have a little less overhead, but is more likely to be buggy…
Note: HSERVO uses wtimer/ztimer so you could only do this in programs that did not use hservo…
The question is, is this worth doing? If it is it may be awhile before I try it as I have a few other side projects going on.
Kurt