AnsweredAssumed Answered

[STM32F4] Battery Voltage of Smart Battery via I2C

Question asked by smrtkai on Oct 21, 2016
Latest reply on Nov 23, 2016 by smrtkai

I have a STM32F4 which is powered by a smart battery. I would like to read the remaining capacity (AbsoluteStateOfCharge, RelativeStateOfCharge). I am not able to figure out, how I have to configure I2C so that I can communicate with the smart battery. 

My latest attempt was to read the device name, but I do not know how many bytes I am expecting.

hal_status = HAL_I2C_Mem_Read(&hi2c1, 0x0B, 0x21, I2C_MEMADD_SIZE_8BIT, (uint8_t*) my_device_name, 5, 100);

Device Address: 0x0B - SMBus specification
Mem Address: 0x21 - Device Name

The I2C interface is configured like this:

void MX_I2C1_Init(void)
  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 100000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = 0x08;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)

I am not sure, if this is correct at all. Can anyone tell, if I am the right track? Or has anyone a working example? I am really lost, right now.

Thanks in advance.