Skip to main content
Alexmouse
Associate III
July 22, 2024
Question

Filtering i2c interrupts by i2c module

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);

}

}

This topic has been closed for replies.

5 replies

PGump.1
Senior II
July 22, 2024

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
AlexmouseAuthor
Associate III
July 22, 2024

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.

PGump.1
Senior II
July 22, 2024

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
AlexmouseAuthor
Associate III
July 22, 2024

Looks like this might be might my solution:

 

if(hi2c->Instance==I2C1)

{

...

}

else if(hi2c->Instance==I2C2)

{

...

}

else if(hi2c->Instance==I2C3)

{

...

}

else if(hi2c->Instance==I2C4)

{

...

}

Alexmouse
AlexmouseAuthor
Associate III
July 22, 2024

I'm sure it will, very many thanks.