Is there a library similar to Software Serial but for SPI communication? Defining new MOSI, MISO SCK pins?

Im using an Arduino Mega and need to connect 3 SPI devices onto it. Currently there are 2 sets of SPI pins on the Arduino only (50, 51, 52 and another set in the ICSP header) however I need a third. Is there any way I can turn any digital pins into another set? I heard about a library called SoftSPI however I cant find any resources that can help with it.

SPI is a bus, and multiple devices can use the same MOSI, MISO and SCLK pins.

Separate chip select (CS) pins are required, one for each device.

It is pretty easy to write software SPI and use any pins. Search for "arduino bit bang spi" for more information.

1 Like

Sorry I'll need you to elaborate a little further. Ok i got that we can use multiple spi devices on the same set of pins differentiated by the chip select pin. Is there something done differently in code when I connect multiple devices other than specifying the right CS pin Im using for each device which is what i do when using just one.

Side note, is there no possibility for my original question? Why are libraries like SoftSPI a thing if you can connect multiple devices on the same set?

No. Please read https://docs.arduino.cc/learn/communication/spi

Why are libraries like SoftSPI a thing

To use different pins, to support MCUs that lack SPI hardware, deviate from "standard" SPI communication protocols, etc.

you already use the same SPI pins for two devices. the SPI header is connected to pins 50, 51, 52

you mean the ICSP header?

Eidt: woah after searching, turns out that the ICSP pins are connected to pins 50-52, that's cool. Alright I'll give it a shot

For 'SoftSPI' you can use the built-in functions shiftOut(dataPin, clockPin, bitOrder, value) and shiftIn(dataPin, clockPin, bitOrder) if you don't need simultaneous send and receive.

Use your chosen SCK pin for the clock pin. Use your chosen MISO pin for the shiftIn() data pin. Use your chosen MOSI pin for the shiftOut() data pin. Set your chosen SS/CS pin LOW before the shifts and HIGH after the shifts.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.