0

Feather M0 Shift register on SPI
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M0 Shift register on SPI

by svdbor on Tue Jan 16, 2018 4:47 pm

All,

I have issues using a shift register (CD4021BE) on the Feather M0. The following code is used:

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
 
#define PIN_SCK          SCK            // SPI clock
#define PIN_MISO         MISO           // SPI data input
#define PIN_MOSI         MOSI           // SPI data output
#define PIN_SS1          10    // SPI hardware default SS pin
 
void setup() {
  Serial.begin(9600);
  SPI.begin();
  pinMode(PIN_SS1, OUTPUT);
}
 
void loop() {
  delay(100);
  digitalWrite(PIN_SS1,LOW);
  // read byte from CD4021 IC
  Serial.println(SPI.transfer(0x00),BIN);
  digitalWrite(PIN_SS1,HIGH);
}


I have 3 buttons connected, and the outputs are as follows (meeting expectations):
button 1: 00000010
button 2: 00001000
button 3: 00010000

and combinations are possible:

button 1 and 2: 00001010
etc.

Running the same code and setup on the Feather M0 will bring the following results:
button 1: 00000001
button 2: 00000111
button 3: 00001111

and combinations are not possible:
button 1 and 2: 00000111

Is the SPI too fast on the M0 to work with this shift register? Does someone experience the same issues and have a solution?

Thanks,
Sander

svdbor
 
Posts: 10
Joined: Tue Oct 31, 2017 4:08 pm

Re: Feather M0 Shift register on SPI

by adafruit_support_mike on Fri Jan 19, 2018 2:21 am

CD4000-series logic is the oldest and slowest, limited to about 2.5MHz when running from a 5v supply. The M0's microcontroller is running almost 20 times that fast, so you probably do need to slow down the signal or move to another logic family.

The corresponding modern chip is the 74*165 parallel-in/serial-out shift register (basically a '595 in reverse). If you're using 48MHz 3.3v logic, the 74LVC165 would be your best choice.. that's the new, 3.3v up-and-coming logic family and is good up to about 150MHz.

adafruit_support_mike
 
Posts: 51988
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather M0 Shift register on SPI

by svdbor on Fri Jan 19, 2018 1:58 pm

Unfortunately the 74LVC165 is not available, and is obsolete on the Digikey website. I was able to get the CD4021 to work by slowing down the SPI to the following settings:

Code: Select all | TOGGLE FULL SIZE
SPI.beginTransaction( SPISettings( 2000000, MSBFIRST, SPI_MODE0 ) );


In the mean time I will keep looking for a direct replacement for the CD4021 and will post it when I find one.

Thanks for your help.

svdbor
 
Posts: 10
Joined: Tue Oct 31, 2017 4:08 pm

Re: Feather M0 Shift register on SPI

by adafruit_support_mike on Sun Jan 21, 2018 3:49 am

Hmm.. looks like they're sticking with the HC logic family:

https://www.digikey.com/products/en/int ... ageSize=25

That's good to 20MHz from a 2V supply, and up to 100MHz from a 5v supply.

Mouser carries the LV family variant:

https://www.mouser.com/Semiconductors/I ... 65&FS=True
which is slightly faster.

adafruit_support_mike
 
Posts: 51988
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.