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.

ADS1226 Flow

Other Parts Discussed in Thread: ADS1226

Hello,

I'm currently working on an project that uses an ADS1226 connected to a Cortex-M0 STM32F051.

I'm having some issues getting reliable data out of this device. Can you please tell me what is the correct flow to take one reading from ADC1 then switch to ADC2 and take one reading. I need the system to be in High resolution mode with buffer enable.

To make it easier I created a function:

int32_t ADC_read(ADC_Typedef channel) 
{ 
uint8_t ADC_buffer[3]; 
int32_t int32_temp; 

  GPIO_ResetBits(ADC_START_PORT,ADC_START_PIN); /* Start Pin */ 
  GPIO_ResetBits(ADC_BUFEN_PORT,ADC_BUFEN_PIN); /* Buffer disable */ 
  if(channel == CHANNEL_NH) 
  { 
    GPIO_SetBits(ADC_MUX_PORT,ADC_MUX_PIN); /* MUX 1 */ 
  } 
  else if(channel == CHANNEL_PH) 
  { 
    GPIO_ResetBits(ADC_MUX_PORT,ADC_MUX_PIN); /* MUX 0 */ 
  }
  GPIO_SetBits(ADC_BUFEN_PORT,ADC_BUFEN_PIN); /* Buffer Enable */
  GPIO_SetBits(ADC_START_PORT,ADC_START_PIN); /* Start Pin */ 
  delay_us(30); /* Spec requires a minimum of 17 us */ 
  GPIO_ResetBits(ADC_START_PORT,ADC_START_PIN); /* Start Pin */ 
  while(GPIO_ReadInputDataBit(ADC_DRDY_PORT,ADC_DRDY_PIN) != RESET) 
  {
    os_dly_wait (1); 
  } 
  ADC_buffer[0] = Send_Receive_Byte(0x00); 
  ADC_buffer[1] = Send_Receive_Byte(0x00); 
  ADC_buffer[2] = Send_Receive_Byte(0x00); 
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);

  int32_temp = (ADC_buffer[2] | (ADC_buffer[1]<<8) | (ADC_buffer[0]<<16)); 
  int32_temp <<= 8; 
  int32_temp /= 256; 

  return int32_temp; 
}

 

Calling this function returns "0" if I take some delay between two calls. It returns correct data only on one channel if I call them without delay in-between.

I had an other code working perfectly when doing multiple reading of a single channel but I'm stuck with the use of MUX. I can't find much information in the datasheet. 

Can you please let me know where I go wrong in my flow?

Thanks,

Alex

  • Hi Alex,

    I'm not that familiar with the ARM peripherals, but it would seem to me that the statements to get the data will send the request to the hardware peripheral faster than the data can be collected.  I would think that there needs to be a transfer flag check between each of the 'Send_Receive_Byte' calls.  I would verify all the timing operations with a scope or logic analyzer.  This will also verify that the data in your code is matching the actual response of the ADS1226.

    I'm also confused as to why you left shift by 8 (multiply by 256), then divide by 256 (or right shift by 8).  I think you are attempting to do sign-extension, but this is a rather processor intensive method.  All you have to do is check to see if the most significant bit of the returned data is high.  If it is 0, then do nothing.  If it is high, then OR 0xFF000000 to the int32_temp variable.

    Best regards,

    Bob B

  • Hi Bob,

    Thanks a lot for your answer.

    I'm waiting for the flags in the  'Send_Receive_Byte' function already. I checked all timings with a logic analyser and I still cant find the issue ... The timings are good but I can't get data out. 

    When I set the Start pin, the data pin stays low (opposed to what is written in the datasheet figure 26). 

    Also, following figure 26 if I want to activate BUFFEN as well, should I reset BUFFEN when I reset START pin? Or should I keep BUFFEN enable until the conversion is ready? 

    For the sign extension you are right, my way is processor intensive. I'll implement your method, thank you.

     

    Best regards,

    Alex

  • Hi Alex,

    I think the clue is that DOUT/DRDY is not going high, which then skips and jumps to the next function call.  If you hold START high continuously, do you see DRDY/DOUT toggle and pulse high?  Can you send me analyzer plots of DOUT/DRDY, START and SCLK when you pulse START?

    You should leave the buffer enabled until after the conversion completes.

    Best regards,

    Bob B

  • Hi Bob,

    I keep START pin high for 20us and wait for the DOUT/DRDY to toggle.

    Then I read the data, I switch the Buffer off, I toggle the Mux, and reactivate the buffer and start pin.

    Now it works. Thank you for your help!

    I'm surprised by the inaccuracy of the datasheet.

    Regards,

    Alex

  • Hi Alex,

    It is hard to read the picture, so I can't verify the timing.  Can you attach the original logic analyzer plot as a picture file that has better resolution?  Once we verify what is happening we can look at making the datasheet clearer.

    Best regards,
    Bob B

     

  • Hi Bob,

    This time I attached it.

    Regards,

    Alex