1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

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

Discussion in 'Arduino' started by fezder, Apr 14, 2017.

  1. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    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)
    Code (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:
    http://www.ti.com/lit/ds/symlink/sn74165.pdf
    Anyone willing to test this?
     
  2. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,792
    Likes:
    134
    Location:
    morristown,tn
    This may help you

    [​IMG]
     
    Last edited: Apr 14, 2017
    • Thanks Thanks x 1
  3. BobW

    BobW Active Member

    Joined:
    Apr 28, 2010
    Messages:
    501
    Likes:
    52
    Location:
    Canada
    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 Thanks x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland

    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?.
     
  6. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Yes, that did the trick, thanks BobW !. Here's final, working code. :)
    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();


    }
     
  7. BobW

    BobW Active Member

    Joined:
    Apr 28, 2010
    Messages:
    501
    Likes:
    52
    Location:
    Canada
    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.
     

Share This Page