Is there a way to be sure if I am using the *hardware* SPI and getting that fast SPI speed? I have it all on the pins assigned as needed, but I am still having a speed issue in my program. When I have the display on, there is some slowdown, even if I only send a tiny bit of data to the display. (Using an Uno)
Can I be sure I'm enabling the fast hardware SPI here in this sample code?
#define LOAD 10
#define DIN 11
#define DOUT 12
#define SPICLOCK 13
int counterNumber1 = 0;
int counterNumber10 = 0;
void setup()
{
int clr;
pinMode(DIN, OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(LOAD,OUTPUT);
digitalWrite(LOAD,HIGH); //disable device
// SPCR = 01010000
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
//sample on leading edge of clk,system clock/4 (fastest)
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
//clear MAX7219 and format to receive data
write_7seg(0x0C,1);
write_7seg(0x09,0xFF);
write_7seg(0x0A,0x0F);
write_7seg(0x0B,0x04);
}
void loop()
{
write_7seg(1, counterNumber1);
write_7seg(2, counterNumber10);
delay (10)
}
//spi transfer function (from ATmega168 datasheet)
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received int
}
//MAX7219 data transfer function
int write_7seg(int digAddress, int displayValue)
{
digitalWrite(LOAD,LOW); //MAX7219 chip select is active low
//2 int data transfer to MAX7219
spi_transfer(digAddress);
spi_transfer(displayValue);
digitalWrite(LOAD,HIGH); //release chip, signal end transfer
}