I am trying to read data from an ADC ADCS7476 (datasheet) using SPI on Arduino Uno. I am using the following code to read the data from the ADC and printing it on serial monitor. However, the code is always printing 0. I never used SPI before and I am not able to debug the issue, does anyone know where I am going wrong.
I am using the following connections:
- ADC's SCLK to Pin 13 on Ardunio
- ADC's SDATA to Pin 12 on Arduino
- ADC's CS to Pin 10 on Arduino
Code:
# include#include <SPI.h>
# define#define cs 10
SPISettings settingsA(250000, MSBFIRST, SPI_MODE0);
byte highbyte,lowbyte;
unsigned int data;
void setup() {
Serial.begin(9600);
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH);
delay(1000);
SPI.begin();
}
void loop() {
SPI.beginTransaction(settingsA);
digitalWrite(cs, LOW);
delayMicroseconds(1);
highbyte = SPI.transfer(0xFF);
lowbyte = SPI.transfer(0xFF);
digitalWrite(cs, HIGH);
delayMicroseconds(1);
SPI.endTransaction();
data= ((unsigned int)highbyte << 8 ) + lowbyte;
Serial.println(data);
delay(100);
}