Is there a SPI library so I can choose my own pins?

I have always been familiar with using SPI libraries where I can define the SPI pins. I was not aware of this “hardware SPI”. What is the difference?

Anyways, I built some PCB’s with the assumption of the library allowing me to choose which pins are what, and it doesn’t seem to be the case? Is there a software SPI library out there that I can use? I have not had much luck so far.

@Mahonroy, hardware SPI refers to hardware assisted SPI which removes the work from the application. Software SPI is simple to implement. I’ll post some code (when I get home) for a software SPI function which replaces the SPI.transfer() hardware SPI function. :smile:

1 Like

There is a software SPI included in “my” Adafruit_HX8357 library published on Web IDE.
You can have a look there.

Peekay, that would be awesome thanks a lot!

ScruffR, are you referring to this? :

@ScruffR, I wrote a single function which behaves like SPI.transfer(). That is, it writes AND reads a byte from the SPI device and returns the result.

@Mahonroy, @ScruffR, voila!

inline __attribute__((always_inline)) uint8_t softSPItransfer(uint8_t data) {
	uint8_t b=0;

	for (uint8_t bit = 0; bit < 8; bit++)  {	// walks down mask from bit 7 to bit 0
		(data & (1 << (7-bit))) ? pinSetFast(mosiPin_) : pinResetFast(mosiPin_);	// write the outgoing bit
		b <<= 1;
		if (pinReadFast(misoPin_)) b |= 1;	// Read the incoming bit
	return b;