Skip to main content
kevinliao
Associate II
January 28, 2015
Question

STM32 Cube HAL I2C DualAddressMode and Not DualAddressMode

  • January 28, 2015
  • 2 replies
  • 957 views
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
This topic has been closed for replies.

2 replies

kevinliao
kevinliaoAuthor
Associate II
January 29, 2015
Posted on January 29, 2015 at 05:17

Has some person can give me a hand?

Thanks a lot.
stm322399
Senior
January 29, 2015
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.