by default bit shifted shift registers

Discussion in 'Arduino IDE' started by alexandros301, May 2, 2014.

  1. alexandros301

    alexandros301 Member

    Joined:
    Mar 22, 2014
    Messages:
    40
    Likes Received:
    0
    I'm trying to get some input in Pure Data from Arduino with two shift registers that read 16 switches in total. I get the following strange results: it looks like the bytes I'm receiving are bit shifted by one and kind of wrapped up. What I mean is that the 1st switch is expressed in the second bit of the first byte, the 2nd switch is expressed in the third bit of the first byte etc. The last switch of the second chip wraps up and is expressed in the first bit of the first byte. But the last switch of the first chip isn't expressed anywhere (could be that it would overflow the first byte and control the first bit of the second byte), resulting in (almost) nothing affecting the first bit of the second byte.

    If I use only one shift register in the code, but have both chips wired on the breadboard, more or less the same behavior occurs, only this time the switches of the second chip do nothing except from the very last switch which is again expressed in the first bit of the byte (which now is the first and only byte)!
    One last weird thing that happens when I use both chips is that although there's no switch to be expressed in the first bit of the second byte, there seems to be some short circuit between the first and last switch of the second chip and if the last switch is on, when the first switch turns on, the first bit of the (second) byte is affected as well.

    I tried to explain this as good as I can, I know it's a bit confusing, but it's very confusing to me too. I changed the shift register chips to make sure there was nothing wrong with the chips and exactly the same thing happens. I also checked my circuit on the breadboard and there's no short circuit there. I'm using 10k pullup resistors for the switches as I always do with switches in Arduino (never used a Due before though).
    Here's the code I use, in case it helps
    Code:
    #include <SPI.h>
    
    const byte buttonLatch = 9;
    const byte numOfButChips = 2; // This is the only modification needed if number of button chips used is changed
    
    byte butArray[numOfButChips + 1];
    
    void setup()
    {
      SPI.begin();
      Serial.begin(115200);
      pinMode(buttonLatch, OUTPUT);
      digitalWrite(buttonLatch, HIGH);
    }
    
    void loop ()
    {
      butArray[0] = 0xc0;
      int index = 1;
      digitalWrite (buttonLatch, LOW);    // pulse the parallel load latch
      digitalWrite (buttonLatch, HIGH);
      for(int i = 0; i < numOfButChips; i++)
        butArray[index++] = SPI.transfer(0);
      Serial.write(butArray, numOfButChips + 1);
      
      delay (10);   // debounce
    }  // end of loop
    Anyone experienced something similar?
     
  2. alexandros301

    alexandros301 Member

    Joined:
    Mar 22, 2014
    Messages:
    40
    Likes Received:
    0
    Just checked the very same circuit intact with an Arduino Uno on my laptop and it's working fine. So it must be some issue with Udoo.
     

Share This Page