Skip to main content
Mohan1
Associate III
September 28, 2019
Question

How to run I2C communication between STM32L476RC controller and BQ40Z50R2?

  • September 28, 2019
  • 8 replies
  • 2835 views

I am trying to do I2C communication between STM32L476RC and Fuel gauge IC(BQ40Z50R2),for that i am using following components:

1) STM32L476RC Controller

2) BQ40Z50R2 Fuel gauge IC

3) STM32 CubeMx software

4) Keil software

The datasheet of fuel gauge is http://www.ti.com/lit/ds/symlink/bq40z50-r2.pdf and datasheet of STM32L476RC is https://www.st.com/resource/en/datasheet/stm32l476rc.pdf.

I tried to write a code to take data(voltage,current and temperature) from fuel gauge where 3.7v Li-Ion battery is connected.To writting a code of I2C communication with Stm32l476 is getting little bit tough because nowhere given a single I2C program with this STM32L476 controller.

I initialise I2C pins in CubeMx and code is generated in keil. Then in while loop i used HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive but not getting output in watch window ,also i checked it on oscilloscope but scl and sdl line shows just a dc horizontal line. Also I used HAL_I2C_Mem_Read,but not working.

I edited the code only in while ,rest of the code is generated by CubeMx.I am facing following problems: 1) My code is not giving any output 2) I am checking output on watch window in keil,is it right or wrong?

This topic has been closed for replies.

8 replies

Tesla DeLorean
Guru
September 28, 2019

Dupe https://community.st.com/s/question/0D50X0000BNv93USQR/communication-between-stm32l476rc-and-fuel-gaugebq40z50r2-through-i2c

What pins specifically are you using?

I2C examples like

STM32Cube_FW_L4_V1.14.0\Drivers\BSP\STM32L476G-Discovery\stm32l476g_discovery.c  

Or ten or so around

STM32Cube_FW_L4_V1.14.0\Projects\STM32L476G-EVAL\Examples\I2C\I2C_EEPROM  

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mohan1
Mohan1Author
Associate III
September 29, 2019

Thanks for your response sir, I am using I2C pins that is SDA and SCL.

Tesla DeLorean
Guru
September 29, 2019

No, what pins on the chip, the number or GPIO bank.

Which I2C peripheral.

You fail to provide a sufficient level of detail, or coding, to understand​ what you are doing wrong.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
September 28, 2019

I do beleive that if there was a utility function to get started with SW emulated bitbang Master I2C would reduce drastically all these posts about I2C or SPI maydays.

My bitbang I2C shared in this forum works like a charm and evolved since its inception in 1999... Never failed, works through hot plug unplug with most non-clock stretching slave spectrum.

Mohan1
Mohan1Author
Associate III
September 29, 2019

Thanks for your response sir,but sir i am very new to this STM32 environment.So i dont know what should i do with this bitbang I2C that you shared.Can you please elaborate it clearly.Sorry sir but please.

Thanks

Mohan