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.

ADS1220: ADS1220 RDATA command error

Part Number: ADS1220

Hi,
Need support to read temperature using ADS1220.

I am using ADS1220 in my project to read thermocouple temperature.


This is the command I used to write

uint8_t buffer[3] = {0,0,0};

buffer[0] = 0x10; //RDATA command
spi_intf.Write(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x03 );


and this is the command I used to read Data using RDATA command

spi_intf.Read(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x03);

but I am not getting proper values while reading.

These are the values I could read ( buff[0]= 0x23, buff[1] = 0x40 buff[2] =0x80)
but approximate values should be buff[0]= 0x03 and buff[1] = 0x20 for 25 Degree temperature measurement


so am I missing any thing ( any other settings)here  and also want to know my commands(Read & write) above  are correct?

Regards,

Anil

  • Hi Anil,

    Welcome to the E2E forum!  The SPI communication will retrieve data full-duplex.  At the same time you write or transfer data, the buffer will also receive data.  So when sending the RDATA command there is actually 4 bytes transmitted and the actual data is in the last 3 bytes.  So it is not clear how the code function is working, but you need to make sure that you are recovering the correct contents.  A guess on my part would be to start reading data at buff[1] instead of buff[0].  Also when transmitting, make sure that you are transmitting 4 bytes and not just 3.

    I would highly recommend that you connect an oscilloscope or logic analyzer to the SPI communications signals and verify that what you are collecting in your code is what is actually transmitted.

    If you still have issues, send me the register settings being used and plots of the communication.

    Best regards,

    Bob B


  • Hi Bob,
    Thanks for your reply and time.

    These are my register configurations

    Multiplex setting:

    uint8_t buffer[] = {0,0};
    buffer[0] = 0x40;
    buffer[1] = 0x30<< 4; // connected to AN1 and AN2

    spi_intf.Write(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x02);

    Setting temp sensor:

    uint8_t buffer[] ={0,0};
    buffer[0] = 0x44;
    buffer[1] = 0x02;

    spi_intf.Write(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x02 );

    conversion mode settting:

    uint8_t buffer[] ={0,0};
    buffer[0] =0x44;
    buffer[1] = 0x04;

    spi_intf.Write(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x02);

    Temperature Reading:

    uint8_t buffer[3] = {0,0,0};
    uint32_t t32;
    buffer[0] = 0x10; //RDATA command
    err = spi_intf.Write(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x04 );

    if (err.IsOk())
    {
    err = spi_intf.Read(reinterpret_cast<std::uint8_t*>(&buffer[0]), 0x03);
    }

    t32 = (uint32_t)buffer[1];
    t32 <<= 8U;
    t32 |= (uint32_t)buffer[2];

    if ((t32 & 0x00008000U) != 0) // For negative temperature calculation
    {
    *rtntemp = static_cast<float32_t>(~(t32-1) * (-0.03125F));
    }
    else
    {
    *rtntemp = static_cast<float32_t>(t32 * 0.03125F);
    }

    I have 3 queries here

    1) Is that my configuration is correct ?

    2)why I am not getting proper values in my buffer[1] and buffer[2]

    3)want to know whether my temperature conversion is correct esp for negative temperature

    Regards,

    Anil

    Regards,

    Anil

  • Hi Anil,

    Have you tried reading back the configuration registers after writing them?  I think that would be a good indication if your communication is working.  I would also suggest going back and review the command structures in the ADS1220 datasheet.

    It would also be a good idea to look at the data with an oscilloscope or logic analyzer to verify what you think you are communicating to the ADS1220 is in fact what is going on.

    1) Is that my configuration is correct ? [Bob] No, you are close but not quite.  For example for register 0 you are sending 0x40 (0x30<<4) which is not AIN1/AIN2 but instead are sending 0x40 0xC0 which would be setting to the reference monitor for the external reference input.  In the following statements your write to the register 1 with 0x44 0x02 followed by 0x44 0x04.  The first command sets the temperature sensor to ON, but the next command overwrites the first and sets the configuration to continuous mode.  So the second command to register 1 will turn of the internal temperature sensor measurement.  What should be sent is 0x44 0x06 if you want to both turn on the temperature sensor and operate in continuous mode.

    2)why I am not getting proper values in my buffer[1] and buffer[2] [Bob] You are not getting the code expected because you are not configuring the device properly.  

    3)want to know whether my temperature conversion is correct esp for negative temperature [Bob] I would recommend that you review the datasheet information regarding the internal temperature sensor.  The temperature sensor is 14-bit left justified within the data.  The ADS1220 is 24-bit, but it appears that you are reading the result by short-cycling and just reading the most-significant 2 bytes.  So after capturing the conversion data at some point you need to right-shift 2 (>>2) the result to 14 bits.  You also have an issue with negative values.  When you invert, you are inverting the entire 32-bit integer.  The method I would use is to save the temperature result to a short signed integer (16-bit) then >> 2 for a 14-bit value.  The value should already be either positive or negative without further manipulation.  Just multiply the result times the coefficient.

    Best regards,

    Bob B

  • Hi Bob,

    Thanks again for your reply.

    you are right and I got the point where I did wrong. Now I corrected my code to configure mux with 0x40 0x30( for AN1 and AN2) then 0x44 0x06 for selecting

    with conversion mode and temp sensor mode. I will readback my values to cross check.(Still I need to do this part)

    Now if I read by buffer values from RDADA -> it reads as 

    buff1], buff[2]  = a3,63
    buff1], buff[2]  =  a2,fb
    buff1], buff[2]  = a3,2f
    buff1], buff[2]  = a3,bf
    buff1], buff[2]  = a3,db

    for 25 degree values I should get my buff[1] as 0x09 or 0x10

    so still I cant read correct values from sensor. 

    Regards,

    Anil

  • Hi Anil,

    I write code all of the time.  I cannot always tell from the response of my reading the values in code or debugger that they are correct.  You need to use the right tools like an oscilloscope or logic analyzer to make sure that the communication is correct to the ADS1220, and that when you read the data back your result from the ADC as shown in the scope plots matches your data shown in code.

    Earlier today I saw a post where the customer was sure that their code was correct, and as it turns out the SPI communication showed that they were using the wrong phase for SPI and so the data was changing on the same edge as it was being read.  The only way you can find these issues is by using the proper tools.  Send me scope or logic analyzer shots of your communication and I can help further.

    Best regards,

    Bob B