cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446 I2C connection, weird behaviour with MPU6050 and HMC5883L

Isoclem
Associate III

Hello everyone,

 

I'm trying to use MPU6050, HMC5883L and MS5611 all together in a project with an STM32F446RE. The problem is, while every components all work fine alone, when is use MPU6050 and HMC5883L together, it doesn't work. By not working, I'm meaning that the datas collected are all wrong. What's also weird is that : MPU6050 and MS5611 work fine together, same for HMC5883L and MS5611.

So let's focus on MPU6050 and HMC5883L only I guess...

 

For the connections I just did that :

board.drawio (1).png

So in my case, I connect the two sensors to the same SCL and SDA. Which should work, but I suspect that the problem might come from this connection. Indeed, even thought I'm assuming the right addresses are written in the code, could it be possible that troughout I2C, parts of the data are overwritten ? If so, what can I do ?

 

 

If you have any other ideas of where the problem could be, feel free to share it ^^

 

I attached all the code i use. 

Thanks for your help !

 

18 REPLIES 18

So I tried using 10k resistors as pull up resistors, I obtain the datas I need for the MPU6050 but not for the HMC5883L... (while the two are connected on the board). So it indeed seems to be the problem.

 

I also found a post (using an arduino) with someome having the same problem as me. He solved it by using a shifter : 

 

5266e578757b7fe84c8b456f.png

 


With that in mind, I guess it's possible to make my own level shifter ? 🙂 (I don't have one :/)

So i'm going to try that out tomorrow and keep you updated...

 

 

So whats the voltage, your adapter using ?

AScha3_0-1716393722861.png

If 1.8V, you need a level shifter .

STM32 is a 3v3 system (except you go for ultra low power, but then other problems coming.).

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

I'm using my STM32F446RE connected to my pc with USB. Connected via 3v3 or 5v the problem stays the same...

 

I don't really understand what you mean by "adapter" 🙂

 

edit : I also find out, it's by connecting SCL from HMC5883L to the board that datas are getting wrong

I think we all have reasonable access to the part data-sheets.

The problem here is the variety of BOARDs you're using, with a whole lot of other attendant circuitry, often regulators, level shifters and pull-ups. It's the interaction of all these parts that results in the type of problems being discussed here.

What you NEED to do is be more specific about the EXACT MODULEs you're stringing together and THEIR circuit diagrams.

Some good photographic imagery, ie Large and In Focus, might establish the specific board design and vendor, as one design is frequently cloned, and futzed (BoM reduction) by several dozen vendors.

The reason I suggested the GY-86 was that ALL the individual parts were on ONE board, and hopefully the problem was thought through more completely without a lot of externals unknowns being introduced into the problem/circuit analysis.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I suspect each board has pull-ups /shifters, and arranged in a star configuration bus. Generally viewed as non-ideal for I2C. Flying 10cm dupont wires not really contributing well to a flat/linear I2C bus topology. Plug the headers into the bread board, and put half the cables back in the bag/box..

The level shift being to address needs of 5V Arduino Makers vs 3.3V of most modern CMOS for the last 3 decades.. not to mention 1.8V and 1.2V systems common in lower power CMOS

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ok 🙂

 

So I removed most of the cables as you adviced me.

I understand for the level shifter.

For the pics, I have a poor quality camera with my phone but here it is :

 

1716400547181.jpg1716400547191.jpg

 

For the first sensor on the first photo it is the magnetometer behind it is written GY-271 and HW-246

On the "chip" it is written "HA 5883 2131".

The second sensor is the mpu I can't really read what's written on the chip.

I can give you all the links where i bought everything :

For the MPU6050

For the HMC5883L

 

Hope it helps :\

Thanks for your help 🙂 !

The Green is the pull-up / level shifter, the Orange is the "5V/VIN" side 2K2's.

The Red is the 3V3 Regulator

1716400547181_markedup.jpg

I'd probably lose the orange resistors and the 6-pin IC, and then bridge the SCL/SDA at the pull-up to the respective pads on the ones removed.

gy_85_level.jpg

gy_85_level_modded.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

GY-271

http://wiki.sunfounder.cc/index.php?title=GY-271_HMC5883L_3-Axis_Magnetic_Electronic_Compass_Module

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Since I'm newbie, can you tell me how to do this operation ? So I don't destroy everything on the way.... x) 

Also, would this have any impact on my code ? (address reading ?)

 

And last question, what led you to this conclusion ? 🤔

Again thanks a lot !