cancel
Showing results for 
Search instead for 
Did you mean: 

How to use cubemx to genrate code to add multiple I2C salve devices or sensor to STM32F423 I2C channel in same port.

sh.310
Associate

Am creating a I2C communicaton hub , where i have more than 20 sensor which is having I2C comunication. thing is i need connect all this sensor with in 2 I2C port. am getting confusion. how to write the code implementtion for same above using stm cube.

3 REPLIES 3
S.Ma
Principal

Why not use a step by step approach? Have a look at my shared GPIO I2C bus implementation code in this forum? It includes some examples of exotic I2C sensors and has a generic definition of slave device (struct) which works fine. Later, you can replace the SW I2C by HW I2C at low level.

CubeMX has yet to generate code by drag and drop a BOM (bill of material) and user's prefferences.

AvaTar
Lead

> thing is i need connect all this sensor with in 2 I2C port. am getting confusion

The I2C bus was designed for this purpose, he uses addresses to differ between devices.

Be aware that many slave devices have fixed addresses, or very limited options to set the address. Just like with TCP/IP and CAN, the bus will stop working if addresses are not unique.

If Cube could spit out all the required application code by itself, you would not be needed anymore.

S.Ma
Principal

If you have many identical sensors with only 1 pin to have 2 possible slave address, you are in luck: you can use an I2C IO Expander connected to all these address select pins of these sensors and use the io expander to have one sensor with a unique address among other so you can pinpoint which one to talk to. Handy when having lots of sensors to put in a thermal chamber....