Software SPI library for Arduino Mega 2560

Hi, does anybody have a Software SPI library to use with the digital I/O of an Arduino Mega2560? I have an arduino Mega2560 and the Sparkfun Host Usb shield, and I don´t want to rewire the shield for conecting its SPI pins to the Harware SPI pins of the Arduino. Regards.

Software SPI, isn't tat just shiftout() and shiftin() ?

Yes, I have a similar issue. I want to port an existing duino shield to a mega but it uses SPI. I see that the sdfat library is capable of this but was wondering if anyone has distilled the software spi part out to be its own library?

thanks, don

It’s fairly easy to bit bash it.

See attached example of a library that bit bashes the SPI.

The biggest problem is that its speed limited by the arduino clock speed. If you have a hardware SPI you can get it to go much faster.

You will need to read the datasheet for whatever you are interfacing to so that you know how to implement the SPI mode needed.

Hope it helps.

MCP3201.zip (1.4 KB)

As CR said bit bashed SPI is just shiftIn/Out, is there a special reason to do another version? Like you need 11 bits or something.


Rob

As CR said bit bashed SPI is just shiftIn/Out, is there a special reason to do another version? Like you need 11 bits or something.

The lib I attached is for 12 bit data and 2 dummy bits, so yea, this is why.

12 bits, I was close :)

Just grab the code form the shiftout/in lib and modify it.


Rob