keshmaster81
Member
I have some code which reads the raw data inputs from all 8 channels of my ADC simultaneously and writes it to the serial monitor.
This is the datasheet for my ADC:
Right now I don't get any data displayed to the serial monitor. I thought this could be an issue with the external clock I'm using: https://www.digikey.ca/en/products/detail/ecs-inc/ECS-2520MVLC-081-92-CN-TR/16688217. I got this clock generator breakout board and was hoping I could get some help interfacing it with my system, which I think could solve my issue. https://learn.adafruit.com/adafruit-si5351-clock-generator-breakout/wiring-and-test
The clock signal I need to produce for my ADC is 8.192 Mhz.
This is the datasheet for my ADC:
ADS131M08 data sheet, product information and support | TI.com
TI’s ADS131M08 is a 24-bit, 32-kSPS, 8-channel, simultaneous-sampling, delta-sigma ADC. Find parameters, ordering and quality information
www.ti.com
Right now I don't get any data displayed to the serial monitor. I thought this could be an issue with the external clock I'm using: https://www.digikey.ca/en/products/detail/ecs-inc/ECS-2520MVLC-081-92-CN-TR/16688217. I got this clock generator breakout board and was hoping I could get some help interfacing it with my system, which I think could solve my issue. https://learn.adafruit.com/adafruit-si5351-clock-generator-breakout/wiring-and-test
The clock signal I need to produce for my ADC is 8.192 Mhz.
Code:
#include <SPI.h>
// Pin Definitions
const int ADC_DRDY_PIN = 9; // Data Ready Pin, falling edge indicates data is ready
const int ADS131_CS_PIN = 10; // Chip Select for ADS131
const int DEBLED = 14; // Debug LED pin
// Global Settings
const int sdel = 20; // Serial pause time
const int NCH = 8; // Number of ADC channels per chip
const int NDEV = 1; // Number of ADC chips
volatile uint8_t DRDY_FLAG = 0; // Data Ready Flag
// Function Prototypes
void ADS131_SETUP(uint8_t unit);
void ADS131_READFRAME();
void ADC_DATA_READY();
// ADC Data Arrays
volatile uint32_t AD131_RAW[NCH];
// Interrupt Service Routine for Data Ready Pin
void ADC_DATA_READY() {
ADS131_READFRAME(); // Read a frame of data
DRDY_FLAG = 1; // Set the data ready flag
}
void setup() {
pinMode(DEBLED, OUTPUT);
pinMode(ADS131_CS_PIN, OUTPUT);
digitalWrite(ADS131_CS_PIN, HIGH); // Set CS high (inactive)
SPI.begin();
SPI.beginTransaction(SPISettings(36000000, MSBFIRST, SPI_MODE1));
Serial.begin(1000000);
delay(100);
ADS131_SETUP(0);
delay(100);
attachInterrupt(digitalPinToInterrupt(ADC_DRDY_PIN), ADC_DATA_READY, FALLING);
}
void loop() {
if (DRDY_FLAG) {
for (int i = 0; i < NCH; i++) {
Serial.print(AD131_RAW[i]);
delayMicroseconds(sdel);
Serial.print("\t");
delayMicroseconds(sdel);
}
Serial.print("\n");
delayMicroseconds(100);
DRDY_FLAG = 0;
}
}
void ADS131_READFRAME() {
digitalWriteFast(DEBLED, HIGH);
digitalWriteFast(ADS131_CS_PIN, LOW); // Activate CS
SPI.transfer(0x00); // Dummy transfer to initiate SPI communication
SPI.transfer(0x00); // Read status byte (2 bytes total, but not used here)
for (int i = 0; i < NCH; i++) {
AD131_RAW[i] = SPI.transfer(0x00) << 16; // Read ADC data (24 bits)
AD131_RAW[i] |= SPI.transfer(0x00) << 8;
AD131_RAW[i] |= SPI.transfer(0x00);
}
SPI.transfer(0x00); // Read CRC (2 bytes total, but not used here)
SPI.transfer(0x00);
digitalWriteFast(ADS131_CS_PIN, HIGH); // Deactivate CS
digitalWriteFast(DEBLED, LOW);
}
void ADS131_SETUP(uint8_t unit) {
uint16_t dd = 0b0000000000000000;
delay(300);
digitalWrite(ADS131_CS_PIN, LOW); // Activate CS
// Configuration register setup
dd = 0b0110000110000010; // Write register command
SPI.transfer(dd >> 8);
SPI.transfer(dd);
SPI.transfer(0);
dd = 0b0111111100000010 + (0x03 << 2); // Set OSR (Over Sampling Rate)
SPI.transfer(dd >> 8);
SPI.transfer(dd);
SPI.transfer(0);
dd = 0b0000000000000000; // Set channel gain (default to 0)
SPI.transfer(dd >> 8);
SPI.transfer(dd);
SPI.transfer(0);
for (int ii = 0; ii < 4; ii++) {
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
}
digitalWrite(ADS131_CS_PIN, HIGH); // Deactivate CS
}