cancel
Showing results for 
Search instead for 
Did you mean: 

MPU6050 I2C communication stops with STM32F411 (out of sync?)

Billy1
Visitor

So I'm trying to configure communication with the MPU6050 from the STM32 Black Pill module using the driver from anasvag575, I reconfigured the driver to LL library because the driver used the standard library and I don't want it to become a mess later.

The problem I'm facing now is that it seems like the thing stopped working when it after calling LL_I2C_TransmitData8 and it just stuck waiting for the ADDR bit to be set but that never happened. The logic shows that it generated the start correctly but the address is very inconsistent when I test it by resetting it

0x68.png

0x66.png

  

Sometimes it generated the correct address, sometimes SCL goes high at the same time as SDA. I've tried changing the I2C speed configuration but sometimes it makes worse where SCL can't even transfer a bit.

I've tried different libraries but obviously none of them really worked, some got stuck waiting for the start bit flag instead.

 

static inline void i2c_write_data(I2C_TypeDef *i2c_handle, uint8_t address, uint8_t *data, uint8_t num_of_data)
{
  uint8_t i;

  LL_I2C_Enable(i2c_handle);

  LL_I2C_GenerateStartCondition(i2c_handle);
  while (LL_I2C_IsActiveFlag_SB(i2c_handle) == 0);

  LL_I2C_TransmitData8(i2c_handle, address);
  while (LL_I2C_IsActiveFlag_ADDR(i2c_handle) == 0);

  LL_I2C_ClearFlag_ADDR(i2c_handle);

  for(i = 0; i < num_of_data; i++){
    while(LL_I2C_IsActiveFlag_TXE(i2c_handle) == 0);
    LL_I2C_TransmitData8(i2c_handle, data[i]);
  }

  while(LL_I2C_IsActiveFlag_BTF(i2c_handle) == 0);

  LL_I2C_GenerateStopCondition(i2c_handle);

  LL_I2C_Disable(i2c_handle);

}

 

2 REPLIES 2
Andrew Neil
Super User

Welcome to the forum.

Please see How to write your question to maximize your chances to find a solution for best results.

In particular, please give full details of your hardware setup - post a schematic of how the sensor is connected; some good, clear photos can also help.

 


@Billy1 wrote:

The logic [analyser?] shows that it generated the start correctly but the address is very inconsistent

Have you looked at the lines with an oscilloscope?

A logic analyser assumes that you have good, clean digital signals - a scope will show if that assumption is true or not ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User

Take an analog capture and ensure the edges are clean enough.

Are external pullup resistors in the 2.2 kOhm range present?

If you feel a post has answered your question, please click "Accept as Solution".