cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering i2c interrupts by i2c module

Alexmouse
Senior

I'm working with the STM32U575 and using all four i2c blocks. My i2c code is interrupt driven.

I can't find the right way to check which i2c block trigered the interrupt, suggestions please?

 

void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t direction, uint16_t addrMatchCode) {

if(direction == I2C_DIRECTION_TRANSMIT) {

// master is sending, start first receive

// if the master is writing, it always writes the address first

HAL_I2C_Slave_Seq_Receive_IT(hi2c, &word_addr_byte, 1, I2C_NEXT_FRAME);

} else {

// master is receiving, start first transmit

word_addr = EEPROM_OFFSET(word_addr);

 

HAL_I2C_Slave_Seq_Transmit_IT(hi2c, &ram[word_addr], 1, I2C_NEXT_FRAME);

}

}

4 REPLIES 4
PGump.1
Senior

I don't use Callbacks, I write directly into the Interrupt service.

However, I imagine that you'll have to compare the 'instance' portion of the 'hi2c' structure to the I2C block pointer...

I hope that helps.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.
Alexmouse
Senior

That's what I'm trying to do but I've not found a way to express it that the compiler likes. I've done the same thing before with Timer interrupts but that seemed to be much easier. I was hoping to find some examples on the web but didn't find any.

I imagine the syntax would be something like -

    switch (hi2c->instance) {
         case I2C1:
           ...

         case I2C2:
           ....

 

I hope that helps.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.
Alexmouse
Senior

I'm sure it will, very many thanks.