Problem to read TLC3548 ADC with SPI

I am working with TLC3548CDW. I have a problem reading analog channels of ADC. I attached signals and code. Right now I am reading only one channel, but I got the same data and it's not changing.
datasheet link of TLC3548CDW: https://www.ti.com/lit/ds/symlink/tlc3548.pdf?ts=1646236295165

VCC=+5 V

Ref. vol. = +5V

FS,CSTART = +5V

In the image, Ch1 is SCLK, Ch2 is MISO, Ch3 is MOSI, Ch4 is CS.

Thank you

#include <SPI.h>
#include <string.h>

/*Pin */
#define DATAOUT 11//COPI
#define DATAIN 12//CIPO
#define SPICLOCK 13//sck
#define TEMP_INT_READ 3

#define CHIPSELECT1 10//cs
#define CHIPSELECT2 8 //cs
#define CHIPSELECT3 7 //cs

#define MAX_VREF_VOLT (5000U)
#define MIN_VREF_VOLT (0U)
#define MAX_VALUE_IN_14BIT (16384U)
#define BIT_PER_MVOLT (MAX_VALUE_IN_14BIT/MAX_VREF_VOLT)

#define ADC_CH0 (0x00)
#define ADC_CH1 (0x01)
#define ADC_CH2 (0x02)
#define ADC_CH3 (0x03)
#define ADC_CH4 (0x04)
#define ADC_CH5 (0x05)
#define ADC_CH6 (0x06)
#define ADC_CH7 (0x07)
#define ADC_CH8 (0x08)

#define SENSORE_1 (0) //temp /CHIPSELECT1
#define SENSORE_2 (1) //CHIPSELECT2

unsigned int readRegister(int ,byte) ;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("TESTSETUP");
// start the SPI library:
SPI.begin();

pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(TEMP_INT_READ,INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT1,OUTPUT);
pinMode(CHIPSELECT2,OUTPUT);
pinMode(CHIPSELECT3,OUTPUT);

//readRegister(0, 0x00);
digitalWrite(CHIPSELECT1,HIGH); //disable device
digitalWrite(CHIPSELECT2,HIGH); //disable device
digitalWrite(CHIPSELECT3,HIGH); //disable device
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
}

int Value;
int pinstatus;
void loop() {
// put your main code here, to run repeatedly:

Value = readRegister(0,0x01);
Serial.println(Value);
delay(5);
pinstatus=digitalRead(TEMP_INT_READ);
Serial.println(pinstatus);
delay(100);

}

//Prototypes********
/void user_printf(const char format)
{
char Buff[100]={0};
va_list argptr;
\va_start(argptr, format);
\vsnprintf (Buff,100, format, argptr);
\va_end(argptr);
Serial.println(Buff);
}*/

//0000 0111 0000 0000
//0x0700
unsigned int readRegister(int sensore,byte channelnumber)
{
byte inByte = 0; // incoming byte from the SPI
unsigned char wData[2]={B00001111,B10000000};
unsigned char rData[2]={0};
unsigned int result = 0; // result to return

// user_printf("%d -> channel_number:%d",sensore,channelnumber);

// Serial.print("\t");

wData[0]=0x07|(channelnumber<<4);
wData[1]=0x00;

if(sensore == 1)
{
digitalWrite(CHIPSELECT2, LOW);
}
else
{
digitalWrite(CHIPSELECT1, LOW);
}

rData[0]=SPI.transfer(wData[0]);
rData[1]=SPI.transfer(wData[1]);

if(sensore == 1)
{
digitalWrite(CHIPSELECT2, HIGH);
}
else
{
digitalWrite(CHIPSELECT1, HIGH);
}
Serial.println(rData[0]);
Serial.println(wData[1]);

result=0x00|(rData[0]<<8)|(rData[1]<<0);

return (result);
}


You must not touch the SPI pins yourself once you called SPI. begin()!

What type of Arduino are we talking about? Remember, if you don't specify another type explicitly we always assume the most used one (UNO). The UNO won't be able to reach 14 MHz on SPI. None of the 5V types will that. So I guess you have a dilemma.

BTW, where's the wiring diagram?

And the SPI mode is 1 according to the datasheet.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.