Hi Aniket,
The main limitation for the number of SPI slave devices allowed in an independent slave configuration is the number of CS lines available to you and the ability for data and clock lines to meet threshold high and low logic levels.
In the Arduino code provided in the tutorial you followed, I’m not sure how the interrupt was set up for operating the Pro Mini in SPI slave mode, since I haven’t used Interrupts on the Arduino before.
Two things I would recommend checking in the Arduino code:
- Ensure that a low-going CS signal is the only thing that makes the Arduino enter the SPI interrupt service routine. I don’t explicitly see in the tutorial code how pin 10 of the Pro Mini triggers the interrupt.
- Ensure that the Pro Mini slaves are not going to cause bus contention on the MISO line. Unselected slaves should not be driving the MISO line high or low. Not sure how you can make sure of this. maybe temporarily set the MISO pin of unselected slaves as inputs, rather than outputs?
For your BBBlack, I don’t easily see in the tutorial code how the CS line is being controlled.
You likely need to manually control the slave select lines using GPIO. For example: select one slave by driving its CS line low, send/receive serial data, then deselect the slave by driving its CS line high.
Only one slave CS line may be driven low at a time when reading data from individual slaves.
Since I used the BBBlue (which is basically a BBBlack with the Robotics Cape integrated into it), I modified the Robotics Cape API functions, rather than directly using ioctl and spidev. I’ve attached my modified SPI functions here.
I’ve tested the functions rc_spi_init_mod, rc_manual_select_mod, and rc_manual_deselect_mod with a 3-to-8 line decoder and a Bus Pirate for sniffing the SPI bus.
You probably won’t need a line decoder for only 4 SPI slaves, so you can just directly drive the CS lines using GPIO.
It’ll be another couple of weeks before I receive my prototype slave devices, so I haven’t had the chance to fully test my functions just yet.
I would dig around in the Robotics Cape library code. The SPI functions in the library are more readable and better documented than the tutorial code, to be honest.
https://github.com/StrawsonDesign/Robotics_Cape_Installer/blob/master/libraries/serial_ports/rc_spi.c
The simplest solution I can think of would be to try installing the Robotics Cape API on your BBBlack and see if you can use their API functions without the Robotics Cape hardware.
Hopefully this helps.
Regards,
Robert
rc_spi_mod.h (246 Bytes)
rc_spi_mod.c (16.4 KB)