This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Arduino - TLC5943 Same RGB LED Pattern

Other Parts Discussed in Thread: TLC5943

Hello folks,

I'm using an Arduino to bit bang to the TLC5943 but I'm not having much luck. Here is my simple bit bang code:

#define BRIGHTNESS_CONTROL_BITS 8
#define GRAYSCALE_CONTROL_BITS 16
#define NUM_CHANNELS_PER_TLC 16
#define NUM_TLC 1
#define NUM_CHANNELS 48
#define NUM_LEDS 16
#define CLK_DELAY 50

const int clk = 13;
const int data = 11;
const int blank = 10;
const int latch = 9;
const int bcsel = 7;
const int gsclk = 3;

const int lowestPin = 2;
const int highestPin = 13;

void pulsePin(int pin) {
  digitalWrite(pin, HIGH);
  delayMicroseconds(CLK_DELAY);
  digitalWrite(pin, LOW);
  delayMicroseconds(CLK_DELAY);
}

void setupGSClk() {
  TCCR2A = 0x33 ;  // WGM2 = 0b111
  TCCR2B = 0x09 ;  // CS2 = 0b001
  OCR2A = 0x01 ;   // TOP = 0x01
  OCR2B = 0x00 ;
  TCNT2 = 0 ;
  pinMode (gsclk, OUTPUT) ;
}

void setGrayscaleValues(const unsigned int *grayscaleValue, int numChannels) {
  digitalWrite(clk, LOW);
  digitalWrite(bcsel, LOW);
  digitalWrite(gsclk, LOW);
  for (int i = 0; i < numChannels; i++) {
    unsigned int mask = 0x8000;
    for (int j = 0; j < GRAYSCALE_CONTROL_BITS; j++) {
      digitalWrite(data, (grayscaleValue[i] & mask) ? HIGH : LOW);
      mask >>= 1;
      pulsePin(clk);
    }
  }
  pulsePin(latch);
}

void setBrightnessControl(int brightnessControl) {
  unsigned int mask = 0x80;
  digitalWrite(clk, LOW);
  digitalWrite(bcsel, HIGH);
  for (int i = 0; i < BRIGHTNESS_CONTROL_BITS; i++) {
    digitalWrite(data, (brightnessControl & mask) ? HIGH : LOW);
    delayMicroseconds(3);
    mask >>= 1;
    pulsePin(clk);
  }
  pulsePin(latch);
}

void setup() {
  Serial.begin(9600);
  for (int i = lowestPin; i <= highestPin; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  const unsigned int led_gs_values[NUM_CHANNELS_PER_TLC] = {
    16383, 16383, 16383, 0, 0, 0, 16383, 16383, 
    16383, 0, 0, 0, 16383, 16383, 16383, 0    
  };  
  digitalWrite(blank, HIGH);
  digitalWrite(latch, LOW);
  digitalWrite(gsclk, LOW);
  setBrightnessControl(64);
  for (int i = 0; i < NUM_TLC; i++) {
    setGrayscaleValues(led_gs_values, NUM_CHANNELS_PER_TLC);
    delay(2000);
  }
  digitalWrite(blank, LOW);
  for (int i = 0; i < 16384; i++) {
    for (int j = 0; j < 16; j++) {
      digitalWrite(gsclk, HIGH);
      delayMicroseconds(3);
      digitalWrite(gsclk, LOW);
      delayMicroseconds(3);
    }
  }
}

Unfortunately, no matter what values I set on the GS or on the BC, the LED pattern remains the same. I have verified the following:

  1. SIN - SCLK are correct for both GS and BC
  2. SOUT - SCLK are correct for both GS and BC
  3. BLANK shuts off the outputs when high, enables outputs when low
  4. If there is no clock signal on GSCLK, then there is no output even if BLANK is low (and vice versa)
  5. XERR remains high at all times
  6. Multiple TLC5943 chips give me the same result (Could be a bad batch of chips but I doubt it?)

However, I should add that I have a strange schematic, different from the EVM:

  1. For easy routing, I did OUT0: LED0_R, OUT1: LED0_G, OUT2: LED0_B, OUT3: LED1_R, ...
  2. Since I was dealing with RGB LEDs, I omitted OUT15. Is this supposed to throw an XERR because of the open LED detected?

Any ideas why I'm not able to change the BC or GS? I am almost sure that this is a code bug rather than a hardware/wiring one.