cancel
Showing results for 
Search instead for 
Did you mean: 

I2C IT RX callback with 2 slave address

bfran.1
Associate II

I have 2 slave i2c interfaced with master , Im working with HAL_I2C_MasterRxCpltCallback

I want select the slaves based with slave address , then I using the register hi2c1.Instance->CR2 & I2C_CR2_SADD for select them :

In the main I have :

// slave 1

HAL_I2C_Master_Transmit_IT(&hi2c1, I2C_ADDRESS_1, &regAddress, 1);

// slave 2

HAL_I2C_Master_Transmit_IT(&hi2c1, I2C_ADDRESS_2, &regAddress, 1);

void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)

{

{

if (hi2c1.Instance->CR2 & I2C_CR2_SADD== I2C_ADDRESS_1)

{

......

}

if (hi2c1.Instance->CR2 & I2C_CR2_SADD== I2C_ADDRESS_2)

{

......

}

}

My problem is that not work :

In debug the value of (hi2c1.Instance->CR2 & I2C_CR2_SADD) is fixed to zero .

I would like to know where I'm wrong, and above all .,

I would like to know where I am wrong, and above all I thought that in the main when I decide to transmit using HAL_I2C_Master_Transmit_IT to that particular address the field (hi2c1.Instance->CR2 & I2C_CR2_SADD)would be filled with that value(I2C_ADDRESS_1 or I2C_ADDRESS_2).

Can I have a working code.

THANKS

1 REPLY 1
bfran.1
Associate II

Sooryy the MCU is a STM32L4