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.

4
  • that looks like a bad instruction ..... you should not connect the 5V to the Vcc ...... i would not trust any tutorial that says otherwise ..... do not use the arduino as a power supply
    – jsotola
    Commented Feb 26, 2019 at 4:57
  • with "software" SPI any pins can be used. with hardware SPI CS should not be wired to MISO
    – Juraj
    Commented Feb 26, 2019 at 6:08
  • Max7219 can be powered from 5V of Arduino. I did a project where 4 Max7219 were powered. With 9V into the barrel jack the 5V regulator would overheat after a while. With 7.5V things ran smoother. It depends on how many LEDs are being lit at one time, and what current was being used. 10K for the Max7219 current limit resistor kept things reasonable.
    – CrossRoads
    Commented Feb 26, 2019 at 12:18
  • Here are 4 of Max7219 powered by USB even youtube.com/watch?v=hwYqgyMc5S4&pbjreload=10 I took this to work and powered it from barrel jack instead, that's when I saw the overheating/shutdown at 9V and had to drop to 7.5V instead.
    – CrossRoads
    Commented Feb 26, 2019 at 12:34

3 Answers 3

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.

6
  • I2C should not interfere with SPI on an Uno, they are different pins. I use SPI for Max7219 projects, much faster updates than software bit-banging of the signals. Defaults for SPI: 4 MHz clock, MSBFIRST, clock Mode 0, work fine, and using SPI.transfer to send data to a register is simple: digitalWrite (ssPin, LOW); SPI.transfer(registerAddress); SPI.transfer (dataToLoad); digitalWrite (ssPin, HIGH); with SCK, MOSI, for clock and data, and D10 used for ssPin. Or any other pin for ssPin, as long as D10 is an output in your sketch so the Uno is the SPI master all the time.
    – CrossRoads
    Commented Feb 26, 2019 at 12:30
  • You are right, SPI and I2C do not conflict, my mistake: answer edited. Not sure what you meant with all the additional comments, I also stated the hardware SPI is much faster than software port manipulation. Commented Feb 26, 2019 at 14:40
  • Yes, we are in agreement that SPI is the way to go.
    – CrossRoads
    Commented Feb 26, 2019 at 17:26
  • So does that mean that none of the pin specifications are 'enforced'? E.g. can I do PWM on a non-PWM pin, or even I2C on any arbitrary digital pins? Commented Feb 26, 2019 at 19:32
  • 1
    Let’s put it this way: if it is absolutely necessary and you are willing to deal with plenty of hassles, yes, you can have serial comm, SPI or I2C on any general IO pin, with some limitations regarding speed. Also PWM can be achieved, with a lower frequency and sacrificing precious processor cycles just to output the square wave. Be warned: nobody has advised you to go down this route and we are explicitly stating it’s going to be a tough path if you decide to follow it. Commented Feb 26, 2019 at 23:39
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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.