I am trying to drive a MAX7219 LED controller and 8×8 LED Matrix via SPI from my Arduino MEGA 2560. I can control the MAX7219 via SPI using my Bus Pirate, but for whatever reason, when I try to control it from Arduino (code below) I get no response. Furthermore, I connected my Bus Pirate to my Arduino SPI pins and put it in sniffing mode, and it shows no communication, whether or not CS is low. Does anyone have any idea why this is not working?
Code:
#include "SPI.h"
void setup() {
pinMode(10, OUTPUT);
lcd.begin(20,4);
SPI.begin();
pinMode(13, INPUT);
}
void spiWrite(byte reg, byte data){
digitalWrite(10, LOW);
SPI.transfer(reg);
SPI.transfer(data);
digitalWrite(10, HIGH);
}
void resetMAX(){
spiWrite(0x0f, 1);
spiWrite(0x0c, 1);
spiWrite(0x02, 13);
}
void loop() {
if(digitalRead(13)==HIGH){
resetMAX();
} else {
spiWrite(0x0f, 0);
}
}
I am using the SPI pins on the ICSP header (Clock = 3, MOSI = 4) and Pin 10 (on the PWM side of the arduino) for the Slave Select. On Pin 13, I have a switch to enable sending different commands to the MAX7219, though that is currently having no effect, since it seems I am sending no SPI commands at all. Thoughts?
Best Answer
I found this on the Arduino SPI page http://arduino.cc/en/Reference/SPI
Not sure if it will fix the problem, so far most of my boards have used the SS pin as an output regardless.