cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Cube HAL I2C DualAddressMode and Not DualAddressMode

kevinliao
Associate II
Posted on January 28, 2015 at 08:18

Hi Guys,

I used the STM32L152 mcu, and used the CubeMX tool to generate sample code and HAL code.

I have two I2C devices, one is OLED, one is EEPROM (AT24C512).

The question is the OLED is one address, but the EEPROM has dual address.

I need use the one I2C to drive the OLED and EEPROM.

How to set the I2C register?

  hi2c2.Instance = I2C2;

  hi2c2.Init.ClockSpeed = 100000;

  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;

  hi2c2.Init.OwnAddress1 = 0;

  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;

  hi2c2.Init.OwnAddress2 = 0;

  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;

  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;

  HAL_I2C_Init(&hi2c2); 

Maybe I need change the register dynamic?

Is it possible to work?  

By the way, How to set the value of OwnAddress1 and OwnAddress2? 

 

Thank you.

Kevin

#stm32 #i2c #eeprom
2 REPLIES 2
kevinliao
Associate II
Posted on January 29, 2015 at 05:17

Has some person can give me a hand?

Thanks a lot.
stm322399
Senior
Posted on January 29, 2015 at 12:51

Your MCU is likely to be the I2C master, there is no need to care about ''own address'' nro ''dual address mode'', because those are I2C slave features.

You only are required to init your I2C controller as master, then perform read and writes to sensors wrt. their functional descriptions.