tobymurray / ESP32-ads1115

Use ESP-IDF to read an ADS1115
1 stars 1 forks source link

not getting ACK while reading ADS #1

Open ghost opened 2 years ago

ghost commented 2 years ago

hello, I'm working on a project where Im using the ads1115 with esp32 . Im using ESPIDF v4.2 in let me know if you getting feel any update or need to change here. // Select configuration register(0x01) // AINP = AIN0 reading voltage // Continuous conversion mode, 128 SPS(0xC1, 0x83)

hardware is fine and working I checked in Arduino IDE but here I'm only getting reading 0x5E, 0x5E

static esp_err_t i2c_master_sensor_test(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, 0x90, 0x01);
  i2c_master_write_byte(cmd, 0x01, 0x01);
  i2c_master_write_byte(cmd, 0xC1, 0x01);
  i2c_master_write_byte(cmd, 0x83, 0x00);
  i2c_master_stop(cmd);
  ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
  i2c_cmd_link_delete(cmd);
  if (ret != ESP_OK) {
    return ret;
  }
  vTaskDelay(30 / portTICK_RATE_MS);
  cmd = i2c_cmd_link_create();
  i2c_master_start(cmd);
  i2c_master_write_byte(cmd, 0x91, 0x01);
  i2c_master_write_byte(cmd, 0x00, 0x01);     //..............<< here not receving ACK
  i2c_master_read_byte(cmd, data_h, 0x00);
  i2c_master_read_byte(cmd, data_l, 0x01);
  i2c_master_stop(cmd);
  ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
  i2c_cmd_link_delete(cmd);
  printf(" >> data_h: %X\n", *data_h);
  printf(" >> data_l: %X\n", *data_l);
  return ret;
}
tobymurray commented 2 years ago

I've been away from this project for ~3 years, to the point where I'm not sure I recall much of my own code. Make sure to check your physical terminations, avoid using a breadboard (they're the cause of like 95% of my unexpected failures), and shorten the wires for your i2c communication as much as is practical.

Good luck!