15 hours ago, TomXP411 said:
That makes for a chatty protocol, though. It also increases the number of times I have to switch the port between reading and writing. If I have a “data waiting” line, I don’t need to issue a command to check the buffer. I just read the state of one pin. If I want to read a byte from the buffer, I just set the Read pin high and raise the clock. One of the original design goals was to prevent unneeded chatter, and removing those lines adds a lot of chatter I’d rather avoid.
It IS a protocol the is more efficient for packet transfers then for byte at a time transfers, but I'm not so sure how high a priority is for byte at a time transfers. If one packet is 128 bytes, your original protocol would have required changing the data ports R/W and flipping polarity of the CLK/ACK port twice for every byte of a write. Flipping polarity of CLK/ACK requires a read of the Port B data direction register, and AND #n and an ORA #m and a write to the Port B data direction register, so it's more expensive than flipping the read/write of PortA.
This one only requires changing the data register status twice for 128 bytes of a packet read, and Port B is stable.
One way to reduce pins is to incorporate the ADR function into the CMD function, where CMD #0 is a device select command, with the following byte the selected device, so all devices listen to a CMD but the non-selected devices only listen for all bits low.
Then you can have:
D0-D7 (I/O) - data or command being transmitted
HANDOUT (O) - handshake CLK when system writing, ACK when reading
HANDIN (I) - handshake ACK when system writing, CLK when reading
CMD (O) - a command is being send to the device(s), #0,N is the command to switch to device N
READ (O) - system is ready to read data from current device
DDATA (I) - device has data available for reading
... as 13 pins.
One advantage of that is that if DDATA is on a pin that can trigger an interrupt, then the device can raise the DDATA when it has anything buffered and once the interrupt is processed and the buffer starts to be emptied, it just holds DDATA high until the buffer is empty.