main/sensors/src/mcp9808.c
int i2c_read_16(MCP9808_SENSOR_OPTIONS * options, uint8_t reg, uint16_t * data)
{
	i2c_cmd_handle_t cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (options->i2c_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
	i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
	i2c_master_stop(cmd);
	
	int status = i2c_master_cmd_begin(options->i2c_port, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);

    if (status != ESP_OK) {
        return SENSOR_STATUS_FAILED;
    }

    vTaskDelay(30 / portTICK_RATE_MS);

    uint8_t data_h, data_l;

    cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (options->i2c_address << 1) | I2C_MASTER_READ, ACK_CHECK_EN);

    i2c_master_read_byte(cmd, &data_h, ACK_VAL);
    i2c_master_read_byte(cmd, &data_l, NACK_VAL);

    i2c_master_stop(cmd);

	status = i2c_master_cmd_begin(options->i2c_port, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);

    *data = (data_h << 8) + data_l;
    return status == ESP_OK ? SENSOR_STATUS_OK : SENSOR_STATUS_FAILED;
}
// Read 16 bits data from the specified registry
Read 16 bits data from the specified registry
Read 16 bits data from the specified registry
int i2c_read_16(MCP9808_SENSOR_OPTIONS * options, uint8_t reg, uint16_t * data)
{
	i2c_cmd_handle_t cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (options->i2c_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
	i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
	i2c_master_stop(cmd);
	int status = i2c_master_cmd_begin(options->i2c_port, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);
    if (status != ESP_OK) {
        return SENSOR_STATUS_FAILED;
    }
    vTaskDelay(30 / portTICK_RATE_MS);
    uint8_t data_h, data_l;
    cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (options->i2c_address << 1) | I2C_MASTER_READ, ACK_CHECK_EN);
    i2c_master_read_byte(cmd, &data_h, ACK_VAL);
    i2c_master_read_byte(cmd, &data_l, NACK_VAL);
    i2c_master_stop(cmd);
	status = i2c_master_cmd_begin(options->i2c_port, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);
    *data = (data_h << 8) + data_l;
    return status == ESP_OK ? SENSOR_STATUS_OK : SENSOR_STATUS_FAILED;
}
int i2c_read_16 ( MCP9808_SENSOR_OPTIONS * options , uint8_t reg , uint16_t * data ) { i2c_cmd_handle_t cmd = i2c_cmd_link_create ( ) ; i2c_master_start ( cmd ) ; i2c_master_write_byte ( cmd , ( options -> i2c_address << 1 ) | I2C_MASTER_WRITE , ACK_CHECK_EN ) ; i2c_master_write_byte ( cmd , reg , ACK_CHECK_EN ) ; i2c_master_stop ( cmd ) ; int status = i2c_master_cmd_begin ( options -> i2c_port , cmd , 1000 / portTICK_RATE_MS ) ; i2c_cmd_link_delete ( cmd ) ; if ( status != ESP_OK ) { return SENSOR_STATUS_FAILED ; } vTaskDelay ( 30 / portTICK_RATE_MS ) ; uint8_t data_h , data_l ; cmd = i2c_cmd_link_create ( ) ; i2c_master_start ( cmd ) ; i2c_master_write_byte ( cmd , ( options -> i2c_address << 1 ) | I2C_MASTER_READ , ACK_CHECK_EN ) ; i2c_master_read_byte ( cmd , & data_h , ACK_VAL ) ; i2c_master_read_byte ( cmd , & data_l , NACK_VAL ) ; i2c_master_stop ( cmd ) ; status = i2c_master_cmd_begin ( options -> i2c_port , cmd , 1000 / portTICK_RATE_MS ) ; i2c_cmd_link_delete ( cmd ) ; * data = ( data_h << 8 ) + data_l ; return status == ESP_OK ? SENSOR_STATUS_OK : SENSOR_STATUS_FAILED ; }
Read 16 bits data from the specified registry
Read 16 bits data from the specified registry