cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32F4] Battery Voltage of Smart Battery via I2C

smrtkai
Senior
Posted on October 21, 2016 at 08:30

Hi,

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)

  {

    Error_Handler();

  }

}

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.
3 REPLIES 3
smrtkai
Senior
Posted on October 25, 2016 at 09:58

Can anyone recommend another forum, where this topic is more suitable?

michaelc.barton9
Associate II
Posted on October 25, 2016 at 16:52

what smart battery are you using ?

(the chip I mean!)

smrtkai
Senior
Posted on November 23, 2016 at 14:17

It is a National Power battery. The battery's name is NPC SM203-3.2 (Part Number 3SA72A06111BXSR)

The specification refers to this chip: http://www.ti.com/product/BQ20Z95