Hi,
I am trying to configure my ADS1218 with arduino board. I am using following setting:
AVCC = 5 v
Unipolar
Decimation 1920
Digital filter SINC3
I perform calibration with buffer off and turn it on after calibration.
I am applying 1.3 Vdc on channel Ain0 and Ain1 by setting the MUX to 0x01, fMOD = 9600 hz
Problem is that after calibration I read 0.00 all the time regardless of input which I can vary from 0 to 2 volts.
If I use it without calibration I get 2.5 V all the time regardless of input which I can vary from 0 to 2 volts.
Here is my code:
/************************************************************** Aalto_ADS1218.ino this example gives differential voltage across the AN0 And AN1 in uV Hooking-up with the Arduino |ADS1218 pin label| Pin Function |Arduino Connection| |-----------------|:--------------------:|-----------------:| | DRDY | Data ready Output pin| D6 | | MISO | Slave Out | D12 | | MOSI | Slave In | D11 | | SCLK | Serial Clock | D13 | | CS | Chip Select | D7 | | DVDD | Digital VDD | +5V | | DGND | Digital Gnd | Gnd | | AN0-AN3 | Analog Input | Analog Input | | AVDD | Analog VDD | - | | AGND | Analog Gnd | - | *************************************************************/ #include <SPI.h> #define SPI_MASTER_DUMMY 0xff #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 RDATAC 0x03 // continuously read the converted data #define STOPC 0x0F // Stop continuous read mode #define RREG 0x10 // Two-byte command to read register contents First byte: bit3-bit0 = 0-16; #define RRAM 0x20 // two-byte command to read the contents of the first byte ram: bit3-bit0 = 0-16; #define CREG 0x40 // copy the contents of the register to the specified ram bank, the lower three bits specify the ram page address #define CREGA 0x48 // copy the contents of the register into all ram banks. #define WREG 0x50 // 2 byte command, write data to register 0-15 #define WRAM 0x60 // 2 bytes instruction, write data to 128 bytes in ram #define RF2R 0x80 // read the data of the specified FLASH page into 128 bytes of RAM #define WR2F 0xA0 // Write the data in ram to the specified FLASH page #define CRAM 0xC0 // Copy the selected ram data into the configuration register, which will overwrite the current working register contents #define CSRAMX 0xD0 // Calculate the checksum in the specified page ram, do not include ID, DRDY DIO #define CSARAMX 0xD8 // Calculate the checksum in all rams, do not include ID, DRDY DIO #define CSREG 0xDF // Calculate the checksum of the configuration register #define CSRAM 0xE0 // Calculates the checksum in the specified page ram, containing all bits #define CSARAM 0xE8 // Calculates the checksum in all rams, containing all bits #define CSFL 0xEC // Calculate the checksum in all FLASH, including all bits #define SELFCAL 0xF0 // Offset and gain self-calibration #define SELFOCAL 0xF1 // offset self-calibration #define SELFGCAL 0xF2 // gain self-calibration #define SYSOCAL 0xF3 // System Offset Calibration #define SYSGCAL 0xF4 // System Gain Calibration #define DSYNC 0xFC // Sync DRDY #define SLEEP 0xFD // sleep mode #define RESET 0xFE // reset the register to the power of the data, stop the continuous read mode, does not affect the ram data // define the ads1218 register Addresses #define SETUP_REG_ADRS 0x00 #define MUX_REG_ADRS 0x01 #define ACR_REG_ADRS 0x02 #define IDAC1_REG_ADRS 0x03 #define IDAC2_REG_ADRS 0x04 #define ODAC_REG_ADRS 0x05 #define DIO_REG_ADRS 0x06 #define DIR_REG_ADRS 0x07 #define DEC0_REG_ADRS 0x08 #define DEC1_REG_ADRS 0x09 #define OCR0_REG_ADRS 0x0A #define OCR1_REG_ADRS 0x0B #define OCR2_REG_ADRS 0x0C #define FSR0_REG_ADRS 0x0D #define FSR1_REG_ADRS 0x0E #define FSR2_REG_ADRS 0x0F #define ADS1218_CS_PIN 7 #define ADS1218_DRDY_PIN 6 void writeRegister(uint8_t address, uint8_t value) { uint8_t numReg = 0x01; noInterrupts(); digitalWrite(ADS1218_CS_PIN, LOW); // delayMicroseconds(500); SPI.transfer(WREG | address); SPI.transfer(numReg); SPI.transfer(value); // delayMicroseconds(500); digitalWrite(ADS1218_CS_PIN, HIGH); interrupts(); } uint8_t readRegister(uint8_t address) { uint8_t data; uint8_t numReg = 0x01; noInterrupts(); digitalWrite(ADS1218_CS_PIN, LOW); // delayMicroseconds(500); SPI.transfer(RREG | address); SPI.transfer(numReg); delayMicroseconds(20); // delay of 10 uS needed data = SPI.transfer(SPI_MASTER_DUMMY); // delayMicroseconds(500); digitalWrite(ADS1218_CS_PIN, HIGH); interrupts(); return data; } void printAllreg(void) { int read_data0; for (int i = 0; i <= 15; i++) { read_data0 = readRegister(i); Serial.println(read_data0, HEX); delay(10); } } void SendSELFCALCommand(void) { noInterrupts(); digitalWrite(ADS1218_CS_PIN, LOW); delayMicroseconds(500); SPI.transfer(SELFCAL); delayMicroseconds(500); digitalWrite(ADS1218_CS_PIN, HIGH); interrupts(); delay(2000); } 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); } uint32_t Read_Data(int passFlag) { uint32_t dataBits = 0x0000; if (passFlag) { waitForDataReady(0); noInterrupts(); digitalWrite(ADS1218_CS_PIN, LOW); //Take CS low // delayMicroseconds(500); SPI.transfer(RDATA); delayMicroseconds(20); byte msbData = SPI.transfer(SPI_MASTER_DUMMY); byte midData = SPI.transfer(SPI_MASTER_DUMMY); byte lsbData = SPI.transfer(SPI_MASTER_DUMMY); // delayMicroseconds(500); digitalWrite(ADS1218_CS_PIN, HIGH); // Clear CS to high interrupts(); dataBits = msbData; dataBits = (dataBits << 8) | midData; dataBits = (dataBits << 8) | lsbData; } return dataBits; } void setup() { digitalWrite(ADS1218_CS_PIN, HIGH); pinMode(ADS1218_CS_PIN, OUTPUT); Serial.begin(9600); //115200 57600 SPI.begin(); // wake up the SPI bus. SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE1); SPI.setClockDivider(SPI_CLOCK_DIV64); writeRegister(0x00, 0xfc); //0000 1100 ,buffer disabled. delay(50); writeRegister(0x08, 0x80); // Decimation register 1, DEC0 delay(50); writeRegister(0x09, 0x77); // Decimation register 2, DEC1, unipolar, SINC3 filter set delay(50); printAllreg(); delay(5000); SendSELFCALCommand(); delay(5000); writeRegister(0x00, 0xfe); //0000 01110 ,buffer enabled, fMOD = 9600 delay(50); writeRegister(0x08, 0x80); // Decimation register 1, DEC0 delay(50); writeRegister(0x09, 0x77); // Decimation register 2, DEC1, unipolar, SINC3 filter set delay(50); writeRegister(0x01, 0x01); // set MUX delay(50); syncSerialData(); // Sync Data Ready with Serial clock edge delay(50); printAllreg(); } void loop() { uint32_t data32 = 0; data32 = Read_Data(1); float value = (float(data32) * 2.5 * 1000000) / 16777216; Serial.print(" 32bit BIN : "); Serial.println(data32, BIN); Serial.print(" Value : "); Serial.println(value, BIN); delay(50); } Here is my schematic:
Any suggestions???
Thanks in advance,
Tanweer