- Sun Feb 28, 2010 8:25 am
#94886
I am having difficulty daisy chaining two 8x8 RGB matrix backpacks. They are both running the latest firmware and they both work fine as standalones.
The process as I understand it is:
1) Break the chain apart and attach a single backpack via SPI.
2) Send the character '%' to the backpack to enter command mode.
3) Send a decimal digit (not character digit) in the range 1 - 8 to the board indicating how many module are daisy chained.
4) Repeat for each module in the chain.
This part is complete. I am assuming it works since the color bar that first appears at the top changed slightly.
I am not quite sure how I am to send a frame. Looking at RGB_Backpack_v4.c it appears that all I need to do is send 64 * NUMBOARDS bytes - in my case, 128 bytes. However rgbmatrixbackpack_userguide.pdf states that I need to send a 64 byte frame using this process for each backpack in the chain:
1) Assert CS
2) Send 64 byte buffer
3) De-assert CS
4) Repeat for next backpack
I have tried sending 128 bytes within a single assert/deassert and also sending two 64 byte frames broken up by the assest/deassert process. Neither appears to work. I also read in a posting that you need to send the command code at each boot. I tried that, but there was no change.
I took the example backpack sketch and modified it only very slightly. I took the assert/deassert process and put it in a function called sendframe and then move a single blue pixel forward. The first matrix in the chain displays acts somewhat normal, and the second matrix in the chain mirrors the first except it is always shifted a single pixel forward - so if I display something at char_buffer[5] on the first matrix, it appears at the 6th pixel on the second.
Does anyone have any suggestions?
I'd also like to make a quick comment on the firmware code - RGB_Backpack_v4.c appears to track how many times it has booted. On the 255th boot it forces NUMBOARDS back to 1 and writes it to EEPROM.
Here is the code.
The process as I understand it is:
1) Break the chain apart and attach a single backpack via SPI.
2) Send the character '%' to the backpack to enter command mode.
3) Send a decimal digit (not character digit) in the range 1 - 8 to the board indicating how many module are daisy chained.
4) Repeat for each module in the chain.
This part is complete. I am assuming it works since the color bar that first appears at the top changed slightly.
I am not quite sure how I am to send a frame. Looking at RGB_Backpack_v4.c it appears that all I need to do is send 64 * NUMBOARDS bytes - in my case, 128 bytes. However rgbmatrixbackpack_userguide.pdf states that I need to send a 64 byte frame using this process for each backpack in the chain:
1) Assert CS
2) Send 64 byte buffer
3) De-assert CS
4) Repeat for next backpack
I have tried sending 128 bytes within a single assert/deassert and also sending two 64 byte frames broken up by the assest/deassert process. Neither appears to work. I also read in a posting that you need to send the command code at each boot. I tried that, but there was no change.
I took the example backpack sketch and modified it only very slightly. I took the assert/deassert process and put it in a function called sendframe and then move a single blue pixel forward. The first matrix in the chain displays acts somewhat normal, and the second matrix in the chain mirrors the first except it is always shifted a single pixel forward - so if I display something at char_buffer[5] on the first matrix, it appears at the 6th pixel on the second.
Does anyone have any suggestions?
I'd also like to make a quick comment on the firmware code - RGB_Backpack_v4.c appears to track how many times it has booted. On the 255th boot it forces NUMBOARDS back to 1 and writes it to EEPROM.
Here is the code.
// Writing to the RGB Serial Backpack Matrix from SparkFun Electronics
// by Ryan Owens
// Copyright SparkFun Electronics
//Define the "Normal" Colors
#define BLACK 0
#define RED 0xE0
#define GREEN 0x1C
#define BLUE 0x03
#define ORANGE RED|GREEN
#define MAGENTA RED|BLUE
#define TEAL BLUE|GREEN
#define WHITE (RED|GREEN|BLUE)-0xA0
//Define the SPI Pin Numbers
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//sck
#define SLAVESELECT 10//ss
//Define the variables we'll need later in the program
char color_buffer [128];
byte count = 0;
void setup()
{
//SPI Bus setup
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); //Enable SPI HW, Master Mode, divide clock by 16 //SPI Bus setup
//Set the pin modes for the RGB matrix
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
//Make sure the RGB matrix is deactivated
digitalWrite(SLAVESELECT,HIGH);
color_buffer[0] = '%';
color_buffer[1] = 2;
sendframe(1);
sendframe(2);
delay(1000);
}
void sendframe(byte whatboard) {
//Activate the RGB Matrix
digitalWrite(SLAVESELECT, LOW);
delay(1);
//Send the color buffer to the RGB Matrix
if (whatboard == 1) {
for(int LED=0; LED<64; LED++){
spi_transfer(color_buffer[LED]);
}
}
if (whatboard == 2) {
for(int LED=64; LED<128; LED++){
spi_transfer(color_buffer[LED]);
}
}
delay(1);
//Deactivate the RGB matrix.
digitalWrite(SLAVESELECT, HIGH);
}
void loop()
{
//Load colors into the first row color buffer array.
//This will be the array of colors sent to the RGB matrix.
//color_buffer[0]=BLACK;
//color_buffer[1]=RED;
//color_buffer[2]=GREEN;
//color_buffer[3]=BLUE;
//color_buffer[4]=ORANGE;
//color_buffer[5]=MAGENTA;
//color_buffer[6]=TEAL;
//color_buffer[7]=WHITE;
//color_buffer[0] = TEAL;
for (byte i = 0; i < 128; i++) {
color_buffer = BLACK;
}
//for (byte j = 64; j < 128; j++) {
//color_buffer[j] = BLUE;
//}
color_buffer[count++] = BLUE;
if (count > 127) {
count = 0;
}
sendframe(1);
sendframe(2);
//delay(15);
//Activate the RGB Matrix
//digitalWrite(SLAVESELECT, LOW);
//delay(1);
//for(int LED=64; LED<128; LED++){
//spi_transfer(color_buffer[LED]);
//}
//Deactivate the RGB matrix.
//delay(1);
//digitalWrite(SLAVESELECT, HIGH);
//while(1);
delay(500); // allow some time for the Serial data to be sent
}
//Use this command to send a single color value to the RGB matrix.
//NOTE: You must send 64 color values to the RGB matrix before it displays an image!
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission
{
};
return SPDR; // return the received byte
}