2024-07-22 03:57 AM
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);
}
}
2024-07-22 05:13 AM
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
2024-07-22 05:33 AM
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.
2024-07-22 05:43 AM
I imagine the syntax would be something like -
switch (hi2c->instance) {
case I2C1:
...
case I2C2:
....
I hope that helps.
Kind regards
Pedro
2024-07-22 05:51 AM
I'm sure it will, very many thanks.