2021-12-26 11:42 AM
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.
2021-12-26 03:44 PM
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.
2021-12-27 09:52 AM
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?
2021-12-27 11:15 AM
> 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.
2021-12-27 02:44 PM
Apologies for not providing every relevant detail.
I have two separate STM32 systems, one an I2C master, one an I2C slave.
Both were communicating with each other perfectly.
Then, to make both connections, at both ends, more robust, I started testing what happened when either system failed.
It was relatively easy to make the master robust, in the event of slave failure, by timing out on the complete callback, either transmit or receive, calling HAL_I2C_Master_Abort_IT and restarting the interaction.
On the slave side, in the event of master failure, which times out only on send reply to master, what then to do? De-init and re-init?