Skip to main content
neovius
Associate
Feb 28, 2019 9:48 AM UTC
Solved

Bug STMF1x CubeMX I2C Slave Address

When setting the primary slave address for I2C in cubeMX for the STM32F1xx

The generated code will be the address * 2.

This created address is incorrect. The address should not be multiplied by 2.

for example:

Set I2c Slave address to 0x50

Generated code sets the OwnAddress to : 160. which is (0x50 * 2)

The st does not response to the address 0x50, because the ownAddress is set to another value.

This topic has been closed for replies.
Andreas Bolsch
Andreas BolschBest answer
Lead III
Feb 28, 2019 11:00 AM UTC

No, that's not a bug. The I2C address (7-bit) is transmitted left justified in the corresponding byte, bit 0 is the R/W bit. The description of I2C_OAR1 shows clearly that the address is left justified there, too.

3 replies

Andreas Bolsch
Andreas BolschBest answer
Lead III
Feb 28, 2019 11:00 AM UTC

No, that's not a bug. The I2C address (7-bit) is transmitted left justified in the corresponding byte, bit 0 is the R/W bit. The description of I2C_OAR1 shows clearly that the address is left justified there, too.

neovius
neoviusAuthor
Associate
Feb 28, 2019 11:10 AM UTC

Ah I didn`t read the description of the "Primary slave address" input field. I though that the address that i put in the field, is the write address of the ST.

But apparently the address i put i the field is the non shifted address.

Khouloud ZEMMELI
ST Employee
Feb 28, 2019 1:38 PM UTC

​Hello @neovius​ 

The generated value of the adress is shifted left by 1 bit( as it's indicated in the screenshot) , that's why you find 160 instead of 80 in your code.

(thank you @Andreas Bolsch​  for the quick answer.)

Regards,

Khouloud.

0690X000006Dun4QAC.png