Page 1 of 1
					
				Arduino Uno SPI Master sending incorrect data to MAX7219
				Posted: Tue Oct 28, 2025 3:31 pm
				by Bijumon
				Hello,
I am testing the SPI Master component with an Arduino Uno to drive a MAX7219 LED driver, But SPI bus sending incorrect data.
i have tested both hardware and software channel.
For example, when I send 0x09, the SPI debugger in Proteus shows 0x84.
Proteus debugger screenshot is attached.
			 
			
					
				Re: Arduino Uno SPI Master sending incorrect data to MAX7219
				Posted: Tue Oct 28, 2025 4:01 pm
				by BenR
				Hello,
SPI has a number of modes which dictate things like which phase of the clock the data is sampled and the state of the clock when idle.
It looks like Flowcode and Proteus are simply using different settings and hence getting different values.
0x09 = 0b00001001
0x84 = 0b10000100  0x80 = 0b10000000
So it's the same data just shifted by one bit position due to the clock edge configuration mismatch.
			 
			
					
				Re: Arduino Uno SPI Master sending incorrect data to MAX7219
				Posted: Tue Oct 28, 2025 4:57 pm
				by Bijumon
				Hi BenR,
Thank you for your prompt reply.
I first tested the program on real hardware (Arduino Uno), but it did not work.
To investigate, I ran the same program in Proteus for simulation and debugging.
Then I tried the exact same Flowcode program using a PIC16F18877 target, and the simulation worked correctly in Proteus (I don’t have real PIC hardware for testing).
Please find the PIC16F18877 Proteus debugger screenshot attached for your reference.
Thanks....
			 
			
					
				Re: Arduino Uno SPI Master sending incorrect data to MAX7219 (Solved)
				Posted: Wed Oct 29, 2025 4:16 pm
				by Bijumon
				Hi BenR,
I finally managed to get it working by using direct C code to initialize the SPI, instead of the SPI Initialize component macro.
Now everything works fine!
Here’s the code I used:
// --- SPI pins setup ---
DDRB |= (1 << PB3) | (1 << PB5) | (1 << PB2);  // MOSI, SCK, SS as output
DDRB &= ~(1 << PB4); // MISO as input
PORTB |= (1 << PB2); // SS high (inactive)
// --- SPI Control Register setup ---
// SPE  = 1 → Enable SPI
// MSTR = 1 → Master mode
// CPOL = 0, CPHA = 0 → SPI mode 0 (clock idle low, sample on rising edge)
// SPR1:0 = 01 → fosc/16  (safe speed for MAX7219)
SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0);
Thanks!