Skip to main content
Explorer
Question

How to find default address of an STM32 for I2C communication

Hey, I’m trying to make 2 stm32 MCU’s communicate with each other over i2c. In order to do that of course I would need the address of the chip to put into the transmit function. Theyre STM32U575ZITQ6 to be exact, and theyre on nucleo STM32U575 144 pin boards. I am quite new to STM32 and am not quite sure where I could find these addresses, possibly in the reference manual or data sheet in an i2c section but not sure where specifically to look for that - any insights would be much appreciated?

Another quick question - what type of address is this typically named as? For example when communicating stm32 to temperature sensor there was the default address which was put in the codes transmit function (I think that’s what I’m looking for but confirmation would be helpful but also a register address, etc.

Thanks!

2 replies

Karl Yamashita
Super User

​@Savannah_Dare 

Only the STM32 configured as an I2C slave needs a slave address. The STM32 acting solely as the master does not require one.

Assuming you're using STM32CubeMX, simply assign a unique slave address that does not conflict with any other slave devices sharing the same I2C bus. Also, make sure the assigned address is not within the I2C reserved address range.

Keep in mind that the STM32 HAL I2C master functions require the 7-bit slave address to be left-shifted by one bit when passed as the device address parameter. For example, if a temperature sensor has a 7-bit slave address of 0x40, you would pass it as (0x40 << 1), which is equivalent to 0x80.

 

 

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Associate

One thing worth adding to Karl's answer: unlike a sensor, an STM32 has no factory default I2C address of its own. The slave address is whatever you program into it, so you choose it rather than look it up. In CubeMX you set it under the I2C peripheral configuration as Own Address 1 (7-bit), and that value is what the master has to target. The other address you mentioned, the one in the sensor example, is the register address inside the sensor, which is a different thing from the slave address on the bus. If you are debugging the link, a quick check is to have the master scan the bus with HAL_I2C_IsDeviceReady across the address range and confirm your chosen address answers before you start moving real data.