11.4 Questions and Answers
Figure-11.8: Internal circuit modules of MAX7219
1. MAX7219 (Fig-11.2) has SPI communication port by which it receives new data from MCU for the and then they are correctly routed/distributed among the digits of the multiplexed display unit.
2. The "display refreshing" happens automatically without any intervention from the MCU side with the help of its own "scanning circuit".
3. One MAX7219 chip can handle 1 to 8 CC-type display devices. the chip can be cascaded with many more MAX7219 chips with the help of the DOUT-pin to expand the number of display digits in the display unit.
4. The MAX7219 chip contains registers, storage space, scanning circuit, and power driver for the management of the multiplexed display unit.
5. To ensure uniform current flow through each segment of each digit of the display unit, an external resistor (Rex1, Fig-11.2) of about 9.9k is connected across Pins-18 and 19.
6. (1) The host MCU/UNO delivers data to the MAX7219 chip using SPI Port; where, the "unit of data item" (data size) is "16-bit" (Fig-11.6). However, data from MCU to MAX7219 is transferred 1-byte at a time. So, thee is a need of "two transactions" to transfer 16-bit data from MCU to MAX7219.
(2) The data item is composed of "8-bit register address" and "8-bit register data".
(3) The MSBit is transmitted first (Fig-11.6) and shifted-in into the buffer register at the rising edge of SCK signal.
(4) When shifting of all 16 bits is done, the bits are latched into their respective register at the rising edge of LAOD signal.
(5) Example: To set operating mode of MAX7219 into "Normal Mode’" by storing 0x01 into Shutdown Register (address 0x0C), the following steps are carried out:
(a) Transfer Register Address (0x0C = 00001100) by executing SPI.transfer(0x0C);. As a result, 0x0C occupies D7-D0 positions of shift register of Fig-11.6.
(b) Transfer Register Data (0x01 = 0000 0001) by executing SPI.transfer(0x01);. As a result, data bits of Step-(a) goes to D15-D8 positions and 0x01 occupies D7-D0 positions of Fig-11.6.
(c) Activate LOAD Signal by executing LOW-HIGH-LOW on PB2-bit of Fig-11.2. As a result, Shutdown Register is selected and the data byte 0x01 enters into it; the operating mode of MAX7219 is set to "Normal Mode".
(d) Codes for the Step-a,b, c:
SPI.transfer(0x0C); //address of Shutdown Register; 8 SCK pulses are generated
SPI.transfer(0x01); //data for Shutdown Register; 8 SCK pulses are generated
Activate L-H-L on LOAD line via DPin-10 //data is latched into Shutdown Register of 1st chip.
7. Register Map of MAX7219
(1) Digit 0/Digit 7 Register:
(a) When 0x00 is written into "Decode Mode Register", then "8-bit data of Digit 0 Register" (to be written by user) control the ON/OFF conditions of the 8 segments of the cc-type display device (DP0 of Fig-11.2) as per Fig-11.8.
(b) Example: To show 2 at DP0 position of Fig-11.2, what value should we put into Digit 0 Register?
Ans: The cc-code of 2 is: (p g f e d c b a = 0 1 0 1 1 0 1 1 = 0x5B). But, to comply with Fig-11.8, the cc-code of 2 (p g f e d c b a = 0 1 0 1 1 0 1 1) has to be re-arranged this way: p a b c d e f g = 0 1 1 0 1 1 0 1 = 0x6D. Now, we have to send 0x6D into Digit 0 Register. This way, we can manually make all the "No-decode CC-codes" for the digits 0 – F and declare them by the following Lookup Table (LUT). To bring the decimal point into ON state, we may just put HIGH at DP position of Fig-11.8 (or of the re-arranged cc-code).
byte lupTable[] = {0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F,
0x7B, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47}; //0, 1, ..., E, F ; No-decode cc-codes
(2) Decode Mode Register: When 0x00 (according to data sheets) is written into "Decode Mode Register", then the role of this register is as explained in Step-a.
(3) Intensity Register: It controls the intensity of the brightness of the display digits. A value of 0x01 is good enough.
(4) Scan Limit Register: This register decides the number of display digits to be scanned (0 for 1-digit, DP0; 1 for 2-digit, DP0-DP1; …, 7 for 8-digit DP0-DP7).
(5) Shutdown Register: A value of 0x01 configures the "Normal Mode" operation of the MAX7219 chip.
(6) No-op (No Operation) Register: This register plays its role when 2 or more MAX7219 chips are operated in cascade. Say, we have 2 chips in cascade and we want to store 0x01 into their respective Shutdown Registers. The procedures/codes to initialize Shutdown Register of 1st MAX7219 chip are:
SPI.transfer(0x0C); //address of Shutdown Register; 8 SCK pulses are generated
SPI.transfer(0x01); //data for Shutdown Register; 8 SCK pulses are generated
Activate L-H-L on LOAD //data is latched into Shutdown Register of 1st chip.
//------------------------------------------------------------------------------------------------------
To initialize the Shutdown Register of the 2nd MAX7219 chip, we need (8+8) + (8+8) SCK pulses of which 1st (8+8) SCK pulses are generated using SPI.transfer(0x0C) and SPI.transfer(0x01) instructions and the next (8+8) SCK pulses are generated using SPI.transfer(0x00 = address of No-op Register) and SPI.transfer(0xFF=any data for No-op Register) instructions. As a result, the 16-bit value 0C01 are shifted out via DOUT-pin into the shift register of the 2nd MAX7219 chip. After that LOAD pulse is activated; 0xFF enters into No-op Register of 1st chip (no harm) and 0x01 enters into Shutdown Register of 2nd chip.
8. Example Sketch: (to show 27.65 on Display Unit of Fig-11.2)
#include<SPI.h>
byte registerAddress[] = {0x09, 0x0A, 0x0B, 0x0C};//Registers of MAX7219 to be initialized
byte registerData[] = {0x00, 0x01, 0x03, 0x01}; //data for registers of AMX7219
byte dataArray[4] = {0x6D, 0x70, 0x5F, 0x5B}; //cc-code for 2 7. 65 (no-decode format)
byte digitAddress[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};//digit address
void setup()
{
pinMode(10, OUTPUT); //LOAD Pin of MAX7219
//-------------------
SPI.begin();
bitSet(SPCR, 4); //UNO is Master SPI
SPI.setBitOrder(MSBFIRST); //MSB_bit will be transferred first
SPI.setClockDivider(SPI_CLOCK_DIV128); //TX rate = 16MHz/128 = 125 kbit
SPI.setDataMode(SPI_MODE1);//MOSI is sampled at the rising edge of CLK
//------------------------------------------------
digitalWrite(10, LOW); //Low at LOAD pin
//---- computation----------------------------------
byte z = 0x12 + 0x13; //z = 3C
dataArray[0] = lupTable[z>>4];
dataArray[1] = lupTable[z&0x0F];
//-------------------------------------------------
//---keep intializing the Mode of Operation------------
for(int i=0; i<4; i++)
{
SPI.transfer(registerAddress[i]);
SPI.transfer(registerData[i]);
digitalWrite(10, LOW);
digitalWrite(10, HIGH); //assert LH/LL on LOAD pin
digitalWrite(10, LOW);
}
//--keep transferring the result/data----------------------
for(int i=0; i<4; i++)
{
SPI.transfer(digitAddress[i]); //DPX position
SPI.transfer(dataArray[i]); //shows 2 on DP0-position
digitalWrite(10, LOW);
digitalWrite(10, HIGH); //assert LH/LL on LOAD pin
digitalWrite(10, LOW);
}
}
void loop()
{
}

...to be continued.

