PIC32 Shiftbrite problem

I know this is Arduino-land… But you guys are so much cooler than the PIC guys! :stuck_out_tongue:

I tried to change the Arduino shiftbrite code over to PIC32. Here are my major functions…

// Load values into SPI register
void SB_SendPacket() {
    if (SB_CommandMode == 0xB01) {
     SB_RedCommand = 127;
     SB_GreenCommand = 110;
     SB_BlueCommand = 110;
    if(!TxBufFullSPI1())WriteSPI1(SB_CommandMode << 6 | SB_BlueCommand>>4);
    if(!TxBufFullSPI1())WriteSPI1(SB_BlueCommand<<4 | SB_RedCommand>>6);
    if(!TxBufFullSPI1())WriteSPI1(SB_RedCommand << 2 | SB_GreenCommand>>8);
// Latch values into PWM registers
void SB_Latch() {
// Send all array values to chain
void WriteLEDArray() {
  SB_CommandMode = 0xB00; // Write to PWM control registers
  for (i = 0; i<NumLEDs; i++) {
    SB_RedCommand = LEDChannels[i][0] & 1023;
    SB_GreenCommand = LEDChannels[i][1] & 1023;
    SB_BlueCommand = LEDChannels[i][2] & 1023;
  SB_CommandMode = 0xB01; // Write to current control registers
  for (i = 0; i < NumLEDs; i++) SB_SendPacket();   

I am seeing the lights change colors WHEN the array is written. (Every ‘rate’ mS)

However, they should currently all be the same color continuously and instead I am getting apparently random colors.

I am wondering why in the send packet function, all of the bit shifting is going down? This function worked on my AVR but not here and that is where I am leaning towards for a culprit.

Any ideas?


Ok... So the bit shifty stuff was to fill the buffer and I was sending a 16bit buffer. That explained some stuff. I changed the buffer to 32 bits and left the rest of the code as is.

Now my fifth and seventh light are changing but everything else is staying a static color. Albeit, they are not all the color that they are supposed to be.

I still have an issue and I think still that my bits aren't quite right.

It's 1:30 am... maybe sleep will help. :)

No experience with PIC32. But please keep in mind that ALL known ShiftBrite code assumes 16-bit ints and an 8-bit SPI register. If you have a hardware 32-bit SPI buffer then you could do one send per ShiftBrite. Also make sure you're sending MSB first...

Ah... I just looked at the datagram in your document that shows three, 10bit chunks and a 2 bit chunk. I guess that does make sense and I can make the code a lot more simple. All the bit shifting is to fit the data into the 8 bit data buffer thing. This makes sense now too! Thank you! Now, I have to mess with it some more when i get home from work. :)

I'll clean my code up when I get it working an pass it on to you. I'm sure that it can't hurt to have some sample code that works with a PIC laying around when you are selling the things.

Thanks for the support!

i know this is Arduino-land... But you guys are so much cooler than the PIC guys!