SN74HC165N Shift-in

I'm getting some strange data from the SN74HC165N with both this code and this code, I have one switch for the SN74HC165N to read for the moment and is wired:

This is the pin designation:
int ploadPin = 8; // Connects to Parallel load pin the 165
int clockEnablePin = 9; // Connects to Clock Enable pin the 165
int dataPin = 11; // Connects to the Q7 pin the 165
int clockPin = 12; // Connects to the Clock pin the 165

I'd expect to see the data on D5 to change on flicking the switch but each time it reads the shift register it reads different values as if there are 8 switches and being randomly flicked, does anyone know what the issue could be? I've found people have used 10k or 4.7k resistors, would it be worthing trying a 4.7k? I don't have any so I'll get some if it's worth trying.

Thanks

Yes, you've got it, you have floating inputs, not good.
Pull-up or pull-down to a known (default) state.

You already have a 10k pulldown resistor on D5. Changing it to 4k7 isn't going to make any difference. The other 7 inputs are floating, so expect to see random values for them. If you ground D0-D4 and D6-7, what readings do you get?

You should also include a small decoupling capacitor on VCC of the 165. 0.1uF Ceramic.

Thanks guys, in my ignorance I thought I'd simplify the test by only using one switch which gave me floaters!

James, will do :slight_smile:

The rule with CMOS logic is no floating inputs (this causes various problems and can lead to continuous conduction through the gates' output stages). If you are designing a battery powered circuit using CMOS logic (for low power) then it really matters. The supply current to this shift register might be a few nanoamps in normal use, but with a floating input might rise by a factor of millions to many milliamps (flattening your battery in hours). In the case of an Arduino you would have to be using sleep mode and battery power for it to matter, but I'd still eliminate the problem, its poor design to allow floating inputs.

For CMOS connect floating inputs directly to GND or +5V as appropriate it not sending signals through them, otherwise pull-up or pull-downs may be useful (say the input is driven from an external device that isn't always connected, then a pullup or pulldown will stop it floating when not connected).

Sometimes a device has pins that can be inputs or outputs (sometimes called "tristate") - you can simply configure then as outputs to avoid floating inputs. (usually there is an output-enable pin, often called OE - always read the datasheet for details!) The 74HC165 isn't amenable to this fix though.

Funny I remember "Ground all unused inputs" being on the first page of nearly all CMOS and TTL datasheets!

For TTL its less important (a floating input in TTL was always HIGH, but somewhat sensitive to nearby noise - an unused input could be tied to ground or pulled-up with a resistor to +5V (shorting to +5V would damage a TTL input) - if it didn't matter what the input was you saved a resistor by tying to ground.

For CMOS you tie to either ground or Vdd, no resistors needed.

Does anyone see there being a problem with a shift-out and shift-in run from the same Arduino?

Both circuits are physically connected to the Arduino, both sketches work individually on my setup, when I run the shift-in code only I see the byte(s) being received with the serial monitor, when I run the shift-out code only I see the byte(s) being written out with the serial monitor, when I run both lots of code I see the shift-in code seeing the inputs have changed and the byte(s) being sent out through the shift-out code but the LEDs don't fire correctly, they seem to come on when the input switch is off but I have to toggle it off-on-off for the LED to fire

I'll upload a photo and some code if it helps.

You can even use the same SCK and SCL lines, a seperate latch enable and parallel load. The output from the shiftIn and the Input for the shiftOut would need to go through a bidir line reciever such as a 74LS244. The purpose of this is to prevent the HC165 from trying to sieze the dataline while the micro was writing.

Is this the case if I'm using different pins? The shiftIn uses pins 8, 9, 11 and 12, the shiftOut uses 2, 3 and 4, the main loop polls the shiftIn for data change, when it sees a change it delays for 100ms then sends the data to the shiftOut then pauses for another 100ms, would the delays be a work-around?

If I need to use a 74LS244 would I have to run both the shiftIn and shiftOut through it or can I use it for either the shiftIn or shiftOut? The reason I ask is the finished product may have a shiftIn or a shiftOut or both so I'd like to code/build it in a way that suits all situations.

Are there any code examples to interact with the 74LS244 or would I not need any code?

Cheers

My post was to say you could build a serial buss, the stipulation is the 74HC165N can'y be allowed to connect to the serial data line while another device was writing to it. ShiftIn and Shift out are not hardware features and are facilitated in software, one call has to finish before another can begin. The serialto parallell register could loopout while the parallel to serial register was emtying, if the data was valid then send the latch data signal to the serial to parallel register, if it was a garbage byte then send a master clear. Although by queing the byte(s) you could perform Big Endian to little Endian translation. that is if 2 devices required a mirrored bit order.

My last post failed, it had the datasheet. apparently the upload folder is full.

ajofscott:
My last post failed, it had the datasheet. apparently the upload folder is full.

Is this what you were posting? http://www.learn-c.com/74ls244.pdf

This is the pin layout

for the shiftIn would I wire it:
8 trigger switches --> 8 input pins on the 74AHC244 --> 8 output pins on the 74AHC244 --> 8 input pins on the HC165 --> data pin to Arduino

shiftOut:
data pin on Arduino --> 1 74AHC244 input pin --> 1 74AHC244 output pin --> HC595 data in PIN --> 8 HC595 output pins --> 8 LEDs

Thanks in advance