MAX7221 SPI 8-Digit LED Display Driver
A master ATMega32 SPI could send data to many SPI slave devices on bus. MAX7221 is another example of an SPI slave device. MAX7221 is an 8-digit display driver. It could fit multiplexed seven-segment display, or a 8x8 dot matrix display. Both seven-segment and dot matrix display are common cathode. For more digits we can use a daisy-chain with preferred numbers of MAX7221.00:00 / 00:00
![]() |
A sample simulation of this example |
This device work independently. The master MCU configures and send the data only once. Then MAX7221 periodically displays and refresh by itself.
![]() |
MAX7221 28-DIP Package |
![]() |
Pin description of MAX7221 |
The data for format for MAX7221 reception is 16-bit wise, and device into two 8-bit registers.
![]() |
Command register uses only 4 lower nibble. |
I don't list all datasheet full specification here. I list only some needed technical details.
Every command register has its own address. We must load these address with any appropriate values.
![]() |
MAX7221 Register Map |
These commands with value I selected:
- The 0x09 command register loads with 0xFF to enable BCD decoding for all digits.
- The 0x0B command register loads with 0x01 to limit the scanning for only digit 0 and 1.
- The 0x0C command register loads with 0x01 to turn on the device (called normal operation).
- The 0x0A command register loads with 0x09 to set the intensity to 10/16.
- All digits have its own command register ranges from 0x01 to 0x08. We load these command registers to display the value. The value could be a BCD format or anythings, up to the pre-setting.
In this example, I turn on only two digits. This two-digit display show the counting value at one second rate.
![]() |
A sample of program |
ATMega32 C Source Code In Atmel Studio 7
The Atmel Studio 7 C source code is here.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* spi_max7221.c | |
* | |
* Created: 7/14/2020 8:49:34 PM | |
* Author : https://aki-technical.blogspot.com | |
*/ | |
#include <avr/io.h> | |
#define F_CPU 4000000UL | |
#include <util/delay.h> | |
#define MOSI 5 | |
#define SCK 7 | |
#define SS 4 | |
void max7221Send(unsigned char cmd,unsigned char data){ | |
/*Select the slave*/ | |
PORTB&=~(1<<SS); | |
/*Send the command*/ | |
SPDR=cmd; | |
while(!(SPSR&(1<<SPIF))); | |
SPDR=data; | |
while(!(SPSR&(1<<SPIF))); | |
PORTB|=(1<<SS); | |
} | |
void masterInit(void){ | |
DDRB=(1<<MOSI)|(1<<SCK)|(1<<SS); | |
/*Enable The SPI Master with fOSC/4*/ | |
SPCR=(1<<SPE)|(1<<MSTR); | |
} | |
int main(void) | |
{ | |
char cnt=0; | |
masterInit(); | |
/*Enable Digit decode for all digits*/ | |
max7221Send(0x09,0xFF); | |
/*Scan two 7-segments 0 and 1*/ | |
max7221Send(0x0B,0x01); | |
/*Turn On The Chip - Normal Operation*/ | |
max7221Send(0x0C,0x01); | |
/*Set The Intensity To 10/16*/ | |
max7221Send(0x0A,0x09); | |
while (1) | |
{ | |
max7221Send(0x01,cnt/10); | |
max7221Send(0x02,cnt%10); | |
_delay_ms(1000); | |
cnt+=1; | |
if(cnt>=60) cnt=0; | |
} | |
} | |
A full schematic diagram lists below.
![]() |
Schematic Diagram |
code doesnt work in real life.
ReplyDeleteThis post was a delightful discovery! Your writing not only captures the essence of the topic but also makes it resonate on a personal level. The examples you chose were spot on, making the content both relatable and enlightening. Thanks for sharing your insights; I’m definitely bookmarking this for future reference!
ReplyDeleteLED Display Drivers
Enrgtech