Skip to main content
Visitor II
December 20, 2024
Solved

Best practices for I2C driver architecture

  • December 20, 2024
  • 2 replies
  • 1142 views

Hi,

I want to use a single low-level module to handle up to three I2C buses at the same time using the HAL library and using the interrupt for all communications with the relative callback. Is it possible to use a single write/read/callback function for all transactions on all three buses at the same time. Are there any problems if the callback is interrupted to handle another interrupt of another I2C bus with higher priority?

Best regards,

Domenico

    This topic has been closed for replies.
    Best answer by TDK

    Should be no problems doing this with HAL. Get one instance working first and it should be straightfoward to move to multiple. They will all use different handles.

    I2C interrupts pre-empting should not cause issues. However I2C is so slow compared to interrupt execution speed that I'd set them all at the same priority.

     

    2 replies

    Graduate II
    December 20, 2024

    As long as you have different data buffer or structure for each bus then you will be fine. But if you are sharing the same data buffer, then you'll get conflicts as 1 of the bus will over write the other bus data.

    TDKAnswer
    Super User
    December 22, 2024

    Should be no problems doing this with HAL. Get one instance working first and it should be straightfoward to move to multiple. They will all use different handles.

    I2C interrupts pre-empting should not cause issues. However I2C is so slow compared to interrupt execution speed that I'd set them all at the same priority.

     

    Visitor II
    December 30, 2024

    Ok, thanks for your solution.