SPI is a very powerfully and fast serial port used between Master and one or more slaves, but I want to evolve the bus into a proper device to device bus. This is actually far more straight forward than I expected as both Raspberry PI and STM32F405 support Half-Duplex modes. RPI only support Half-Duplex Master, so all I need to do is to connect MISO and MOSI and set correct modes – Raspberry PI into Half Duplex Master and all STM32F405’s into Half-Duplex Slaves. Switching between sender is done in SW using a Dynamic time-slot scheme.
Doing this without Raspberry PI can be done in the same way by one of the devices taking over as Half-Duplex Master. The key here is that we have connected full SPI, MOSI to MOSI and MISO to MISO, but in Half Duplex one of them will be idle so we just connect them together. This should work!
F405 is capable of 42Mbps, but the closest RPI speed is 32Mbps – and if we assume 1ms switching time and max 4ms sending we should be around 25Mbps (80%) effective bandwidth usage.
This is a step down from 84Mbps bandwidth on a full duplex (F405), but it is still pretty good speed and very functional since we now communicate device to device directly.
The second scheme that I used before is using full duplex and using a dynamic time-slot scheme between device that send on MISO. This works very well, but I can only send to/from Master – never directly Device to Device in this scheme. This mode have the advantage of full duplex, meaning that with the same 32Mbps and 80% rule we have a 54Mbps total bandwidth. But, is this actually faster? The answer depends on your message flow – if all your traffic is to/from the Master then yes, if not we just waste bandwidth by turning messages around at master.
A 3rd Scheme of rotating Master is possible, but I fail to see what I would gain since changing Master means all communication goes through that device.
All my new Hat’s have full SPI connected and to enable Half-Duplex mode we simply add a jumper between MOSI and MISO on the header – this enables me to select communication scheme based on what I believe is most efficient.
Half-Duplex with STM32F405’s only will be at 42Mbps and as with ca 34Mbps effective bandwidth. We get lower speed with Raspberry PI because we need to fit available clock schemes with this as Half-Duplex Master.
Assuming we have 20 devices in a stack the max message wait time will be 5ms x 20 under full load which is 100ms. I am ok With that because this is a very worst case – I actually believe switch time is much much lower and we can improve parameters, but we can measure that later.
So how much bandwidth do we need for stereo sound? Assume that sound is 32 bit samples at 32Khz – this is 1Mbps bandwidth usage. This is a brute force calculation, but it still indicate that we have bandwidth for 25-50 channels of high quality sound. If I assume telecom quality which is 64Kbps we basically have capacity for ca 195 2-way phone calls simultaneously.
Doing video or sound over some distance is more of an issue, but don’t forget that we have Wired and Wireless Ethernet options as well.
To sum this up – I intend to abandon my attempt on rotating Master and focus on 2 schemes – Master with dynamic TDM slots on Slaves or Half-duplex with dynamic TDM slots that scale to load. I will be back with a more detailed protocol description later.