SN74HC165N with SPI.h

I’m trying to extend the number of pins for Due using SN74HC165N shift registers. I managed to get it to work with my Leonardo but when I’m uploading the same sketch to my due and connecting my due in exactly the same way I connected it to my Leonardo (Using SPI header on due instead of ICSP on like on Leonardo as per instructions here Arduino - SPI) it doesn’t work. Due will occasionally just print that all the pins have been closed, or open at once, and won’t react at all to me closing the digital pins of the shift register. Often I even see Serial printed halfway for example something like “Switch 1 opSwitch 2 Open” and “Begin switch test” which suppose to be printed only on setup getting printed every time when I will open the monitor.

This is the demo sketch I’m using for both:

// Demo sketch to read from a 74HC165 input shift register
// Author: Nick Gammon
// Date:   23 March 2013

// Pin connections for Uno and similar:

// Chip pin 1 (/PL)  goes to LATCH (D9)  (or any other pin by changing LATCH below)
// Chip pin 2 (CP)   goes to SCK   (D13)
// Chip pin 9 (Q7)   goes to MISO  (D12)

// Pin connections for Mega2560:

// Chip pin 1 (/PL)  goes to LATCH (D9)  (or any other pin by changing LATCH below)
// Chip pin 2 (CP)   goes to SCK   (D52)
// Chip pin 9 (Q7)   goes to MISO  (D50)


#include <SPI.h>

const byte LATCH = 0;

void setup ()
{
  SPI.begin ();
  Serial.begin (115200);
  Serial.println ("Begin switch test.");
  pinMode (LATCH, OUTPUT);
  digitalWrite (LATCH, HIGH);
}  // end of setup

byte optionSwitch;
byte oldOptionSwitch; // previous state

void loop ()
{ 
  digitalWrite (LATCH, LOW);    // pulse the parallel load latch
  digitalWrite (LATCH, HIGH);
  optionSwitch = SPI.transfer (0);
  
  byte mask = 1;
  for (int i = 1; i <= 8; i++)
    {
    if ((optionSwitch & mask) != (oldOptionSwitch & mask))
      {
      Serial.print ("Switch ");
      Serial.print (i);
      Serial.print (" now ");
      Serial.println ((optionSwitch & mask) ? "closed" : "open");
      }  // end of bit has changed
    mask <<= 1;  
    }  // end of for each bit
  oldOptionSwitch = optionSwitch;
  delay (10);   // debounce
}  // end of loop

And the way I’m connecting my Due to shift register:

Due → SN74HC165N
Digital 0 (LATCH) → 1 (PL)
SPI MISO → 9 (Q7)
SPI SCK → 2 (CP)
SPI MOSI → 15 (CE)
SPI 5v → 16 (VCC)
SPI GND → 8 (GND)

I would really appreciate any help. I’m building a game controller/airplane panel for flight simulator and got all working with my Leonardo, unfortunately, I’m running out of memory on it so I thought I gonna move to Due.