cancel
Showing results for 
Search instead for 
Did you mean: 

How to de-activate HAL_I2C_Slave_Receive_IT()

Ed Boris
Associate
Posted on April 03, 2018 at 22:56

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?

7 REPLIES 7
Sandro G
Associate II
Posted on May 09, 2018 at 11:53

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()?

Posted on May 10, 2018 at 12:18

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Ed Boris
Associate
Posted on May 10, 2018 at 14:21

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

Posted on May 10, 2018 at 13:31

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

Posted on May 10, 2018 at 16:54

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on May 10, 2018 at 22:40

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

STE_Michael
Associate II

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