If you want to make a software-only 8x serial port on a rPi, then you need more I/O pins.
I would suggest to use a NXP PCA9701 16-bits SPI port expander that can read and write all 16 bits in a single SPI transfer.
So all rPi hardware you need is 4 pins, a SPI port and one timer interrupt for sampling at 3*9600 or 4*9600 Hz that does a single SPI transfer.
The software part will be more tricky, but doable.
Another way to go would be to use I2S with DMA to provide a realtime I/O stream; seehttps://github.com/lhartmann/orangepi-i2s-steppershttps://gist.github.com/cnlohr/2b9f8a26 ... 4cff9d04fe
The I2S DMA option would greatly relax the interrupt timing requirement,
for you could process all collected samples in batches of any suitable length.
I don't think anyone has implemented this yet anywhere,
so it would be a great achievement if you could add 8 or more software serial ports this way!
OK, first off...I am only planning on implementing RX/TX on each port, no flow control. That way, I will only need 8 inputs, and 8 outputs (total of 16 I/Os). According to a pin map I found (https://www.raspberrypi.org/documentation/usage/gpio/
), the 40-pin header has at least 26 I/Os; at least for me, there's no lack. Me personally, I could implement 12 serial ports with GPIO (=24 I/Os), as the only other device I need to handle is an I2C touchscreen LCD (=2 I/Os).
One note: the PCA9701 gives 16 INPUTS
, not GPIO. It could be used to sample 16 RX lines, but TX lines would have to be handled separately.
Doing bit-banged RS-232 over SPI brings in a slightly more difficult challenge: now all of the data has to get pipelined over a serial bus. If I'm sampling at 4x 9600Hz = 76.8KHz, now ASSUMING we can get all 8 inputs and 8 outputs done over one 16-bit transfer, we have a mathematical absolute minimum SPI clock rate of 1.3MHz (likely much higher). That shouldn't be a problem with a hardware SPI module, but it's something to keep in mind.
I2S definitely would have some possibility; however, at least in my case, that would require external chips--in which case I might as well just buy some SPI-to-UART bridges, or interface a Propeller. Trying to keep it simple and cost effective.
The PigPio project definitely has some interesting links there, including sampling GPIO "between 100,000 and 1,000,000 times per second." Now THAT might be onto something! If I could use DMA to sample the I/Os for UART input, seeing as a PI has a large amount of RAM (at least comparatively speaking to my 2K MCUs!), that could greatly reduce the CPU load for actual sampling, and feasibly permit higher baud rates--though the resulting data would have to be parsed. Output TX rates could be reduced to the baud rate, as we don't need oversampling for TX.
Once I get enough other things off my plate, I'll start poking around with Ultibo and the Pi Zero. Shouldn't be that hard to get the baby steps put together.
@stevenpostma Thanks for your suggestions. Seems that something like this would be of value/interest to you.