Call i2c_init() before i2c_frequency() (since i2c_frequency() requires the object to be set up) and zero the I2C object before giving it to i2c_init() as i2_init() has to set up a default frequency for its timeouts to work and it will only do this if the hz field in the object was zero to begin with (otherwise you end up with a random but usually very large indeed timeout).

pull/6246/head
Rob Meades 2018-03-01 14:52:42 +00:00
parent ae788f7384
commit c53fb9dc64
1 changed files with 2 additions and 2 deletions

View File

@ -27,10 +27,10 @@ void HAL_MspInit(void)
void set_minimum_battery_voltage()
{
i2c_t i2c_obj;
i2c_t i2c_obj = {0};
int data_read;
i2c_frequency(&i2c_obj, I2C_FREQUENCY);
i2c_init(&i2c_obj, I2C_SDA_B, I2C_SCL_B);
i2c_frequency(&i2c_obj, I2C_FREQUENCY);
if (read_from_i2c(BQ24295_I2C_ADDRESS, 0, &data_read, i2c_obj)) {
data_read = data_read & MIN_BATTERY_VOLTAGE_MASK;