Hello,
I am trying to read data from ads1218 ADC interfaced with Arduino Uno. I have connected 5V DC input in AIN0 (+ve) and AIN1 (-ve), 4Mhz crystal oscillator (2 no of 22pf capacitor connected in parallel ) is used in Xin and Xout pins, fosc=4Mhz,fmod=31.25kHz, PGA=1. My connection are as follows:
Since arduino clock is 16Mhz and fosc is 4Mhz so as per the data data sheet SCLK period can be used up to 4tosc periods(up to 1Mhz) so using SPI clock divide function(SPI.setClockDivider(SPI_CLOCK_DIV16) arduino SPI clock is divided to level of 1Mhz.
DRDY: Pin 6
Din: Pin 11
Dout: Pin 12
SCLK: Pin13
CS: Pin 7
#include <SPI.h> #define RESET 0x06 //Send the RESET command (06h) to make sure the ADS1220 is properly reset after power-up #define START 0x08 //Send the START/SYNC command (08h) to start converting in continuous conversion mode // define the ads1218 command #define RDATA 0x01 // read the latest ad conversion data #define WREG 0x50 // 2 byte command, write data to register 0-15 #define DSYNC 0xFC // Sync DRDY #define RESET 0xFE // reset the register to the power of the data, stop the continuous read mode, does not affect the ram data #define ADS1218_CS_PIN 7 #define ADS1218_DRDY_PIN 6 int32_t stat; void syncSerialData(void) { noInterrupts(); digitalWrite(ADS1218_CS_PIN, LOW); delayMicroseconds(500); SPI.transfer(DSYNC); delayMicroseconds(500); digitalWrite(ADS1218_CS_PIN, HIGH); interrupts(); delay(2000); } void waitForDataReady(int timeOut) //wait for data ready { // wait for /DRDY = 1 while ((digitalRead(ADS1218_DRDY_PIN)) != LOW); // wait for /DRDY = 0 while ((digitalRead(ADS1218_DRDY_PIN)) == LOW); } void setup() { pinMode(ADS1218_CS_PIN, OUTPUT); digitalWrite(ADS1218_CS_PIN, HIGH); Serial.begin(9600); SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE1); SPI.setClockDivider(SPI_CLOCK_DIV16); // SCLK upto 4tosc periods // setup register (00) SPI.transfer(0x50); SPI.transfer(0x1E); //speed:4Mhz ; fmod:fosc/256,ref enable,2.5Vref,,buffer enable,bit order:0 MSB first // Setting the MUX register channel requirement SPI.transfer(0x51);// write command: 0101 mux address(01) SPI.transfer(0x05); // wreg -1(6 register to write due to 6 channels) SPI.transfer(0x01); // ain0 and ain1 // Write command to address 02 SPI.transfer(0x52); // analog control register SPI.transfer(0x00);// PGA set to 1 syncSerialData(); // Sync Data Ready with Serial clock edge delay(50); } void loop() { digitalWrite(ADS1218_CS_PIN, LOW); //Take CS low SPI.transfer(RDATA); delayMicroseconds(12.5); // used:4Mhz (50tosc)) stat= SPI.transfer(0) ; stat = (stat<<8) | SPI.transfer(0); stat = (stat<<8) | SPI.transfer(0); digitalWrite(ADS1218_CS_PIN, HIGH); // Clear CS to high if (stat & 0x800000 ) { stat = (stat | 0xFF000000); } Serial.println(stat); delay(50); // }