0

GPIO pins 19,21,23,24,26,35,38,40 are dedicated for SPI protocol. Is it possible to use other GPIO pins for SPI? If yes, how do we do it?

  • Hello @tan45. Welcome and nice to meet you. Ah, let me see see. I am also troubled by not having enough Rpi GPIO pins to go around, because I am using six SPI buses, on top of 5 I2C buses. You might like to listen to my chat these days: chat.stackexchange.com/rooms/103645/…. Let me know if you wish to know more. Cheers. PS - One get around is to use GPIO extender, such as MCP23S17, then you can have many more GPIO pins than you want. Again let me know if you wish for more details.Your sincerely, Cheers. – tlfong01 Feb 20 at 6:04
  • 1
    @tlfong01 Thanks for replying. Could you please tell if we can use some other GPIO pin for MOSI instead of GPIO pin 19? – tan45 Feb 20 at 6:46
  • Hi there @tab45, Long time no see. How nice to meet you again. Let me see see again. Actually your question embarrasses me a bit, because since my Arduino Decimilla (my first love) days, I ALMOST NEVER USE BIULT IN CS pins. I DIY my only CS pins. I just use MCP23x17 GPIO pins as SPI CS pins. You might like to read the following post and see if you understand what I was talking about: (1) "Using MCP23017 GPIO Pins as Rpi SPI CS pins": raspberrypi.org/forums/…. Best Regards, Your Sincerely, Cheers. – tlfong01 Feb 20 at 7:17
  • Errata and apology. Ah I gave you the wrong weblink, which was about how to demux SPI/I2C/UART buses, the idea is something like this. I use TBX0104 or something similar to shift up SPI signals to 5V. This TBX0104, or ses, the idea is something like this. I use TBX0104 or something similar to shift up SPI signals to 5V. This TBX0104, or HCT125 125 etc, usually have a "ENABLE" pin to "select" the device. So I use Rpi GPIO, or MCP23x17 GPIO to select which TBX0104 connected SPI signal shifter to use. So it is sort of SPI multiplier which is different from DIYing you own CS pins. – tlfong01 Feb 20 at 7:27
  • I am now thinking of using SPI MCP23S17 GPIO pins to do SPI select. (I don't use I2C MCP23017 this time, because I am already using SPI anyway, so using SPI as the dominant bus saves SPI and I2C clashing. I am just thinking aloud in a hurry. Sorry for the typo errors. – tlfong01 Feb 20 at 7:31
0

The Pi has hardware support for the Pi acting as a SPI master. It has no support for the Pi working as a SPI slave.

That being the case it is simple to bit bang the SPI master protocol in software (as the software controls the SPI clock as it is the master). Using bit bang allows you to use any spare GPIO for any of the SPI signals.

Just search for SPI master bit bang software and implement your preferred solution.

| improve this answer | |
  • I will try bit banging. But like you said that the SPI has no support for working as a SPI slave, then why do we have the MISO pins for? I am using the same RPi as both master and slave by sorting MISO and MOSI pins. – tan45 Feb 20 at 9:58
  • The Pi can only act as a SPI master. The master initiates all communications with the slave selected by slave select and controlled by the SPI clock. The master sends data to the slave via MOSI and receives data from the slave via MISO. Usually the computer is the SPI master and all connected devices are slaves. – joan Feb 20 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.