Skip to main content
Explorer
December 26, 2021
Question

How to abort HAL_I2C_Slave_Transmit_IT

  • December 26, 2021
  • 1 reply
  • 1491 views

HAL_I2C_Master_Transmit_IT can be aborted via HAL_I2C_Master_Abort_IT.

But how to abort HAL_I2C_Slave_Transmit_IT?

There does not appear to be a corresponding abort function.

If a callback complete does not occur, the software should be capable of aborting the slave transmit, but there does not appear to be a function to do that.

    This topic has been closed for replies.

    1 reply

    Super User
    December 26, 2021

    There's a discussion here but it didn't get any traction with ST. Not sure the question was understood.

    https://community.st.com/s/question/0D50X00009XkWUcSAN/how-to-deactivate-hali2cslavereceiveit

    It looks like HAL_I2C_Init does the proper things here. Doesn't reinitialize pins, resets the peripheral, set state to ready, etc. NVIC interrupt will still be enabled but doesn't matter if it's not enabled on the I2C side.

    Of course, de-initializing the peripheral in the middle of a transfer will lead to nonstandard behavior, so use at your own risk. Perhaps that is why they don't have an explicit Abort function.

    Explorer
    December 27, 2021

    I'm trying to make my I2C handling, both for master and slave, as robust as possible.

    If the slave receives a request from the master, and the slave tries to respond to the master, but for whatever reason that response doesn't complete, the slave needs to abort that response and go back to waiting for a request from the master.

    It would appear the only way to do that, with the present STM HAL implementation, is for the slave to de-init and re-init the I2C interface, is that correct?

    Super User
    December 27, 2021

    > I'm trying to make my I2C handling, both for master and slave, as robust as possible.

    Great, but a device cannot be both a master and a slave. Which one are we talking about here? On the master side, the ACK/NACK mechanism will reveal if a slave is responding or not.

    On the slave side, if you are expecting the master to request information and so you call HAL_I2C_Slave_Transmit_IT proactively, but after 3seconds (or whatever timeout you want), the master has not yet asked for that info, HAL_I2C_Init will abort the call.

    If you want to handle read/write calls dynamically instead of proactively, you need to look at HAL_I2C_EnableListen_IT and related calls, as explained at the top of the source file.