1
\$\begingroup\$

I am using an Arduino UNO to control a STP08CP05 - an 8 bit LED driver that has a shift register that allows it to be controlled with an SPI interface: A clock (CLK) pin and a data (SDI) pin.

There is also a latch input, which 'copies' the 8 bits from the shift register to an output array, I think. There's also an output enable pin that is always set low (to enable the output permanently.)

The problem:

If the first bit that is written to the chip while clocking in the 8 bits (in my case the MSB) is set high (on) then all the LEDS turn off. If the MSB bit is low, then the 7 other bits work fine (the correct 7 LEDs light up correctly etc.) The problem is the strange behaviour around the MSB.

Why do all the LEDs turn off if the first bit sent (the MSB) is high?

Here is the code using the SPI library:

#include <SPI.h>
void setup() {
  pinMode(10, OUTPUT); //LE control
  SPI.begin();
  //I've tried changing the SPI mode, etc. I think MODE0 is correct here.
  SPI.beginTransaction(SPISettings(10000, MSBFIRST, SPI_MODE0)); 
}
void loop() {
  while (1) {
    SPI.transfer(64); //sets 2nd to last LED (works), but (128) won't work.
    digitalWrite(10,HIGH); //Toggle LE pin
    digitalWrite(10,LOW);
    delay(100);
  }
}

To try to understand the problem I switched to clocking in the data programmatically (avoiding the library,) but this just reproduces the same problem:

void setup() {
  const int clockPin = 13;
  const int MOSIPin = 11;
  pinMode(10, OUTPUT);
  pinMode(MOSIPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop() {
  const int clockPin = 13;
  const int MOSIPin = 11;
  while (1) {
    for (int n = 0;n<8;n++) {
      digitalWrite(clockPin,LOW);
      int out;
      //this sets the 2nd to last LED (this works) but if it was (n==0) it won't work.
      if (n==1) { out=HIGH; } else { out=LOW; }
      digitalWrite(MOSIPin,out);
      digitalWrite(clockPin,HIGH);
    }
    digitalWrite(clockPin,LOW);
    digitalWrite(10,HIGH); //Toggle LE pin
    digitalWrite(10,LOW);
    delay(100);
  }
}

Useful notes from the datasheet:

pinouts from datasheet*

block diagram from datasheet*

truth table from datasheet*

timing diagram from datasheet*

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Please post the schematics, and a photo of PCB or breadboard to see if what you built has errors or matches the original intention how it is supposed to be built. \$\endgroup\$
    – Justme
    Sep 13, 2021 at 10:11
  • \$\begingroup\$ Thanks Justme - I've reread my question, and your comment made me look at things again. Sorry to have wasted your time. Thanks so much for the help! Hopefully my answer will be useful for someone in the future who has the same, strange bug. \$\endgroup\$
    – lionfish
    Sep 13, 2021 at 20:31

1 Answer 1

1
\$\begingroup\$

Solved: Simply the output enable pin, which I thought I had pulled low (using a 1K resistor) wasn't pulled low, and so was instead floating. This led to the behaviour described above. I guess this pin must have been taken slightly 'high' by either the SDO or OUT7.

Sorry for wasting SE's time with this - I was assuming my mistake was due to misunderstanding some aspect of the datasheet, rather than simply having put the resistor lead in the wrong hole.

(I'm happy to share schematics etc, if of interest, but this is solved. For anyone interested in the purpose of the device, it's to make a high speed 'binary clock' for aligning multiple photos in time, used for tracking bees. more details here: http://michaeltsmith.org.uk/ ).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.