cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone, ı want to use 4 mpu6050 with 1 stm32. My question; How ı use multi slave with one i2c channel from stm32-nucleo-f401re ?

hybnomsX
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Bob S
Principal

One. More. Time.

There is an address pin on the MPU-6050. Ground the "AD0" pin on one board and tie it to VCC on the other board. Look at the data sheet to see what the two addresses are. Connect those two boards to one I2C bus. Then repeat that on the 3rd and 4th boards and connect them to a second I2C port.

Or - get an I2C MUX (for example, https://www.adafruit.com/product/2717), connect that mux to the I2C port, then connect the 4 sensors to the 4 ports on the mux. You may need to add pull-up resistors on the mux ports - check the data sheet/schematic to see.

Or - as @Community member​ mentioned, each I2C port is usually available on more than one set of pins on the STM32. By re-configuring the GPIO pins and their "alternate function" mapping, you can have a single I2C port on multiple pairs of pins (but only one pair at a time).

View solution in original post

9 REPLIES 9
Bob S
Principal

It looks like the mpu-6050 has only one address select line. Which means at most 2 of these can be placed on a single I2C bus.

Unless you can add external I2C bus buffers/isolators, or an I2C Mux. Then you can turn the isolators on/off to each mpu-6050, or switch the mux to each unit one at a time.

The F401 has several I2C ports. Is there some restriction limiting you to only using one?

hybnomsX
Associate II

i managed use 1 mpu6050 but i need use 4 mpu6050 with stm32. But f401 has 3 i2c channel.

Check how many pins any specific I2Cx SCL signal can be mapped.

Then multiplex between them.

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

how to multiplex between them. can ı read 4 mpu6050 angle from one i2c channel ? is it possible??

Bob S
Principal

One. More. Time.

There is an address pin on the MPU-6050. Ground the "AD0" pin on one board and tie it to VCC on the other board. Look at the data sheet to see what the two addresses are. Connect those two boards to one I2C bus. Then repeat that on the 3rd and 4th boards and connect them to a second I2C port.

Or - get an I2C MUX (for example, https://www.adafruit.com/product/2717), connect that mux to the I2C port, then connect the 4 sensors to the 4 ports on the mux. You may need to add pull-up resistors on the mux ports - check the data sheet/schematic to see.

Or - as @Community member​ mentioned, each I2C port is usually available on more than one set of pins on the STM32. By re-configuring the GPIO pins and their "alternate function" mapping, you can have a single I2C port on multiple pairs of pins (but only one pair at a time).

One I2C peripheral, not sure, I'm not going to do the due-diligence on this for you.

I do believe there's more than one pin that each I2Cx peripheral can map to the SCL

You'd configure them as GPIO or AF, with a pulled-high OD, and you'd cycle which is internally connected to the SCL of the peripheral.

I think you only need to switch the SCL (clock) pin, the unconnected slave(s) won't see an active bus, and won't respond.

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

I understand what you mean. I will change the address by applying different voltage(0-1) to the ad0 pin of the mpu 6050 and I will communicate from 2 sensors over a single i2c pin.

If I use the multiplexer in the link you shared, how will I know which mpu6050 has which address?

Moreover,Thank you very much for your reply. it will work for me.

Thx for answer

If you use the MUX, then all four MPU-6050 units can have the same address. You send a command to the MUX (at its own I2C address) to tell it which port you want to talk to. For example, if you connect the sensors to mux ports 0 to 3:

  • send command to MUX to connect to port 0
  • read sensor data from sensor 1
  • send command to MUX to connect to port 1
  • read sensor data from sensor 2 (same I2C address as sensor 1)
  • send command to MUX to connect to port 2
  • read sensor data from sensor 3 (same I2C address as sensor 1)
  • send command to MUX to connect to port 3
  • read sensor data from sensor 3 (same I2C address as sensor 1)