7 years, 2 months ago.

How to have i2C communication with four i2C devices in STM32l053.

Hi, I'm new to mbed and microcontrollers. I have four devices to be communicated with one microcontroller. I'm using STM32l053. In the datasheet i saw that i can have 2 i2C communications. How to handle four devices. Thank you.

2 Answers

7 years, 2 months ago.

I am assuming you are asking how to communicate with four devices with the same I2C address on a single I2C bus.

There are two ways.

Most I2C devices allow setting the I2C address of the device to one of two addresses usually distinguished by the last (Least Significant) bit. For example, the MPU6050 IMU (motion sensor) has an address pin ADO which when set LOW the I2C address is 0x68 and when set HIGH the I2C address is 0x69. Now if you have four of these on the same I2C bus, what you can do is connect each of their ADO pins to an STM GPIO and set them all to LOW except the one you want to poll, set its ADO HIGH. Then by polling the MPU6050 with the address 0x69, you will read data from just that one. Then toggle the ADO to LOW for the device just read and toggle the ADO HIGH for the next one to read, etc.

Or, by a breakout board with a TCA9548A I2C multiplexer (https://www.tindie.com/products/onehorse/tca9548a-i2c-multiplexer/) and you can connect up to eight (or 64 if you gang these boards together) I2C devices with the same address and control the polling by opening and closing channels via I2C writes to the TCA9548A. This can save on GPIO pins from the microcontroller.

Accepted Answer

Thank you. Its solved.

posted by Mohan gandhi Vinnakota 10 Jul 2015
7 years, 2 months ago.

I2C devices have a device address on them - many times it is dip switch settable or little solder pads that can be set. Be careful of the devices to make sure that you can re-address them. Since each device has its own address - they can all be connected to the same I2C interface pins - don't forget to add the appropriate pull-up resistors. Your program will have to keep track of which device you are talking to - based on the address. Part of the comm protocol includes the device address - - this is just the broad overview of I2C.........HTH

My four sensors are different. And they have different address for each. Here I'm connecting with four different i2C buses.

First device PB7-I2C1-SDA PB6-I2C1-SCL

second device PB8_I2C1-SCL PB9-I2C1-SDA

Third device PB11-I2C2-SCL PB10-I2C2-SDA

Fourth device PB14-I2C2-SDA PB13-I2C2-SSCL

When i connect one device to the controller i could see the result. For two devices also i could see the output. But when i connect three devices, I could see nothing. For four devices also nothing.

What could be the problem??

posted by Mohan gandhi Vinnakota 10 Jul 2015

Problem solved. The problem is i was connecting four sensors on four different bus. Now i connected all of four on single bus. It's working. thank you for your quick response.

posted by Mohan gandhi Vinnakota 10 Jul 2015