Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aleksas
Last active September 12, 2020 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleksas/b743c11e98656aee1d572aba73c9bf65 to your computer and use it in GitHub Desktop.
Save aleksas/b743c11e98656aee1d572aba73c9bf65 to your computer and use it in GitHub Desktop.
Simplified Dual Channel Read in auto mode (default) p. 14.

Read 16 bit value using TI ADS8330 via Arduino Due

Based on ADS8319 sketch for reading 16 bit adc value using Arduino Uno. Adapted according to ADS8329/ADS8330 datashhet Simplified Dual Channel Read in auto mode (default) on page 14.

To use wit other Arduinos not having SPI.transfer16 function, please reference ADS8319 sketch for reading 16 bits in two 8 bit reading steps.

// BY: yiipmann
// SOURCE: https://arduino.stackexchange.com/questions/17296/interfacing-ads8319-with-arduino-uno
#include <SPI.h>
#define CONVPIN 7
#define SELPIN 8
#define SELPIN2 4
#define MISOPIN 12
#define SCLKPIN 13
int adcvalue;
byte byte1; byte byte2;
const float aRefVoltage = 5;
float volts = 0;
void setup() {
// put your setup code here, to run once:
pinMode(SELPIN, OUTPUT); // ADC's selection pin
pinMode(SELPIN2, OUTPUT); // 2nd ADC's selection pin
pinMode(CONVPIN, OUTPUT); // ADC's conversion pin
pinMode(SCLKPIN, OUTPUT); // ADC's clock pin
pinMode(MISOPIN, INPUT); // ADC's data out
SPI.begin();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(CONVPIN, LOW);
digitalWrite(SELPIN, HIGH);
digitalWrite(SELPIN2, HIGH);
digitalWrite(CONVPIN, HIGH);
digitalWrite(SELPIN, LOW);
delay(1000);
byte1 = SPI.transfer(0x00); //transfer (read) 8 bits from the adc chip D15-8
byte2 = SPI.transfer(0x00); //transfer (read) the second 8 bits. D7-0
adcvalue = (byte1 <<8) | (byte2 & 0xff); // combine the 2 bytes to make our 16 bit word
Serial.print("Voltage Value: ");
Serial.println(adcvalue,BIN);
volts = (adcvalue*aRefVoltage/65535);
Serial.print(" Sensor Volts: ");
Serial.println(volts,5);
delay(1000);
}
// Based on: https://arduino.stackexchange.com/questions/17296/interfacing-ads8319-with-arduino-uno
// Modified according to "Figure 6. Simplified Dual Channel Timing" (https://www.ti.com/lit/ds/symlink/ads8330.pdf)
#include <SPI.h>
#define CONVPIN 3 // ADC's conversion pin
#define SELPIN 2 // ADC's selection pin
uint16_t ch0_value, ch1_value;
const float referecnce_voltage = 3.3f;
float ch0_volts, ch1_volts;
void setup() {
pinMode(SELPIN, OUTPUT);
pinMode(CONVPIN, OUTPUT);
SPI.begin();
Serial.begin(9600);
}
void loop() {
// READ CH0
digitalWrite(SELPIN, LOW);
digitalWrite(CONVPIN, LOW);
ch0_value = SPI.transfer16(0x0000);
digitalWrite(CONVPIN, HIGH);
digitalWrite(SELPIN, HIGH);
// READ CH1
digitalWrite(SELPIN, LOW);
digitalWrite(CONVPIN, LOW);
ch1_value = SPI.transfer16(0x0000);
digitalWrite(CONVPIN, HIGH);
digitalWrite(SELPIN, HIGH);
// ---------------------
ch0_volts = ch0_value * referecnce_voltage / UINT16_MAX;
ch1_volts = ch1_value * referecnce_voltage / UINT16_MAX;
Serial.println(ch0_volts, 5);
Serial.println(ch1_volts, 5);
Serial.println();
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment