Hi!
I've started writing the code for the LED cube and I've bumped into a question which might be very basic, but it's also important.
An SPI transfer begins by setting the SS pin to LOW and ends by setting it back to HIGH. In between you transfer the bytes with calls to SPI.transfer(). My question is: when exactly does the transferred data become live on the cube? Immediately after it's written with SPI.transfer(), or only after the SS pin is set back to HIGH?
I'm planning on transferring the data of an NxN horizontal plane like this:
void displayCurrentPlane ()
{
digitalWrite (PIN_SS, LOW); //Start transferring data
SPI.transfer (0xFF); //Turn off the current plane (in fact all planes)(all 1s)
digitalWrite (PIN_SS, HIGH); //Done transferring data
digitalWrite (PIN_SS, LOW); //Start transferring data
for (byte i = N - 1; i >= 0; --i) //Set up the LEDs inside the current plane
{
SPI.transfer (cubeData[currentPlaneIndex][i]);
}
SPI.transfer (~(1 << currentPlaneIndex)); //Turn on the current plane (current plane's bit 0, all other bits 1)
digitalWrite (PIN_SS, HIGH); //Done transferring data
}
Does this seem correct?
Thanks!