SPI with ADC7066 (TI Chip)

#include <SPI.h>

 const int CS = 53;
 
  void setup(){ 
  
  pinMode (CS, OUTPUT);
  digitalWrite(CS, HIGH);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);        
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV32);
  Serial.begin(9600);
  delay (100);
  }

void loop() {
writeReg1(0x11,0x06);
  
  delay(5000);
  void writeReg1 (byte Add, byte mask){
    
  byte RD_REG= 0x10;
  byte WR_REG= 0x08;
  byte dummy= 0x00;
 
  digitalWrite(CS, LOW);
  SPI.transfer(RD_REG);
  SPI.transfer(Add);
  SPI.transfer(dummy);
  digitalWrite(CS, HIGH);
  
  digitalWrite(CS, LOW);
  SPI.transfer(dummy);
  SPI.transfer(dummy);
  SPI.transfer(dummy);
  digitalWrite(CS, HIGH);
}

I am trying to read data on CH1 of ADS7066, but getting 0 on Oscilloscope. Any help would be appreciated.

DataSheet: ADS7066 data sheet, product information and support | TI.com

I'm assuming from the const int CS = 53; that this is being done on a Mega. But it really doesn't matter, as the provided sketch doesn't compile.

arduino-cli compile -b arduino:avr:mega:cpu=atmega2560 --warnings all --output-dir /home/me/tmp --no-color (in directory: /home/me/Documents/sketchbook/Mega/test)
/home/me/Documents/sketchbook/Mega/test/test.ino: In function 'void loop()':
/home/me/Documents/sketchbook/Mega/test/test.ino:18:1: error: 'writeReg1' was not declared in this scope
 writeReg1(0x11,0x06);
 ^~~~~~~~~
/home/me/Documents/sketchbook/Mega/test/test.ino:21:39: error: a function-definition is not allowed here before '{' token
   void writeReg1 (byte Add, byte mask){
                                       ^
/home/me/Documents/sketchbook/Mega/test/test.ino:38:1: error: expected '}' at end of input
 }
 ^
Used library Version Path
SPI          1.0     /home/me/.arduino15/packages/arduino/hardware/avr/1.8.3/libraries/SPI
Used platform Version Path
arduino:avr   1.8.3   /home/me/.arduino15/packages/arduino/hardware/avr/1.8.3
Error during build: exit status 1
Compilation failed.

If an oscilloscope shows 0 (no signal/low signal), the signal source is not connected or not sending anything; what is the signal source?

That would not be a problem related to your program.

As indicated, your code does not compile. Because you did not close loop() with a }, void writeReg1 (byte Add, byte mask){ is inside loop() where it should not be. Add a } after the delay(5000).

I'm not familiar with the ADS7066 so can't advise further.

Hi,

Have you tried the code TI suggests? That code is located here.

Hi All,
Apologies for the vague question; I am trying to do SPI communication between ADC7066 and Arduino Mega. I have made few changes in the code.

I am supplying 1V to the code CH1of the ADS7066 from an External Power Supply.

Connection Diagram:
|ADC7066| Uno|

|CS| Digital Pin 53|
|SDI| MOSI (51 )|
|SDO| MISO (50)|
|CLK| CLK (52)|
|5V| 5V|
|AIN1| 2V|

Arduino Code :

#include <SPI.h>


 const int CS = 53;
 
  void setup(){ 
  
  pinMode (CS, OUTPUT);
  digitalWrite(CS, HIGH);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);        
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  Serial.begin(9600);
  delay (100);
  }
void loop() {
byte  voltage0 = readAdc(0);
  
  delay(5000);
  
  
}
 byte readAdc(int channel){

byte RD_REG = 0x10;
byte Add = 0x11;
byte Dummy = 0x00;
digitalWrite(CS, LOW);
SPI.transfer(RD_REG);
SPI.transfer(Add);
SPI.transfer(Dummy);
digitalWrite(CS, HIGH);

digitalWrite(CS, LOW);
byte value = SPI.transfer(Dummy);
SPI.transfer(Dummy);
SPI.transfer(Dummy);
digitalWrite(CS, HIGH);

Serial.println(value, BIN);
  }

Scope Image:

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