I have completed Example 1 of this tutorial:
and I have some questions about shift registers and the arduino's shiftIn function.
This is my shift register:
The tutorial code uses a custom shiftIn function instead of the shiftIn function that is a part of the Arduino language:
I wanted to understand why so I modified the tutorial code to call the other function:
switchVar1 = shiftIn(dataPin, clockPin, MSBFIRST);
Much to my surprise, the circuit no longer worked correctly. For most of the buttons the bits were shifted over one.
I found the source code to Arduino's shiftIn function here:
After doing some experimenting, I found I had to invert the writes to the clockPin, flipping HIGH and LOW. Then it worked.
I believe this has something to do with the shift register doing the serial shifting on either the rising and falling clock edges. Arduino's shiftIn function expects it to be done one way, but this shift register does it the other way. That's why it was necessary for the tutorial to use a custom shiftIn function.
I have some questions.
The Arduino documentation says:
If you're interfacing with a device that's clocked by rising edges, you'll need to make sure that the clock pin is low before the first call to shiftIn(), e.g. with a call to digitalWrite(clockPin, LOW).
I tried doing that but I still couldn't get it to work correctly using the built-in shiftIn function. Is it possible to do that, or am I misunderstanding something?
Where in the product datasheet does it tell me that this won't work with the built-in shiftIn function? What is the proper terminology to describe this?
The tutorial includes a delay after setting the clockPin low.
Taking that out didn't do anything. Is it necessary? Does it have something to do with the Clock Risk and Fall Time, as documented on the second page of the datasheet?
And what else can I do to learn more about shift registers here?