Trouble reading SN74HC165N Shift register


hello,

i having trouble getting texas instuments sn74hc165n  8-bit parallel-load shift registers expect.
this one: http://www.ti.com/product/sn74hc165/samplebuy?keymatch=sn74hc165n&tisearch=search-en

eventually want use 2 of them read value of 12 bit counter, frist, because if have learn, i'd see work in simpelest form.

i hoping can point out im doing wrong.

see below code , schema, in essence, here im trying:
connect following pins arduino
- clk, sh/_pl,  qh
connect following pins 5v
- vcc, a
connect other pins ground
- b, c, d, e, f, g, h, _qh, ser

i expect read "1" instead "2".
if connect b 5v, expect read 2 4
if connect c 5v, expect read 4 8
this continues pin g reading 128 instead of 64 , pin h reading 0.

i have both arduino uno , arduino due. on the due gets right first time (after hardware reset).

im getting pretty desperate here, searched forum , google. have 4 of these shift registers, tried them , give same results.

code: [select]
const int clk = 8;    // sn74hc165n pin 2, clk
const int data = 12;   // sn74hc165n pin 9, qh
const int lock = 13;   // sn74hc165n pin 1, sh/ld
// sn74hc165n clk inh connected gnd
// sn74hc165n h connected gnd or vdd, see question
// sn74hc165n _qh, connected gnd
// sn74hc165n ser, connected gnd

void setup()
{
  pinmode(clk, output); 
  pinmode(data, input);   
  pinmode(lock, output); 

  serial.begin(115200);
}

void loop()
{
  // lock parallel input
  digitalwrite(lock, high);
 
  // read
  byte b = shiftin(data, clk, msbfirst);
  serial.println(b);

  // re-enable parallel input
  digitalwrite(lock, low);

  delay(2000);
}



oh, tried clocking manually, this
code: [select]
void loop()
{
  digitalwrite(lock, high);
  byte val = 0;
  for(int = 0; < 8; i++)
  {
    digitalwrite(clk, high);
    delay(5);
    val |= digitalread(data) << (7 - i);
    digitalwrite(clk, low);
  }   
  digitalwrite(lock, low);
  serial.println(val);
  delay(2000);
}


same results, gets right first time on due, after hardware reset. on uno wrong every time.


Arduino Forum > Using Arduino > Sensors > Trouble reading SN74HC165N Shift register


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support