I’m attempting to interface an arduino with the “button pad controller” using spi. I can’t seem to get the controller to respond.
Here is my code. If anyone has any ideas what I’m doing wrong, I would much appreciate the help! Thanks!
#define SCK_PIN 13 // Clock
#define MISO_PIN 12
#define MOSI_PIN 11
#define SS_PIN 10 // Control Signal
byte red[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte green[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte blue[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte buttons[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
//---------------------------------------
// SETUP AND LOOP
//---------------------------------------
// Set up Everything
void setup() {
setupSPI();
}
// Loop
void loop() {
digitalWrite(SS_PIN, HIGH);
for(int i = 0; i < 16; i++)
{
transfer(red[i]);
}
for(int i = 0; i < 16; i++)
{
transfer(green[i]);
}
for(int i = 0; i < 16; i++)
{
transfer(blue[i]);
}
for(int i = 0; i < 16; i++)
{
transfer(buttons[i]);
}
digitalWrite(SS_PIN, LOW);
delayMicroseconds(500);
}
//---------------------------------------
// SPI DATA
//---------------------------------------
void setupSPI()
{
pinMode(SCK_PIN, OUTPUT);
pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT);
pinMode(SS_PIN, OUTPUT);
modeSPI(0);
}
// Set SPI mode
void modeSPI(byte config)
{
byte tmp;
// enable SPI master with configuration byte specified
SPCR = 0;
SPCR = (config & 0x7F) | (1<<SPE) | (1<<MSTR);
tmp = SPSR;
tmp = SPDR;
}
// transfer a byte
byte transfer(byte value)
{
SPDR = value;
while(!(SPSR & (1<<SPIF))) ;
return SPDR;
}