Hello, I am working with PCA9701/PCA9702, these are 16 bit and 8 bit GPI shift registers for adding extra ports, these work with SPI, I come to this forum to get advice and help as I am not sure if I am understanding how does this work, the data sheet says that it takes CS low, then serial clock and SDIN, to read the input ports, I am using a basic routine using SPI library for reading the PCA9702 however, I do not know which data to send on SDIN, if I send 0xFF I get the same at SDOUT, I hope you can give me some pointers, here is my code
#include <SPI.h>
byte receivedVal;
void setup() {
//Serial.begin(); //Serial Monitor is eanbled
SPI.setDataMode( SPI_MODE1 ) ;
SPI.begin();
Serial.begin(9600);
Serial.setTimeout(50);
}
void loop() {
//Set up the two commands to be sent
byte myData[] = { 0xFF } ; //8-bit command/data
digitalWrite(SS, LOW); //CS/ of chip is made LOW for data communication
delayMicroseconds(100); //for stabilization (optional)
//----------------------
SPI.transfer(myData, sizeof(myData)); //data for SDIN so shift register can shift
receivedVal = SPI.transfer(0x00); //read data on SDOUT
delayMicroseconds(100); //for stabilization (optional)
digitalWrite(SS, HIGH); //data is latched at output at rising edge of CS/
delayMicroseconds(100); //for stabilization
//----------------------
Serial.println(receivedVal); //display data read
}
however, I only see 256 on the output
this is the Arduino to PCA9702 connection
I am applying 12 Vdc to the input IN0, using 5Vdc supply on PCA9702 as datasheet says it can take up to 5.5Vdc
can you tell me if this code is correct ?