function to read the register:
Code: Select all
void Reset_Si7021(void)
{
uint8_t Stored_Value;
esp_err_t Get_I2C_Response = ESP_OK;
printf(" Reset fn. start");
// Reading the User Reg.
i2c_cmd_handle_t CMD = i2c_cmd_link_create();
i2c_master_start(CMD);
i2c_master_write_byte(CMD, (Si7021_ADDR << 1) | Write_Bit, Want_Ack);
i2c_master_write_byte(CMD, 0xE7, Want_Ack); // read user reg.
i2c_master_start(CMD);
i2c_master_write_byte(CMD, (Si7021_ADDR << 1) | Read_Bit, Want_Ack);
Get_I2C_Response = i2c_master_read_byte(CMD, &Stored_Value, NACK_VAL);
i2c_master_stop(CMD);
i2c_master_cmd_begin(I2C_NUM_0, CMD, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(CMD);
if( Get_I2C_Response == ESP_OK)
{
printf("\nStored User Reg. Data: %X\n",Stored_Value);
}
else
{
printf("\nReset fn. Error\n");
}
}, how ever when i move this function in another .h file the resultsStored_Value = 18
become
Stored_Value = 15
When I do this
Code: Select all
i2c_master_read_byte(CMD, &Stored_Value, NACK_VAL);
i2c_master_stop(CMD);
Get_I2C_Response = i2c_master_cmd_begin(I2C_NUM_0, CMD, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(CMD);
if( Get_I2C_Response == ESP_OK)
{
printf("\nStored User Reg. Data: %X\n",Stored_Value);
}
else
{
printf("\nReset fn. Error\n");
}Reset fn. Error
what could be the mistake I did in the code? ( I don't have a logic analyzer at the moment)