Improving ADC121C021 or esp32's ADC sample time

Hi,
I would like to improve my adc readings to its maximum capability, trying to understand if i'm there or not.
My code using ADC121C021:

#include <Wire.h>
 
#define ADDR_ADC121             0x50
 
#define V_REF 3.00
 
#define REG_ADDR_RESULT         0x00
#define REG_ADDR_ALERT          0x01
#define REG_ADDR_CONFIG         0x02
#define REG_ADDR_LIMITL         0x03
#define REG_ADDR_LIMITH         0x04
#define REG_ADDR_HYST           0x05
#define REG_ADDR_CONVL          0x06
#define REG_ADDR_CONVH          0x07
 
unsigned int getData;
float analogVal = 0;

void setup() {
  
  Serial.begin(115200);

  Serial.println("ADC121C021");

  Wire.begin(21, 22, 3400000);

  init_adc();

}
 
void loop() {

  read_adc();
  
}

void read_adc() {
  Wire.beginTransmission(ADDR_ADC121);        // transmit to device
  Wire.write(REG_ADDR_RESULT);                // get result
  Wire.endTransmission();

  Wire.requestFrom(ADDR_ADC121, 2);           // request 2byte from device
  
  if (Wire.available()) {
    byte data = Wire.read();  // Read the received data
  }

}

void init_adc() {
  Wire.beginTransmission(ADDR_ADC121);        // transmit to device
  Wire.write(REG_ADDR_CONFIG);                // Configuration Register
  Wire.write(0x20);
  Wire.endTransmission();  
}

I'm using 3.4Mhz for the i2c and according to datasheet ADC121C021 supports that. Why am I getting only 5kHz?
Using esp32(tiny pico) with this code gives me 18kHz:

#include <esp_adc_cal.h>

#define ADC1_CHANNEL_32   ADC1_CHANNEL_4  // GPIO32
#define ADC_WIDTH      ADC_WIDTH_BIT_12  // ADC resolution
#define VREF_MV        3300  // Reference voltage in millivolts

esp_adc_cal_characteristics_t adc_chars;

uint32_t mic1Value;

void setup() {
  Serial.begin(115200);

  adc1_config_width(ADC_WIDTH);
  adc1_config_channel_atten(ADC1_CHANNEL_32, ADC_ATTEN_DB_11);
  
  esp_adc_cal_value_t cal_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_0, ADC_WIDTH, VREF_MV, &adc_chars);

  mic1Value = adc1_get_raw(ADC1_CHANNEL_32);

}

void loop() {

  mic1Value = adc1_get_raw(ADC1_CHANNEL_32);
  
}

Can I get better results?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.