2018-04-03 01:56 PM
I have a slave device that is monitoring the I2C bus for its address from a master. This was done using the API HAL_I2C_Slave_Receive_IT(). This works successfully. My question is - if you want the slave device to stop monitoring the bus because would like to perform a different operation - how do you get the slave to stop? It seems like once you invoke this API there is no way to get out of this mode until an I2C address frame comes along with a matching address. There doesn't seem to be an API to do this. I tried HAL_I2C_DisableListen_IT() but that didn't seem to work. ANy tricks to this?
2018-05-09 02:53 AM
I use HAL_I2C_Init(). It works, but I guess it's overkill and there should be a more elegant way.
@ST: There is a function HAL_I2C_Master_Abort_IT(), so why is there no HAL_I2C_Slave_Abort_IT()?
2018-05-10 05:18 AM
Hello,
It is the master who decides to make or not the transfer and generates the START and the STOP condition regardless of the transfer.
The slave continues to Transmit/Receive data whatever the clock is generated from the master.Best Regards,
Imen
2018-05-10 05:21 AM
Yes - Sandro has the correct understanding of the issue. Perhaps you are in a configuration where the slave device will occasionally need to take control of the bus (like multi-master) and perform a send operation. How do I stop the listening process without having to perform the HAL_I2C_Init()?
--Ed
2018-05-10 06:31 AM
Hi Imen
The question was the following: If my STM32 is ready to receive data with HAL_I2C_Slave_Receive_IT() but the master is not sending anything, and now I decide that my STM32 should instead send something, how do I do this? I cannot just HAL_I2C_Slave_Transmit(), this results in an error because the I2C unit is still busy listening. As written above, I use HAL_I2C_Init(), but that doesn't seem to be the most elegant way.
--Sandro
2018-05-10 09:54 AM
Hello,
It's master side that you have to manage that, the slave can not do anything !
The master, in case of problem, must decide how to close the communication (generate a STOP), so that the slave does not always remain pending.
Best Regards,
Imen
2018-05-10 03:40 PM
Hi Imen
We are discussing a situation where the master has not yet started sending anything. Thus, the HAL_I2C_Slave_Receive_IT() will not exit with an interrupt callback. Instead, we have to find another way to cancel the receive operation.
--Sandro
2018-08-23 04:26 AM
Hi,
this is my problem too. If I want to use multi-master functionality, I have to be able to dynamically switch the behavior of the I2C driver.
The driver normally operates in slave receive mode, but if it wants to send something itself, the slave receive mode must be ended and a master transmit started.
The second problem is that no dynamic length data can be received. There is always an AF-Fail.
I think for a complex I2C multi-master communication the HAL driver is not suitable and you have to use the LL drivers.
Michael