1

I am currently trying to learn about SPI and how it works on the Arduino. I want to wire a MAX7219 chip to it to drive an 8x8 LED matrix with. Normally, I would assume the wiring from Arduino to MAX7219 goes:

  • PIN 10 SS -> CS
  • PIN 11 MOSI -> DIN
  • PIN 13 SCK -> CLK

And indeed, this answer confirms my assumption. However, after going through some other resources and guides I found some confusing and conflicting information about how the pins on the two devices should be connected.

For instance, the documentation that came with my Arduino kit has this schematic.

enter image description here

This tutorial I found has the same wiring.

enter image description here

Most surprisingly, this tutorial doesn't even use the SPI pins at all.

enter image description here

What perplexes me the most is the sentence

The VCC and GND of the module go to the 5V and GND pins of the Arduino and the three other pins, DIN, CLK and CS go to any digital pin of the Arduino board.

Is this true? If yes, then what is the point of the SPI pins at all? Why are the pins wired in so many different configurations? I am really confused by this.

omniverseal
  • 11
  • 1
  • 2

3 Answers3

2

SPI is a communication protocol, you can take advantage of some hardware optimizations by using the pins where that hardware is available or you can do everything by hand using any pin you like, with the disadvantage of a bigger and slower firmware. In certain situations, like in the presence of a shield or a library already using those pins, the SPI pins might be unavailable and you have to resort to a software solution (aka bitbang, as you manipulate bits to generate the proper signals), otherwise use of the hardware SPI pins is strongly advised.

Roberto Lo Giacco
  • 1,271
  • 9
  • 19
0

For instance, the documentation that came with my Arduino kit has this schematic.

Pins 10 through to 13 are standard SPI pins on the Uno.

  • 10 (SS)
  • 11 (MOSI)
  • 12 (MISO)
  • 13 (SCK)

I have a tutorial here. I also have a Stack Exchange reference question and answer about SPI.


Most surprisingly, this tutorial doesn't even use the SPI pins at all.

It is certainly possible to "bit bang" SPI and in some cases this is desirable, for example if you have something like an SD card interface, and also want to use SPI for a display. On the page I linked, specifically at this post I describe how to bit-bang SPI.


What perplexes me the most is the sentence

The VCC and GND of the module go to the 5V and GND pins of the Arduino and the three other pins, DIN, CLK and CS go to any digital pin of the Arduino board.

For bit-banged SPI, yes you can use any pins.


Is this true? If yes, then what is the point of the SPI pins at all?

The hardware SPI is faster and easier, and you can do other things while SPI is sending/receiving but with bit-banging it is much more timing-dependent.

Nick Gammon
  • 38,901
  • 13
  • 69
  • 125
0

This video shows a project I did with a Duemilanove, 4 MAX7219s driving 4 8x8 LED matrices, and powered via 7.5V power supply. https://www.youtube.com/watch?v=hwYqgyMc5S4

With a 9V supply, the 5V regulator overheated and shut down after some number of minutes. With 7.5V, there was no problem.

The SPI and power pins, 5V, Gnd, SCK, MOSI, go to all devices, and each chip has its own SS pin (I didn't want to deal with sending out a bunch of NOP commands to feed data thru daisy-chained chips). Data to all 4 devices is refreshed as fast as 50mS, any faster and the display got too hard to read. I think I only used SPI at 4 MHz too, I have done other projects with SCK at 8 MHz, that can send out data really fast.

CrossRoads
  • 2,449
  • 7
  • 9