This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1218: Invalid data coming from ADC ads1218 interfaced with arduino UNO

Part Number: ADS1218

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

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Sushmita,

    I refer you back to the datasheet regarding the communication transfers and commands being used.  For example, the WREG command is a two command sequence.  For example, your code shows the command (0x50) and the register data 0x1E.  But the write register command requires that you send both the command and the number of registers to be written -1 followed by the data.  So for this sequence to write to register 0 would be 0x50 0x00 0x1E.

    I think there may be some confusion as to the MUX register write.  There is only one ADC so you can only take one measurement at at time.  There is no FIFO or auto-scan features with the ADS1218.  So the correct procedure would be to write 0x51 0x00 0x01.

    The last register configuration would be 0x52 0x00 0x00.  Note that each communication transaction in all cases requires that CS be held low throughout the entire transfer.  I do not see this happening within the Setup.  To verify your register writes you can read back the register contents to verify the contents.  It is also a good idea to use an oscilloscope or logic analyzer to check that the transmission is as expected.

    I would also verify that the DRDY is toggling using an oscilloscope.  If you do not see this happening then either the oscillator has not started correctly, you do not correct power applied to both analog and digital supply pins or perhaps some pins are floating/not connected properly such as PDWN, POL, RESET, etc.

    Best regards,

    Bob B

  • Hi Bob,

    Thank you for the information. Register addressing was done wrong in my code. I will correct that part and check how the data is coming.

    I have one doubt regarding the SCLK period, since in data sheet it is given that SCLK period can be used up to 4tosc periods so my microcontroller clock is 16Mhz so 4*tosc= 1Mhz (fosc is 4Mhz) so in my code dividing the arduino clock to level of 1Mhz using SPI clock divide function (SPI.setClockDivider(SPI_CLOCK_DIV16) for SPI operation is correct right?

  • Hi Sushmita,

    1MHz SCLK would be the fastest clock you could use for communication given your desired settings.  It appears that the clock divider setting is correct, but you can always verify the clock frequency with an oscilloscope or logic analyzer.

    Best regards,

    Bob B