Go Down

Topic: Need shiftIn Bug-fix Tested on CD4021B PISO Shift Register (Read 10483 times) previous topic - next topic

Rockfish

I was having a problem with the included shiftIn function while trying to use a 74HC165 PISO. I've found the solution, but am unsure if I just broke compatibility with the CD4021 PISO. Does anyone have a minute to test this, and respond?

The function in question (just use this function rather than shiftIn)

Code: [Select]
uint8_t fixedShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
uint8_t value = 0;
uint8_t i;

for (i = 0; i < 8; ++i) {
digitalWrite(clockPin, LOW);
if (bitOrder == LSBFIRST)
value |= digitalRead(dataPin) << i;
else
value |= digitalRead(dataPin) << (7 - i);
digitalWrite(clockPin, HIGH);
}
return value;
}

bperrybap

#1
Nov 11, 2013, 06:23 am Last Edit: Nov 11, 2013, 07:06 am by bperrybap Reason: 1
why do you need to do this?
Isn't this about the same issue as this:
https://groups.google.com/a/arduino.cc/forum/#!topic/developers/H8xhxLtyz8c

Why wouldn't you:
- set the clock pin to HIGH
-  pulse the parallel load pin
- call the normal shiftin()

The 165 clocks/shifts on a rising edge.
The initial set to HIGH in the original routine would do nothing
just like the initial set to LOW would do nothing in the modified routine.

And then the next time around in the original version, the set to HIGH
would shift the data.

--- bill


ackbar345

OK I just tested this on my CD4021B as I've been having problems with the built-in ShiftIn function (running 1.0.5) dropping a bit. Seems to work ok, just remember to pulse the latch before you call it. Thanks for the fix!

Go Up