Made BMX280 use a repeated start instead of two distinct starts.

This commit is contained in:
H. Utku Maden 2021-06-04 14:58:26 +03:00
parent 259ede3d5b
commit 7e49e7dacd

@ -142,13 +142,7 @@ static esp_err_t bmx280_read(bmx280_t *bmx280, uint8_t addr, uint8_t *dout, size
i2c_master_start(cmd);
i2c_master_write_byte(cmd, bmx280->slave | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, addr, true);
i2c_master_stop(cmd);
err = i2c_master_cmd_begin(bmx280->i2c_port, cmd, CONFIG_BMX280_TIMEOUT);
i2c_cmd_link_delete(cmd);
if (err == ESP_OK && (cmd = i2c_cmd_link_create()))
{
// Read Registers
i2c_master_start(cmd);
i2c_master_write_byte(cmd, bmx280->slave | I2C_MASTER_READ, true);
@ -157,8 +151,6 @@ static esp_err_t bmx280_read(bmx280_t *bmx280, uint8_t addr, uint8_t *dout, size
err = i2c_master_cmd_begin(bmx280->i2c_port, cmd, CONFIG_BMX280_TIMEOUT);
i2c_cmd_link_delete(cmd);
}
return err;
}
else
@ -173,10 +165,10 @@ static esp_err_t bmx280_write(bmx280_t* bmx280, uint8_t addr, const uint8_t *din
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
if (cmd)
{
i2c_master_start(cmd);
i2c_master_write_byte(cmd, bmx280->slave | I2C_MASTER_WRITE, true);
for (int i = 0; i < size; i++)
{
i2c_master_start(cmd);
i2c_master_write_byte(cmd, bmx280->slave | I2C_MASTER_WRITE, true);
// Register
i2c_master_write_byte(cmd, addr + i, true);
//Data