A
Arduino•15h ago
Onigiri_Cloud

Need help optimizing 74hc595 updates

Hi i need a way to make my 595 update faster currently it takes about 750 to 850 ms for 8bytes (8bits per iteration) to transfer using shiftout neeh help with to either make shiftout faster or update 595 over spi
23 Replies
Onigiri_Cloud
Onigiri_CloudOP•15h ago
board: pro micro with atmega32u4
AnonEngineering
AnonEngineering•15h ago
might be a code issue, Googling indicates shiftOut takes about 150 us (on a much slower Uno)
Onigiri_Cloud
Onigiri_CloudOP•15h ago
i am assuming u talking about per byte i am doing this 8 times per loop so it gets little high like 8 times that
AnonEngineering
AnonEngineering•15h ago
8 x 150 us is still only about a millisecond
Onigiri_Cloud
Onigiri_CloudOP•15h ago
well i still require it being faster the delay of that adds up with other things making it like 3 miliseconds which is lot! and shift out adds the most of it to whole runtime
AnonEngineering
AnonEngineering•15h ago
800 seemed long, 3 ms I can picture 🙂
Onigiri_Cloud
Onigiri_CloudOP•15h ago
so.... any idea how to make it faster?
AnonEngineering
AnonEngineering•15h ago
apparently folks have gained some speed driving the 595 with SPI, I haven't ever done it myself
Onigiri_Cloud
Onigiri_CloudOP•15h ago
that seemed to be the most obvious answer but it's not working 595 output pins act kinda when i do spi and i am not sure if am doing it right or some bug? cause work fine with shiftout
#include <SPI.h>

const int latchPin = 14;

void setup() {
pinMode(latchPin, OUTPUT);
digitalWrite(latchPin, LOW);

SPI.begin();
}

void loop() {

sendToShiftRegister(0b10101010);
delay(500);
sendToShiftRegister(0b01010101);
delay(500);
}

// Function to send one byte to the 74HC595 via SPI
void sendToShiftRegister(uint8_t data) {
digitalWrite(latchPin, LOW);
SPI.transfer(data); digitalWrite(latchPin, HIGH);
}
#include <SPI.h>

const int latchPin = 14;

void setup() {
pinMode(latchPin, OUTPUT);
digitalWrite(latchPin, LOW);

SPI.begin();
}

void loop() {

sendToShiftRegister(0b10101010);
delay(500);
sendToShiftRegister(0b01010101);
delay(500);
}

// Function to send one byte to the 74HC595 via SPI
void sendToShiftRegister(uint8_t data) {
digitalWrite(latchPin, LOW);
SPI.transfer(data); digitalWrite(latchPin, HIGH);
}
this is what i did
pseud0
pseud0•15h ago
How did you connect each pin?
No description
Onigiri_Cloud
Onigiri_CloudOP•14h ago
VCC to vcc SER to arduino 16 as data OE to ground RCLK to 14 as latch SRCLK to 15 as clock SRCLR to VCC
No description
pseud0
pseud0•14h ago
And what about pins like master reset
AnonEngineering
AnonEngineering•14h ago
isn't that SRCLR?
pseud0
pseud0•14h ago
oh right that's your serial clear. GND to GNd technically.
Onigiri_Cloud
Onigiri_CloudOP•14h ago
it is the same wait going to try the same code again
AnonEngineering
AnonEngineering•14h ago
yeah, i just changed the latch pin
Onigiri_Cloud
Onigiri_CloudOP•14h ago
i think... it got updated once or twice not sure... it's on 0b01010101
AnonEngineering
AnonEngineering•14h ago
in other words your real life circuit isn't like the sim?
Onigiri_Cloud
Onigiri_CloudOP•14h ago
void loop() {

sendToShiftRegister(0b10101010);
Serial.println("0b10101010");
delay(1000);
sendToShiftRegister(0b01010101);
Serial.println("0b01010101");
delay(1000);
}
void loop() {

sendToShiftRegister(0b10101010);
Serial.println("0b10101010");
delay(1000);
sendToShiftRegister(0b01010101);
Serial.println("0b01010101");
delay(1000);
}
yea can say that too also installed the spark fun promicro board defination just to make sure it wasn't the cause of issue
AnonEngineering
AnonEngineering•14h ago
how about not using 14 for latch (it's MISO)
Onigiri_Cloud
Onigiri_CloudOP•13h ago
it has pinMode(latchPin, OUTPUT); think that disables 14 as miso? but yea will try that wow that fixed it! so turns out... this not true thanks for all the help! so i might have lost my last digital io pin but spi works! didn't have any plans of using that as for now so.. guess its fine?
AnonEngineering
AnonEngineering•12h ago
so it was using MISO as latch that was slowing it down?

Did you find this page helpful?