I am trying to show values of ADC0, ADC1, and ADC2 on 3 different 3-digit displays. I am using 3 Max7219 connected in daisy-chain configurations, but I am struggling and could really use some help to do that.
I was able to show 1 on display 1, 2 on display 2, 3 on display 3 through the following code:
#include <avr/io.h>
#include <util/delay.h>
// SPI initialization
void SPI_Init() {
// Set MOSI (PB5) and SCK (PB7) as output
DDRB |= (1<<PB5) | (1<<PB7);
// Set SS (PB4) as output
DDRB |= (1<<PB4);
// Enable SPI, Master mode, set clock rate fck/16
SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0);
}
// Send a byte via SPI
void SPI_SendByte(uint8_t data) {
SPDR = data;
while (!(SPSR & (1<<SPIF))); // Wait for transmission complete
}
// Send a command to all MAX7219s
void MAX7219_Send(uint8_t address, uint8_t data) {
PORTB &= ~(1<<PB4); // SS low
SPI_SendByte(address); // Address
SPI_SendByte(data); // Data
PORTB |= (1<<PB4); // SS high
}
// Initialize MAX7219
void MAX7219_Init() {
MAX7219_Send(0x09, 0x00); // Decode mode: No decode for all digits
MAX7219_Send(0x0B, 0x02); // Scan limit: Display digits 0-2 (3 digits)
MAX7219_Send(0x0C, 0x01); // Shutdown: Normal operation
MAX7219_Send(0x0F, 0x00); // Display test: Off
}
// Display values on each of the 3-digit displays
void Display_Values() {
// Display "1" on the first display (digit 0)
MAX7219_Send(1, 0x30); // "1" on digit 0
MAX7219_Send(2, 0x00); // Clear digit 1
MAX7219_Send(3, 0x00); // Clear digit 2
// Select the second display (CS line for second MAX7219)
PORTB &= ~(1<<PB4); // SS low for the second MAX7219
SPI_SendByte(1); // Address digit 0
SPI_SendByte(0x6D); // "2" on digit 0
PORTB |= (1<<PB4); // SS high
// Select the third display (CS line for third MAX7219)
PORTB &= ~(1<<PB4); // SS low for the third MAX7219
SPI_SendByte(1); // Address digit 0
SPI_SendByte(0x79); // "3" on digit 0
PORTB |= (1<<PB4); // SS high
}
int main() {
SPI_Init(); // Initialize SPI
MAX7219_Init(); // Initialize all MAX7219s
while (1) {
Display_Values(); // Display "1", "2", "3" on each of the 3 displays
_delay_ms(2000); // Delay to observe
}
}
1. Which Arduino Board (UNO/NANO/MEGA) and which ADC Channels are you using?
2. Cascade operation of MAX7219 requires a bit good undestanding of the role of "No-op Register" of the MAX7219.
3. I would suggest that you first make three individual display units with three mAX7219. After that you cascade two, make them operational, and then cascade all three.
4. Working with MAX7219 will be very much enjoyable if you can use the follwing MAX7219-driven display units (Fig-1).
Is the above a count from an ADC channel? What is the corresponding input DC voltage? Do you want to show that voltage on the display unit? How many digits do you want after the decimal point?
It's good that you are playing with ATmega32 which was my favorite one before I have switched overt to ATmega328P. Anyway, being a Arduino Forum Member, you may own Arduino UNO/NANO/MEGA.
How are you programming the TAmega32? Are you using Arduino as ISP Programmer?
It's good that you are playing with ATmega32 which was my favorite one before I have switched overt to ATmega328P. Anyway, being a Arduino Forum Member, you may own Arduino UNO/NANO/MEGA.
How are you programming the TAmega32? Are you using Arduino as ISP Programmer?