Current leakage with SPI?

Hello,

I'm selecting the line and column of my 8x8 matrix with SPI. I have a problem, sometimes one or more LEDs are selected when they shouldn't. I checked the decoding code that decodes the 64bits and iterates over each bit, and I'm sure that it is correct (I displayed the value in ascii in the console and it's good).

Moreover I know that it's not a decoding problem because depending on the order on how I call the SPI transfer, the LEDs that are displayed and should not are different.

For instance when writing this code:

void matrix2_display_dot(char line, char column)
{
    digitalWrite(RCLKPin, LOW);
    SPI.transfer(1<<line);
    digitalWrite(RCLKPin, HIGH);

    digitalWrite(RCKPin_tpic6b595, LOW);
    SPI.transfer(1<<column);
    digitalWrite(RCKPin_tpic6b595, HIGH);
}

I get a different result than when writing this code:

void matrix2_display_dot(char line, char column)
{
    digitalWrite(RCKPin_tpic6b595, LOW);
    SPI.transfer(1<<column);
    digitalWrite(RCKPin_tpic6b595, HIGH);

    digitalWrite(RCLKPin, LOW);
    SPI.transfer(1<<line);
    digitalWrite(RCLKPin, HIGH);
}

What's the problem? Is there some current leakage or something?

Perhaps there is a problem elsewhere in your code. Could you post a small sketch that lights one LED and demonstrates the problem? Are you sure your shift registers are wired correctly? Did you include bypass capacitors near your shift registers?

Is there some current leakage or something?

No it is either lack of decoupling or code and as you have not described either we can not help.

When I display the LEDs one by one and slowly they are displayed correctly. The code for displaying a picture is like this:

void pic_display(pic_t pic)
{
    int line;
    int column;
    
    for(int i = 0; i < 64; i++) {
        line = i / 8;
        column = i % 8;

        if(pic & (0x8000000000000000 >> i)) {
            matrix2_display_dot(line, column);
        }
        
    }
}

I didn't used capacitors, should I?

But I have a new idea, maybe the problem is that when the 74HC595 is selected the PREVIOUS value of the TPIC tpic6b595 is still active for a fraction of time, and thus display the wrong value?

I didn't used capacitors, should I?

Yes always use a capacitor on every external chip.

There is nothing wrong with that code appart from the fact that is is just a small part of the code. Wee need to see it all. Add it as an attachment if it is too big to post.

The whole code is available here http://bit.ly/15ruDRL but there isn't much more than what I posted.

Could you refer me to a tutorial explaining what type of capacitors I need, and on which IC pins I need to connect them?

Could the few displayed LEDs that shouldn't be displayed due to the lack of synchronisation between the select of the line and the select of the column? If so how can I synchronize both? Do I need to chain the TPIC.... with the 74HC.... ?

Read this
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

It would also help to see the schematic as code is very specific to hardware.

8rmfyj5U3Qk:
I didn't used capacitors, should I?

Yes. This is the most likely cause of the problem.