ControlEverythingCommunity / ADC121C021

1-Channel 12-Bit Analog to Digital Converter
7 stars 4 forks source link

Reading by FreeRTOS #2

Open iotdevoted45 opened 1 year ago

iotdevoted45 commented 1 year ago

hello @ryker1990

I'm trying to read ADC count by I2C based ADC121C021 module with help of this code but Im only getting ESP_FAIL

static esp_err_t read_ADS(i2c_port_t i2c_num, uint8_t *data_h, uint8_t *data_l){
  int ret;
  i2c_cmd_handle_t cmd = i2c_cmd_link_create();
  i2c_master_start(cmd);
  i2c_master_write_byte(cmd, ADS_ADDRESS | WRITE_FLAG, 0x01);
  i2c_master_write_byte(cmd, 0x00, 0x00); 
  i2c_master_stop(cmd);
  ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);    // (here fun return)
  i2c_cmd_link_delete(cmd);
  if (ret != ESP_OK) {
    return ret;
  }
  vTaskDelay(400 / portTICK_RATE_MS);
  cmd = i2c_cmd_link_create();
  i2c_master_start(cmd);
  i2c_master_write_byte(cmd, ADS_ADDRESS | WRITE_FLAG, 0x01);
  i2c_master_write_byte(cmd, 0x20, 0x01);
  i2c_master_stop(cmd);
  ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
  i2c_cmd_link_delete(cmd);
  cmd = i2c_cmd_link_create();
  i2c_master_start(cmd);
  i2c_master_write_byte(cmd, ADS_ADDRESS | READ_FLAG, 0x01);
  i2c_master_read_byte(cmd, data_h, ACK_FLAG);
  i2c_master_read_byte(cmd, data_l, NACK_FLAG);
  i2c_master_stop(cmd);
  ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
  i2c_cmd_link_delete(cmd);
  return ret;
}

let me know if I'm doing something wrong. One more point I tried the Arduino based example where if I used the salve Address 0x50 its not working but If I used 0x58 its working totally fine for me Jumpers are open (for Pull_up and Address)

iotdevoted45 commented 1 year ago

It's been more than 15 days now. I don't think anyone is active here ..