Help with CS5532 AD

Im trying interface the Cirrus Logic AD CS5532 24bit with arduino, but without success. Im working with this for around 2 weeks using arduino mega.

Arduino dont report any problem to send information, but when i try read something, i receve wrong values.

I double checked the connections and solders.

I think the problem is on SCK. I cant set this to 2mhz (16mhz/8).

Any help is welcome.

Without you posting a schematic of what you have and the code you are using how is anyone going to be able to answer your question.
I know ESP.
I see it looks like the red wire isn't connected up right.

ok.. i dont think schematic is important because i only have the CS5532 on SPI ports.

My problem ir reading the registers of CS5532. I need read 8 bits of one register and 32bits of other.

On my last try i use this code:

 //All constants on this code have 8bits

 //void Setup()
 SPI.begin();
 SPI.setClockDivider(SPI_CLOCK_DIV8); 

 //to send 32bits to Configuration Register
  SPI.transfer(COMMAND_CONFIGREG); 
  SPI.transfer(CONFIGREG11);
  SPI.transfer(CONFIGREG12);
  SPI.transfer(CONFIGREG13);
  SPI.transfer(CONFIGREG14);

//to read 32bits of Configuration Register

  CONF_TMP0 = SPI.transfer(COMMAND_READCONF);
  CONF_TMP1 = SPI.transfer(0x00);
  CONF_TMP2 = SPI.transfer(0x00);
  CONF_TMP3 = SPI.transfer(0x00);

with this .. the SPI returns sometimes 0b1111111 sometimes 0b0..

obs: i already have fixed de SPI setClockDivider function and defined all arduino mega spi pins on SPI.cpp

So where is the rest of the code?

Points to note:-

  1. How are you configuring the sip bus for example:-
    Spi.mode((1<<CPOL) | (1 << CPHA)); // set SPI mode 3

  2. Your code has SPI.transfer( where as the examples use Spi.transfer(

Here is all the code im using to test the SPI:

#include <SPI.h>


const byte CHANNELREG011 = 0b00110000;     
const byte CHANNELREG012 = 0b01000000;
const byte CHANNELREG013 = 0b00000000;
const byte CHANNELREG014 = 0b00000000;

const byte CHANNELREG021 = 0b01110000;     
const byte CHANNELREG022 = 0b01000000;
const byte CHANNELREG023 = 0b00000000;
const byte CHANNELREG024 = 0b00000000;

const byte CONFIGREG11 = 0b00000010; 
const byte CONFIGREG12 = 0b00000000; 
const byte CONFIGREG13 = 0b00000000; 
const byte CONFIGREG14 = 0b00000000; 

const byte READ01 = 0b10000000; 
const byte READ02 = 0b10001000; 

const byte CONF_RESET1 = 0b00100000;
const byte CONF_RESET2 = 0b00000000;
const byte CONF_RESET3 = 0b00000000;
const byte CONF_RESET4 = 0b00000000;

const byte COMMAND_CONFGREG = 0b00000011;
const byte COMMAND_CHANNELREG1 = 0b00000101;
const byte COMMAND_CHANNELREG2 = 0b00010101;
const byte COMMAND_READCONF = 0b00001011;


byte CONF_READED = 0;
byte CONF_READED2 = 0;
byte CONF_READED3 = 0;
byte CONF_READED4 = 0;
byte CONF_TMP1 = 0, CONF_TMP2 = 0, CONF_TMP3=0;


void ADreset(){
//digitalWrite(SS,LOW);
for(int i = 0;i<15;i++){
  SPI.transfer(0xFF);}
  
SPI.transfer(0xFE);
delay(50);

  SPI.transfer(COMMAND_CONFGREG);
  SPI.transfer(CONF_RESET1);
  SPI.transfer(CONF_RESET2);
  SPI.transfer(CONF_RESET3);
  SPI.transfer(CONF_RESET4);
  
  SPI.transfer(CONF_RESET2);
  SPI.transfer(CONF_RESET2);
  SPI.transfer(CONF_RESET2);
  SPI.transfer(CONF_RESET2);
  
  SPI.transfer(COMMAND_READCONF);
  CONF_READED2 = SPI.transfer(0x00);
  CONF_TMP1 = SPI.transfer(0x00);
  CONF_TMP2 = SPI.transfer(0x00);
  CONF_TMP3 = SPI.transfer(0x00);

  CONF_READED2 = CONF_READED2 << 8;
  CONF_READED = CONF_READED2 | CONF_TMP1;
  CONF_READED = CONF_READED << 8;
  CONF_READED = CONF_READED | CONF_TMP2;
  CONF_READED = CONF_READED << 8;
  CONF_READED = CONF_READED | CONF_TMP3;
  
  Serial.println(CONF_READED,BIN);
  
  //  CONF_READED = CONF_READED << 8;
 // CONF_READED = CONF_READED | CONF_TMP;
  
//  CONF_READED = CONF_READED << 8;
//  CONF_READED = CONF_READED | CONF_TMP;
//  CONF_TMP = SPI.transfer(0x00);
//  CONF_READED = CONF_READED << 8;
//  CONF_READED = CONF_READED | CONF_TMP; 
  
  
 // digitalWrite(SS,HIGH);
  
}

void ADConfig(){
 // digitalWrite(SS, LOW);
  SPI.transfer(COMMAND_CONFGREG);
  SPI.transfer(CONFIGREG11);
  SPI.transfer(CONFIGREG12);
  SPI.transfer(CONFIGREG13);
  SPI.transfer(CONFIGREG14);
  delay(10);
  
  SPI.transfer(COMMAND_CHANNELREG1);
  SPI.transfer(CHANNELREG011);
  SPI.transfer(CHANNELREG012);
  SPI.transfer(CHANNELREG013);
  SPI.transfer(CHANNELREG014);
  delay(10);
  
  SPI.transfer(COMMAND_CHANNELREG2);
  SPI.transfer(CHANNELREG021);
  SPI.transfer(CHANNELREG022);
  SPI.transfer(CHANNELREG023);
  SPI.transfer(CHANNELREG024);
  delay(10);
 // digitalWrite(SS, HIGH);
 
  
  CONF_READED2 = SPI.transfer(COMMAND_READCONF);
  CONF_TMP1 = SPI.transfer(0x00);
  CONF_TMP2 = SPI.transfer(0x00);
  CONF_TMP3 = SPI.transfer(0x00);
  CONF_READED = CONF_READED2 << 8;
  CONF_READED = CONF_READED | CONF_TMP1;
  CONF_READED = CONF_READED << 8;
  CONF_READED = CONF_READED | CONF_TMP2;
  CONF_READED = CONF_READED << 8;
  CONF_READED = CONF_READED | CONF_TMP3;
 
  Serial.println(CONF_TMP1,BIN);
  Serial.println(CONF_TMP2,BIN);
  Serial.println(CONF_READED,BIN);
}


// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):



void setup() {
  Serial.begin(9600);

  // start the SPI library:
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  SPI.setDataMode(SPI_MODE2); 

  // initalize the  data ready and chip select pins:
  
  

  ADreset();
  ADConfig();
  delay(100);
}

int SerialRead = 0;
int SerialTMP = 0;
int incomingByte = 0;
void loop() {
 
Serial.println("AD CS5532 - Programa de teste ");

Serial.println("Para ler canal AD 01, precione 1 ");
Serial.println("Para ler canal AD 02, precione 2 ");
Serial.println("Para ler REG_CONF, precione 3 ");
while(SerialRead == 0){
  

//Serial.println(SerialTMP);
if (Serial.available() > 0) {            
      SerialRead = Serial.read();
      Serial.print("I received: ");
      Serial.println(SerialRead, DEC);
      }

switch(SerialRead){
  
case 49:
readAD1();
delay(100);
break;

case 50:
readAD2();
delay(100);
break;

case 51:
Serial.println(CONF_READED,BIN);
Serial.println(CONF_READED2,BIN);
break;

}

SerialRead = 0;

}
}




//Read from or write to register from the SCP1000:
unsigned int readAD1() {
  byte inByte = 0;           // incoming byte from the SPI
  unsigned int result = 0;   // result to return
  unsigned int result_blank = 0;   // result to return
  Serial.print("Comando Enviado: ");
  Serial.println(READ01, BIN);


 // digitalWrite(SS, LOW);
  SPI.transfer(READ01);
  // send a value of 0 to read the first byte returned:
  result_blank = SPI.transfer(0x00);
  // decrement the number of bytes left to read:
  result = SPI.transfer(0x00);
  // if you still have another byte to read:
  for(int i = 0;i<2;i++) {
    // shift the first byte left, then get the second byte:
    result = result << 8;
    inByte = SPI.transfer(0x00);
    // combine the byte you just got with the previous one:
    result = result | inByte;
    // decrement the number of bytes left to read:
    }
  // take the chip select high to de-select:
  //digitalWrite(SS, HIGH);
  // return the result:
  Serial.print("Valor recebido: ");
  Serial.println(result,BIN);
 ; 
  return(result);
}

unsigned int readAD2() {
  byte inByte = 0;           // incoming byte from the SPI
  unsigned int result = 0;   // result to return
  unsigned int result_blank = 0;   // result to return
  Serial.print("Comando Enviado: ");
  Serial.println(READ02, BIN);
 
 

//  digitalWrite(SS, LOW);
  SPI.transfer(READ02);
  // send a value of 0 to read the first byte returned:
  result_blank = SPI.transfer(0x00);
  // decement the number of bytes left to read:
  result = SPI.transfer(0x00);
  // if you still have another byte to read:
  for(int i = 0;i<2;i++) {
    // shift the first byte left, then get the second byte:
    result = result << 8;
    inByte = SPI.transfer(0x00);
    // combine the byte you just got with the previous one:
    result = result | inByte;
    // decrement the number of bytes left to read:
    }
  // take the chip select high to de-select:
 //digitalWrite(SS, HIGH);
  // return the result:
  Serial.print("Valor recebido: ");
  Serial.println(result,BIN);
  return(result);
}

i tryed put SPI.SetDataMode and get better results on mode2.

The SS pin i put to low on SPI.cpp, i will use only one chip on spi, so i let it always on

OK. I lost two more nights working on it and get it to work. I redid the code and re-read the CS5532 datasheet.

He works in modo0 and have to send the bytes directly. Or using constants as hex, not binary.

This is my first SPI experience, so i lost much time to learn how to use it.

have to send the bytes directly. Or using constants as hex, not binary.

Hex binary or decimal, they are all the same. It matters not what you use only the bit pattern that you send.
The chip enable must be lowered before you send a package and raised when the whole packet is sent. This is not done by the Spi.transfer call, you must bracket this action between all the transfers you use.