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