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.

ADS1258: DRDY Read

Part Number: ADS1258


Hi Team,

I am using the direct data read for ADS1258. When ever I got a DRDY low it will go to a interrupt handler in my controller. So in this handler first I have to make the Start pin to low to make the device idle. After that I have to read the data. Is it right? I have seen this method in this forum where your Team mention this method to someone. 

As of now I am doing program flow like this in the interrupt handler.

// When DRDY is low
void Interrupt_handler(){

    disable_the_interrupt();
    start_pin_to_low();
    read_data();
    start_pin_to_high();
    enable_the_interrupt();
    
}

Any suggestion

  • Hi FAHAD K R,

    First make sure that the interrupt triggers on the falling edge of DRDY as opposed to a level trigger.  In your interrupt handler routine, make sure you clear the interrupt prior to enable_the_interrupt() function.  Setting the start_pin_to_low() will not stop the ongoing conversion.  It will stop after the next conversion completes, so you are not in the idle state as the ADC is still converting.  Most likely for this sequence you will read the conversion data and set start_pin_to_high() before you actually reach the idle state.  The process is shown in Figure 53 of the ADS1258 datasheet.

    I'm thinking you want to take a single conversion, read the data when DRDY goes low, and the start the next conversion (Figure 54 in the datasheet).  If this is the case, then you should just pulse the START pin low-high-low when you want to start the next conversion.  To do this you would pulse the start pin at the beginning prior to entering your main loop to initiate the first conversion.  In the interrupt routine you would remove the existing start_pin_ functions and instead add the start pulse (or toggle) function.

    Although this interrupt routine should work, there are some potential issues depending on the complexity of your system.  In general good programming practice is to acknowledge the interrupt and get out as quickly as possible.  One way to limit the amount of time is to set a Boolean flag to true for new data available.  Then in your main loop, you check to see the value of the flag and if the flag is set, then you read the data.  This is important when multiple interrupts could occur that may affect the overall timing of the program loop.  An example of how to do this is in the ADS1258 Example C Code.

    Best regards,

    Bob B

  • Hi Bob,

    This is the data out from the SPI communication.

    Blue- DRDY

    Green- Data out from ADC

    Yellow- Clock

    1) I am reading it in the direct mode. I tried with 3 byte and 4 byte (with and without the status byte). But get the same output, only 8 clock is there and the data is same for the all time (data is 0x92). 

    2) I have a doubt in the sample code. If I am setting a flag in the ISR, I only have to call the function waitForDRDYinterrupt function when I need to read the data and Enable the interrupts, Then I have to wait for the interrupt. And in this waitForDRDYinterrupt function after interrupt I have to read the data. Is it you mean by the previous suggestion?

     

    bool waitForDRDYinterrupt(uint32_t timeout_ms)
    {
        /* --- TODO: INSERT YOUR CODE HERE ---
         * Poll the nDRDY GPIO pin until it goes low. To avoid potential infinite
         * loops, you may also want to implement a timer interrupt to occur after
         * the specified timeout period, in case the nDRDY pin is not active.
         * Return a boolean to indicate if nDRDY went low or if a timeout occurred.
         */
    
        // Convert ms to # of loop iterations or use a timer
        uint32_t timeout = timeout_ms * 6000;   // convert to # of loop iterations
    
        // Reset interrupt flag
        flag_nDRDY_INTERRUPT = false;
    
        // Enable interrupts
        IntMasterEnable();
    
        // Wait for nDRDY interrupt or timeout - each iteration is about 20 ticks
        do {
            timeout--;
        } while (!flag_nDRDY_INTERRUPT && (timeout > 0));
    
        // Reset interrupt flag
        flag_nDRDY_INTERRUPT = false;
    
        return (timeout > 0);           // Did a nDRDY interrupt occur?
    }
    
     

    Thank You 

    FAHAD K R

  • Hi FAHAD K R,

    1) I am reading it in the direct mode. I tried with 3 byte and 4 byte (with and without the status byte). But get the same output, only 8 clock is there and the data is same for the all time (data is 0x92). 

    I am a bit confused here as to what you are trying to do.  Did you set or pulse the START pin to initiate a new conversion?  Also, the microcontroller initiates the SCLK, so are you saying that you are only seeing 1 bytes worth of SCLK?

    2) I have a doubt in the sample code. If I am setting a flag in the ISR, I only have to call the function waitForDRDYinterrupt function when I need to read the data and Enable the interrupts, Then I have to wait for the interrupt. And in this waitForDRDYinterrupt function after interrupt I have to read the data. Is it you mean by the previous suggestion?

    In your main loop you can use the waitForDRDYinterrupt(), but you don't need to use this function.  What I was attempting to demonstrate was the use of a flag.  Here is another example using your original code:

    // When DRDY is low
    void Interrupt_handler(){
    
        disable_the_interrupt();
        flag_nDRDY_INTERRUPT = true;
        
        // check to make sure that the interrupt gets cleared before reenabling
        enable_the_interrupt();
    }
    
    void main {
        bool flag_nDRDY_INTERRUPT = false;
        
        // setup the ADC and enable the interrupt
        // toggle the START pin to initiate the first ADC conversion
        start_pin_to_high();
        start_pin_to_low();
        
        // main loop
        while(.t.) {
            // this is the main processing loop so add what ever you would like to 
            // do in this loop
            
            // if the flag has been set, then there is new data
            if(flag_nDRDY_INTERRUPT==true) {
                read_data(); 
                // reset the status flag
                flag_nDRDY_INTERRUPT = false;
                // toggle the START pin to initiate the next ADC conversion
                start_pin_to_high();
                start_pin_to_low();
        }
    }

    Notice that all that is done within the interrupt is to set the flag and your main processing loop checks the status of the flag and reads the data if new data are available.

    Best regards,

    Bob B