# (solved)Odd behaviour with 74165 PiSo (paraller in, serial out)

Status
Not open for further replies.

#### fezder

##### Well-Known Member
Right,at first I thought this chip is easy to use. Turns out, something odd is going on here.
I had it correcly hooked in my understandig, but wrong wiring gives me right results! I know....but read on.
first off code, It's small, and used only 3 pins (which is one confusion, I should use clock_inhibit, but I have it hooked on GND)
C:
byte PISOdata = 3; //input from SiPo
byte PISOlatch = 4; //latch for SiPo, LOW=load
byte PISOclk = 5;  //SiPo clock

void setup()
{
pinMode(PISOdata, INPUT);
pinMode(PISOlatch, OUTPUT);
pinMode(PISOclk, OUTPUT);
Serial.begin(9600);
}

void loop()
{
digitalWrite(PISOlatch, LOW);    //load register
digitalWrite(PISOlatch, HIGH); //register at high, to allow reading

for (byte i = 0; i < 8; i++)
{
digitalWrite(PISOclk, LOW);
digitalWrite(PISOclk, HIGH);
}
Serial.println();

}
Now then, the confusion. IF it short serial-in (pin 10) from '165 to gnd, not using it, no matter what I do, I always lose one bit of data.
Then, I figured to start laying "button" signals from lm3914 (used it as knob-controlled button-array of sorts) starting from SERIAL-input pin of '165, and guess what? Now I get all data I want! . But any clues, why not when It was hooked correctly?
datasheed for you:
Anyone willing to test this?

#### be80be

##### Well-Known Member

Its showing all HIGH because the inputs are all high - go measure the voltages on them if you don't believe that statement.
Inputs for TTL must be below 0.8V to guarantee being seen as low.

[ To be less cryptic TTL inputs must be pulled low with about 100 ohm or less. 10k isn't going to affect them much.
You normally wire low inputs directly to GND and high inputs via a 1k resistor to 5V (this is to protect the inputs should the
5V rail go above 5V, inputs have abs max of 5.5V, yet power supply abs max is 7V ]

74165 is a very different beast to 74HC165 - why are you using it? It consumes about as much power as your microcontroller!

Last edited:

#### BobW

##### Active Member
As soon as you latch the parallel signal in, the first bit is immediately available at the serial output. So, you must read it before toggling the serial clock. This is different than many other serial devices that require a clock signal before reading the first bit.

#### fezder

##### Well-Known Member
Thanks for both of you. Circuit for each input is like this, except resistor is 1k. Signal is taken from collector, and signal levels are within threshold values. (not in "gray" area).
https://i.stack.imgur.com/5M7jX.png
To be more specific, here's SN74HC165 (what I have) datasheet, http://www.ti.com/lit/ds/symlink/sn74hc165.pdf
Also, this new datasheet shows more information like application notes and timing requirements.

I see what I can do with code to read one bit before start toggling clock. Didn't think of that! Is this detail mentioned in datasheet somewhere?.

#### fezder

##### Well-Known Member
Yes, that did the trick, thanks BobW !. Here's final, working code.
C:
byte PISOdata = 3; //input from PiSo
byte PISOlatch = 4; //latch for PiSo, LOW=load
byte PISOclk = 5;  //PiSo clock

void setup()
{
pinMode(PISOdata, INPUT);
pinMode(PISOlatch, OUTPUT);
pinMode(PISOclk, OUTPUT);
Serial.begin(9600);
}

void loop()
{
digitalWrite(PISOlatch, LOW);    //load register
digitalWrite(PISOlatch, HIGH); //register at high, to allow reading
Serial.print(digitalRead(PISOdata)); //here's the extra reading you suggested

for (byte i = 0; i < 7; i++) //also changed this from i<8 to i<7 since there was excess 0 at data.
{
digitalWrite(PISOclk, LOW);
digitalWrite(PISOclk, HIGH);
}
Serial.println();

}

#### BobW

##### Active Member
I see what I can do with code to read one bit before start toggling clock. Didn't think of that! Is this detail mentioned in datasheet somewhere?.
The datasheet doesn't point it out specifically, but it's clear from the internal logic diagram that's shown on the datasheet.

The simplest way to deal with this is to put the clock toggle logic at the end of your read loop instead of the beginning.

Status
Not open for further replies.