Hi guys. I originally posted this as a post under my LED matrix thread but feel i need to move it here now.
I have a single TLC5940 running just the R and B lines of my common annode matrix with the annodes connected to the 595Register.
Both my 595 and TLC are wired up via SPI - the TLC is pinned out exactly as per the basic use library and the 595 with its SS connected to Digital 2.
Ive checked, double checked and tripple checked my wiring and cant see any issues - anyway i have the following in my main loop:
Tlc.clear();
Tlc.set(1, 10);
Tlc.set(14, 100);
while (Tlc.update());
//PORTD &= ~(1<<2);
digitalWrite(2, LOW);
SPDR = B10101010;
digitalWrite(2, HIGH);
while (!(SPSR & _BV(SPIF)));
- Note i actually have my annodes connected directly to 5v instead of going through the 595 to make life easier to see whats happening.
If i take out my SPDR = B10101010 line above the led matrix display works as expected. 2 rows of very dimly lit LEDs - 1 red and 1 blue.
If i add the SPDR line back in i get the 2 lines i want lit up but at 100% brightness, then a line either side of the 2 lit up dim - as if my attempted SPI data has nudged the TLC's or something.
Ive tried including an spi_init:
void spi_init(void) {
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT); /* Should be output in Master mode. */
// pinMode(2, OUTPUT);
SPCR &= ~(_BV(DORD)); /* MSB first. */
SPCR |= _BV(MSTR); /* Act as master. */
SPCR |= _BV(SPIE);
}
but in the end took this out as it seems the TLC library already includes and sets this stuff up and makes no difference to the outcome.
If i add a delay(10) before my SPDR data theres no problem (aside from the fact id get insane amounts of flicker when i rewire it back to the 595 and multiplex). As i reduce that delay i can steadily see the LED output becoming more random/corrupt to the point where at around delay(1) it appears okay for a half second and then flickers to the wrong columns being lit up.
Im new to all this, but thought i understood the SPI okay now after spending hours and hours reading up on all the registers etc. Clearly not though!
really need some advice here anyone encountered this before?? im all out of ideas and just cant see where im going wrong - im almost certain im wired up correctly as it works fine without my own attempted SPI call. Should i just bitbang the 595 register and be done with it (really dont want to as i need the pins)? How much slower would this be?
Thanks all - hope someone can steer my newbie skill set in the right direction!
Carl.