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.

ADS1247 spi internal temp

Other Parts Discussed in Thread: ADS1247

Hi, I'm trying to read the internal temp of the ads1247 and I am getting gibberish. here is my code can someone tell me what I am doing wrong? I'm test the IC on a arduino uno, but after I manage to get it to work I am going to port the program to a couple of pic18 mcus

#include <SPI.h>
unsigned long A2DVal =0x0;
void setup() {
  pinMode(10, OUTPUT);
  pinMode(9, INPUT);
  //pinMode(11, OUTPUT);
  //pinMode(12, INPUT);
  //pinMode(13, OUTPUT);
  SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE1));
  delay(2000);
  SPI.begin();  //turn on spi bus
  /*
   * prog interruptfor drdy
   */
   SPI.transfer(0x06);//reset ad
   delay(1);
   SPI.transfer(0x16);//issue sdatac
   SPI.transfer(0x40);//mux0
   SPI.transfer(0x00);
   SPI.transfer(0x01);
   SPI.transfer(0x42);//mux1
   SPI.transfer(0b00000000);
   SPI.transfer(0b00110011);
   //SPI.transfer(0x00);
   //SPI.transfer(0x33);
   SPI.transfer(0x43);//sys0
   SPI.transfer(0x00);
   SPI.transfer(0b00000000);
   SPI.transfer(0x4A);//IDAC0
   SPI.transfer(0x00);
   SPI.transfer(0x07);
   SPI.transfer(0x4b);//IDAC1
   SPI.transfer(0x00);
   SPI.transfer(0x01);

   Serial.begin(115200);
}

void loop() {
  if (digitalRead(9) == 0){
        Serial.println("cowabunga");
        digitalWrite(10,LOW);
        A2DVal = 0x0;
      
        SPI.transfer(0x12);
        Serial.print(A2DVal,HEX);
        A2DVal |= SPI.transfer(0xff);
        A2DVal << 8;
        Serial.print(A2DVal,HEX);
        A2DVal |= SPI.transfer(0xff);
        A2DVal <<8;
        Serial.print(A2DVal,HEX);
        A2DVal |= SPI.transfer(0xff);
      
        Serial.println(A2DVal,HEX);
        delay(1);  
    }
  
}

  • Daniel,


    I'm not great at reading through Arduino code, so it might help to get an oscilloscope or a logic analyzer to make sure that your communications are correct. If you can post the scope shot of SCLK, DIN, DOUT, and CS it would certainly help. However, I don't seen any obvious problems. It looks like the MUX1 register is set correctly so that the reference is always on and the internal temperature diode is set to be read.

    One common problem that I've heard about with Arduino code is that the /CS line needs to be low through the entire data transaction (not just byte-to-byte). Make sure that part of the communication is correct.

    When you say you get gibberish, what exactly are you getting? What data is coming out of the ADC (I want the raw data, not the converted temperature values)? Does any of the data look correct? Is it giving repeated values?


    Joseph Wu
  • Joseph,


    I used an oscilloscope to see it the communication is correct and I 'read' the bytes sent to and from the ADS. I kept the CS line low throughout the entire transaction, perhaps I need to set CS to high in the end.

    By gibberish I mean 3 random bytes, at first I was receiving 7F FF FF, which according to the datasheet means overflow.

  • Daniel,


    I just wanted to check the communications. If you even suspect that the communication is in error, just post the scope shots that you get.

    When you get 7FFFFF as an output of the ADC, it means that the input is larger than the reference. I would first check to make sure that the reference is on and that it is being used as the ADC reference. Then check that the internal reference working by measuring from VREFOUT to VREFCOM with a multimeter. Note that for stability, you'll need somewhere from 1uF to 47uF of capacitance from VREFOUT to VREFCOM.


    Joseph Wu
  • Sorry for taking long to reply. i cleaned up the arduino code and commented it. I'm also sending you the the pins you requested. since my oscilloscope only has two channels I kept the clock(yellow/orange) in all the images. I have a 1uF capacitor on VREFOUT to VREFCOM, it is wired according to page 88 of the datasheet. strange this is that now I'm getting 7FFFFF.

    #include <SPI.h>
    unsigned long A2DVal =0x0;
    //vdd 5v
    //spi 500 kHz
    
    void setup() {                               // start arduino setup
       pinMode(10, OUTPUT);
       pinMode(9, INPUT);
       SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE1));
       delay(2000);
       SPI.begin();  //turn on spi bus            // end arduino setup
       SPI.transfer(0x06);//reset ad
       delay(1);
       SPI.transfer(0x16);//issue sdatac    (command)
       SPI.transfer(0x40);//mux0            (command)
       SPI.transfer(0x02);//mux1            (command)
       SPI.transfer(0x01);//mux0              data
       //SPI.transfer(0b00110011);// mux1       data  int. temp
       SPI.transfer(0x31); //mux1             data     v offset
       SPI.transfer(0x43);//sys0            (command)
       SPI.transfer(0x07);//IDAC            (command)
       SPI.transfer(0x00); //sys0             data
       SPI.transfer(0x07);// idac             data
       SPI.transfer(0x4b);//IDAC1           (command)
       SPI.transfer(0x00);//                (command)
       SPI.transfer(0x01);//                  data
       SPI.transfer(0xff);// NOP              data
    
       Serial.begin(115200);
    }
    
    void loop() {
      if (digitalRead(9) == 0){
            Serial.println("New data");
            digitalWrite(10,LOW);//         CS pin to low
            A2DVal = 0x0;//                  byte read
            SPI.transfer(0x12);// read      (command)
            A2DVal |= SPI.transfer(0xff);//    NOP
            Serial.println(A2DVal,HEX);//                   arduino serial com. to computer (serves as a delay)
            A2DVal |= SPI.transfer(0xff);//    NOP
            Serial.println(A2DVal,HEX);//                   arduino serial com. to computer (serves as a delay)
            A2DVal |= SPI.transfer(0xff);//    NOP
            Serial.println(A2DVal,HEX);//                   arduino serial com. to computer (serves as a delay)
            
            digitalWrite(10, HIGH);//     CS pin to high   
            delay(210);  
        }
      
    }
    

    clock and master in slave out:

    zoomed:

    clock and master out slave in:

    zoomed:

    CS pin:

  • Daniel,


    Do you have a basic schematic for your connections to the ADS1247?

    Looking at the code, you RESET the device, then issue the SDATAC. However, then you write 40 02 which says that it's a write command starting at 00h for three bytes (not two). Then 01h is written into BCS, 33h is commented out, 31h is written into VBIAS, then 43h is written into MUX1. After that, I think the 07h will be interpreted as a reset and you're already off from the intended sequence.

    Just to be sure, I would go back to the code to make the fixes and then try reading back from your registers to see if you've gotten the write correct.

    Also, do you have a four channel scope? It might help to see the SCLK, /CS, DIN and DOUT all at the same time.


    Joseph Wu