Now I am cascading two MAX7219 matrix LEDS. I tried to display two characters, but only the first matrix displays the character. I swapped the matrix LEDs then the original second, now first matrix LED display the character. So it appears that the hardware connections are OK, the software has a bug.
From MAX7219 datasheet
...
No-Op Register
The no-op register is used when cascading MAX7219s or MAX7221s.
Connect all devices’ LOAD/CS inputs together and connect DOUT to DIN on adjacent
devices.
DOUT is a CMOS logic-level output that easily drives DIN of successively cascaded parts. (Refer to the Serial Addressing Modes section for detailed information on serial input/output timing.)
For example, if four MAX7219s are cascaded, then to write to the fourth chip, sent the desired 16-bit word, followed by three no-op codes (hex 0xXX0X, see Table 2). When LOAD/CS goes high, data is latched in all devices. The first three chips receive no-op commands, and the fourth receives the intended data.
testMax7219SegmentLed01(SPI_CHANNEL_0);
testMax7219MatrixLed01(SPI_CHANNEL_1);
// ***************************************************************************
// Function - Test MAX7219 8x8 matrix LED
// Date - 2013nov06
// ***************************************************************************
void testMax7219MatrixLed01(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219MatrixLed01(spiChannelNumber);
}
// ***************************************************************************
// Function - Test MAX7219 7-segment LED
// Date - 2013nov06
// ***************************************************************************
void testMax7219SegmentLed01(uint8_t spiChannelNumber)
{
setupSpi051(spiChannelNumber);
max7219SegmentLed01(spiChannelNumber);
}
// ***************************************************************************
// Function - Display 8x8 matrix LED
// Date - 2013nov06
// ***************************************************************************
void max7219MatrixLed01(uint8_t spiChannelNumber)
{
// *** Print project title ***********************************************
printf("\n\n*** Matrix LED 01 - 2013nov06hkt1154 ***\n\n");
// *** Setup MAX7219 digit control register buffer ***********************
#define BUFFER_SIZE 2
#define ADDRESS_INDEX 0
#define DATA_INDEX 1
uint8_t txBuffer[BUFFER_SIZE];
uint8_t rxBuffer[BUFFER_SIZE];
// *** Setup SPI xferConfig ***
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = txBuffer;
xferConfig.rx_data = rxBuffer;
xferConfig.length = BUFFER_SIZE;
// *** Setup MAX7219 for digit decode and scan limit ***
// setUpMax7219NoDecode(txBuffer, xferConfig, spiChannelNumber);
// *** Setup Two MAX7219 ***
setUpTwoMax7219NoDecode(txBuffer, xferConfig, spiChannelNumber);
// *** Display 8 digits ***
/*
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_7, PATTERN_ALL_ON);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_6, PATTERN_ALL_ON);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_5, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_4, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_3, PATTERN_ALL_ON);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_2, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_1, PATTERN_ALL_ON);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_0, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, OPERATION_ADDR, NORMAL);
*/
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, SHUTDOWN_ADDR, SHUTDOWN_MODE);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_7, charA[0]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_6, charA[1]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_5, charA[2]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_4, charA[3]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_3, charA[4]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_2, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_1, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_0, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_7, charA[0]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_6, charA[1]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_5, charA[2]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_4, charA[3]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_3, charA[4]);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_2, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_1, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_0, PATTERN_ALL_OFF);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, OPERATION_ADDR, NORMAL);
}
// ***************************************************************************
// Function - Display 4 digits of 7-segment LED
// Date - 2013nov06
// ***************************************************************************
void max7219SegmentLed01(uint8_t spiChannelNumber)
{
// *** Print project title ***********************************************
printf("\n\n*** Segment LED 01 - 2013nov06hkt1128 ***\n\n");
// *** Setup MAX7219 digit control register buffer ***********************
#define BUFFER_SIZE 2
#define ADDRESS_INDEX 0
#define DATA_INDEX 1
uint8_t txBuffer[BUFFER_SIZE];
uint8_t rxBuffer[BUFFER_SIZE];
// *** Setup SPI xferConfig ***
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = txBuffer;
xferConfig.rx_data = rxBuffer;
xferConfig.length = BUFFER_SIZE;
// *** Setup MAX7219 for digit decode and scan limit ***
setUpMax7219BcdCodeB(txBuffer, xferConfig, spiChannelNumber);
// *** Display 8 digits ***
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_7, CHAR_H);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_6, CHAR_E);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_5, CHAR_L);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_4, CHAR_P);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_3, CHAR_BLANK);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_2, CHAR_BLANK);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_1, DIGIT_0);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, DIGIT_ADDR_0, DIGIT_1);
displayOneDigit(txBuffer, xferConfig, spiChannelNumber, OPERATION_ADDR, NORMAL);
}
// ***************************************************************************
// Function - Write MAX7219 command
// Date - 2013nov06
// ***************************************************************************
void writeLedCommand(uint8_t txBuffer[BUFFER_SIZE], SSP_DATA_SETUP_Type xferConfig, \
uint8_t spiChannelNumber, \
uint8_t commandRegisterAddress, uint8_t command)
{
txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;
SpiWriteRead050(xferConfig, spiChannelNumber);
}
// ***************************************************************************
// Function - Display 1 digit
// Date - 2013nov06
// ***************************************************************************
void displayOneDigit(uint8_t txBuffer[BUFFER_SIZE], SSP_DATA_SETUP_Type xferConfig, \
uint8_t spiChannelNumber, \
uint8_t digitAddress, uint8_t digitData)
{
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, digitAddress, digitData);
}
// ***************************************************************************
// Function - Set up MAX7219 for Code B of all 8 digits, scan 8 digits
// Date - 2013nov06
// ***************************************************************************
void setUpMax7219BcdCodeB(uint8_t txBuffer[BUFFER_SIZE], SSP_DATA_SETUP_Type xferConfig, \
uint8_t spiChannelNumber)
{
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, SHUTDOWN_ADDR, SHUTDOWN_MODE);
delayTime(ONE_FIFTH_SECOND);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
DECODE_MODE_ADDR, CODE_B_ALL_DIGITS);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
SCAN_LIMIT_ADDR, DISPLAY_8_DIGITS);
}
// ***************************************************************************
// Function - Set up MAX7219 for no decode all 8 digits, scan 8 digits
// Date - 2013nov06
// ***************************************************************************
void setUpMax7219NoDecode(uint8_t txBuffer[BUFFER_SIZE], SSP_DATA_SETUP_Type xferConfig, \
uint8_t spiChannelNumber)
{
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, SHUTDOWN_ADDR, SHUTDOWN_MODE);
delayTime(ONE_FIFTH_SECOND);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
SCAN_LIMIT_ADDR, DISPLAY_8_DIGITS);
}
void setUpTwoMax7219NoDecode(uint8_t txBuffer[BUFFER_SIZE], SSP_DATA_SETUP_Type xferConfig, \
uint8_t spiChannelNumber)
{
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, SHUTDOWN_ADDR, SHUTDOWN_MODE);
delayTime(ONE_FIFTH_SECOND);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, SHUTDOWN_ADDR, SHUTDOWN_MODE);
delayTime(ONE_FIFTH_SECOND);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
SCAN_LIMIT_ADDR, DISPLAY_8_DIGITS);
writeLedCommand(txBuffer, xferConfig, spiChannelNumber, \
SCAN_LIMIT_ADDR, DISPLAY_8_DIGITS);
}
.END
No comments:
Post a Comment