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 <SPI.h>
#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);
}
#include
and#define
having a space (but since the compiler does not complain I think it is just a wrong copy-paste), I can't see anything obviously wrong. So, just for the most basic questions, 1) is the circuit powered? 2) does the ADC have its own power supply or you are powering it from the arduino 5V? 3) if the former, did you connect th two grounds? 4) is the adc powered at 5V? 5) Can you attach an oscilloscope to the data and clock lines to see what is on the bus?