I'm using a MAX7219 and 6 (six) seven segment displays I used my own board and two purchased on ebay - no difference in operation. MOSI, and CLK are correct and verified with my scope (Tektronics) CS (chip select) is pin 22 (for no particular reason) SPI is set to Mode0 Yes, I have tried other pins as CS - all work the same. My MEGA board can be powered by USB or 9.9 VDC wall-wart - no difference Trial code is shown below, and works properly. Placed 47 uF 50V cap on display board between +5 and GND - no effect Placed 220 uF 35V cap on display board between +5 and GND - no effect MOSI, SCK and CS are verified with scope to be 5 VDC. Compiler and D/L applications are set to MEGA and seem to work properly.
PROBLEM IS THIS: Code compiles and D/L properly into Mega. Mega resets, and about 50% of the time all digits illuminate (not executing code properly?) Digit 0 (most right hand digit is enabled) never works. I can press the reset on the Mega as many times as I want - no effect.
HOWEVER if I pull either +5 or GND to the MAX7219 module, and reset my Mega, it works perfectly. Yes, this is obviously a reset problem, but I've never seen a reset problem before with the MAX7219. I put delays at the beginning at short delays in the SPI communications to no effect.
Has anyone ever seen anything like this before? I have no hair left to pull. I'm thinking maybe to use a MOSFET to turn the MAX7219 on after the MEGA is up and running. Any suggestions are appreciated.
//version 0.1
#include <SPI.h>
#define LOAD_PIN 22
void maxTransfer(uint8_t address, uint8_t value) {
digitalWrite(LOAD_PIN, LOW); // Ensure LOAD/CS is enabled (LOW)
SPI.transfer(address); // Send the register address
SPI.transfer(value); // Send the value
digitalWrite(LOAD_PIN, HIGH); // Tell chip to toggle in data
}
void setup() {
pinMode(LOAD_PIN, OUTPUT); // Set port pin to output
// Reverse the SPI transfer to send the MSB first
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
// Start SPI with attributes in "SPI.beginTransaction"
delay(250);
SPI.begin();
maxTransfer(0x09, 0xFF); // Enable mode B
maxTransfer(0x0A, 0x0F); // Use highest intensity
maxTransfer(0x0B, 0x00); // Only scan digit 0
maxTransfer(0x0C, 0x01); // Turn on chip
}
void loop() {
// Loop through each code
for (uint8_t i = 0; i < 0x10; ++i)
{
maxTransfer(0x01, i);
delay(50);
}
}