Thursday, January 12, 2012

Extending Arduino example CIRC-05 to use hardware SPI control

For kicks, I've extended the basic Arduino shift register LED control example CIRC-05 from www.oomlout.com to use the Arduino's hardware SPI routines instead of software signalling.

As someone who has done very little with low-level electronics and who didn't know what SPI even was until today, this was embarrassingly easy. Kudos to the excellent Arduino libraries and the great documentation for making this simple.

I'm posting the re-written example for CIRC-05 here. It has the original software-based control as well as support for SPI, so you can see how similar the methods are.

(BTW, if you were wondering what a "latch" is in the IC, see this example.)

The only change required to the example circuit is that you must use pins 11 and 13 instead of pins 2 and 3, as the Arduino hardware SPI support has MOSI locked to pin 11 and CLK locked to pin 13. It also uses pin 12 for MISO, but we're not using that in this example.

Use output 11 where the wiring diagram says use output 2, and use output 13 instead of 3. No other changes are required.

The actual circuit on the breadboard is not altered in any way.

Here's the sketch code:

https://github.com/ringerc/scrapcode/blob/master/arduino_avr/Arduino_Tutorial_CIRC05_hardware_spi.c

1 comment:

  1. Thanks for writing this. It really helps with my project.

    ReplyDelete

Captchas suck. Bots suck more. Sorry.