cancel
Showing results for 
Search instead for 
Did you mean: 

I2C How to switch between receive and transmit Interrupt the rigth way? | I2C VS SMBUS | STM32F446RE Raspberry

AMüll.1
Associate

Hi Community,

Short version of the question: How can I achieve a response like shown in the first picture from the slave device, without getting stuck in an error. This response is from the specific slave device, but I can only generate it once. After that the STM is stuck in an error. 

0690X00000BwZ4NQAV.png

To explain the situation a bit further:

I’m trying to accomplish an I2C communication between a Raspberry (Master) and a STM32 F446RE. Please be forgiving with me, I’m new to “real�? microcontroller programming. I just have limited experience with Arduino and this stuff. However, since a few weeks working through this tremendous amount of datasheets, documentation and videos I reached a point where I don’t have any idea to reach the goal anymore.

Hopefully it’s just a very simple problem and I’m just not experienced enough to solve it. 

First, I’m using the HAL lib, CubeMX and the CubeIDE.

I’ve tried many things till now. The whole story started in the naivest way with HAL_I2C lib and the configuration as slave. With this version, I was able to send to the slave and also to read from the slave, but only one of the two after programming. For this the standard HAL_I2C_Slave_ReceiveIT() and HAL_I2C_Slave_TransmitIT() functions where used, of course with their callbacks to “reinitialize�? the interrupt functions. At this point the slave just transmitted something but not the right value.

One question by the way. Am I right with the point of “reinitializing�? or should i say recalling the Interrupt function after the transmission, respectively in the callback?

Starting from this point I tried to accomplish any kind of switching between the receive and the transmit functions and to find a solution for the wrong data values at transmission. Regarding to the switching problem, I got an error something like receiving status busy. So I thought maybe it’s a time problem, and searched from it.

In the meantime, I came across the clock stretching problem with the raspberry. According to this I turned clock stretching at the STM off. I also switched to HAL_FMPI2C lib, because the HAL_I2C lib related to this specific STM32 has only one register for receiving and transmission data. So I tried to manipulate the TXDR register in the HAL_FMPI2C lib manually to get a useful output. This solved some transmission problems referred to the data the slave device should transmit. 

At this point the master could “continuously�? send data to or read data from the slave, but still only one of them at a time. I still haven’t found a way to switch between them, without getting stuck in the while loop. Wouldn’t this destroy the whole point of interrupts and just load the MCU? Or am I wrong with this point? Isn’t there any intended, correct way to do this? Below are some pictures of the output of the logic analyser. To me it seems everything quite ok.

Master write - slave receive

0690X00000BwZ4SQAV.png

Master read - slave transmit

0690X00000BwZ4cQAF.png

master read - slave transmit without any programmed delay in master0690X00000BwZ4hQAF.png

Thinking about the switching problem brought me to the point “Maybe I’m facing a major difference between I2C and SMBUS?�? I’m still not shore about that point, but I tried to implement the SMBUS feature in the STM32F446. 

One question to SMBUS regarding to this specific model. The STACK SMBUS seems not be supported by this controller (just L4 F0 F3 etc but not F4). And apparently ST said it wouldn’t be implemented for Hardware reasons. 

Is there a difference between the general HAL_SMBUS feature and the STACK SMBUS? 

Currently I don’t get it and I don’t know if I could implement SMBUS but the STACK SMBUS not or if the SMBUS feature generally isn’t supported by this model. In the documentation there definitely are chapters to SMBUS related to I2C and FMPI2C.

However, I tried also to get the SMBUS feature running, but here I lost completely any kind of logical context in terms of the behaviour of the controller.

Summary:

1.Is the shown message I want to achieve just related to SMBUS and ordinary I2C can’t hand it? 

2. Is there a difference between SMBUS and STACK SMBUS?

3. is there any way to implement SMBUS reliable on the STM32F446RE?

4. Is there any intended "right" way of switching between receive and transmit, if the SMBUS feature won’t work for me?

0 REPLIES 0