How to communicate with multiple slaves at the same time in I2C communication

Needless to say, modules with different addresses can communicate with their addresses directly. So what if you get a module with the same address, or multiple modules with the same address?

Method 1: (modules with two built-in addresses)
For a module with two built-in addresses, one of the addresses can be selected by setting a pin high or low, set the high to A and set the low to B .
Suppose you have three modules to communicate at the same time. First, set module 1 high and the address selection ports of module 2 and module 3 low, so that only module 1 is at address A, and then communicate with address A to prevent other modules from interfering. Next, set module 1 to low and module 2 to high to communicate with module 2. The cycle can continue to realize the communication to the three modules at the same time.

Method 2: (Module with enable terminal)
If a pin of the module in your hand must be pulled down or pulled up to be used normally, then follow the method 1, enable one of them, and the others are in the disabled state. You can communicate with only one of the modules.

If none of the above works, there is only way three.

Universal method 3: (Nothing, only one address module)
Originally bought six ADXL345 to read acceleration information in different places, the datasheet says that one of the addresses can be selected by setting a pin high and low . However, it is found that the address cannot be changed! So I had to think of such an evil method.

The tool used is an analog switch. The original poster took CD4053 as an example. This product is very cheap, and you can buy a lot for a few yuan.

Simply put, the analog switch is equivalent to multiple single-pole double-throw switches, which can control certain two-way connection through the IO port output high and low level.
We know that I2C communication has two lines, SCL and SDA. By adjusting the analog switch so that only one module is completely connected to the I2C BUS, it can communicate with only one of them.

Specific implementation:
Assume that there are modules 1 2 3
CD4053 ay by cy suspended ax bx cx and connected to the SCL of the microcontroller,
connect the SCL port of module 1 to port a of CD4053,
connect the SCL port of module 2 to port b of CD4053, and
connect module 3 the c-CD4053 SCL port access port
so simply set high a low B, C is set, the module 1 can communicate with
it Similarly, B will be set high, low a, C is set, to the communication module 2 and
hence In the same way, set C to high, and A and B to low to communicate with module 3.

However, please note that both CD4053 VEE and VSS must be grounded, otherwise the reading will be unstable and the host will be stuck here for a long time.

Transfer from: https://www.cnblogs.com/schips/p/10795711.html

Guess you like

Origin blog.csdn.net/qq_45467083/article/details/109488059