(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
byte PISOreceivedData;

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.print(digitalRead(PISOdata));
  }
  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:
**broken link removed**
Anyone willing to test this?
 
This may help you


 
Last edited:
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.
 
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, https://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?.
 
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
byte PISOreceivedData;

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.print(digitalRead(PISOdata));
  }
  Serial.println();


}
 
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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…