SPI code to daisy chain HC595 chips

Posted on
  • Hello,
    I have daisy chained two HC959 ICs together and wired them up to 16 LEDs. The code below produces a Nightriders effect with the LEDs running up and down. Everything is working well but I must be doing something wrong as the LED 8 above or below the lit one very quickly flashes on too. This would be coming from the other IC so I think the issuebut not sure how to fix it?

    SPI1.setup({ mosi:B5, sck:B3 });
    var i = 2,
          dir = true;
    function loop() {
      if(dir) {
          i = i<<1;
      else {
          i= i>>1;
      // Change direction
      if(i >= 25536 || i <= 2) {
          dir = !dir;
    setInterval(loop, 60);
  • 959? Do you mean 595?

    How do you have them wired? If you mean 595s, review the description of the two clock pins. The led is flashing between the two spi.send()s, I'll wager. I think the way to fix is to put the latch clock on a different gpio pin and pulse it high after you send the two bytes to it, then it will only latch the data in the shift register once it has all the data.

    Also, why two spi.send?
    Why not spi.send([i>>8,i],b8)?

  • As @DrAzzy says, try spi.send([i>>8,i],B8). Doing two sends will pulse b8 low twice, which may make the flicker... If you send both at once then you only get a single pulse, and hopefully no flicker

  • Yes sorry I meant 595. That code worked perfectly, thanks. I didn't think I was meant to be doing two spi.send() commands but didn't know you could pass an array into it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

SPI code to daisy chain HC595 chips

Posted by Avatar for Owen @Owen