cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Slave_Transmit() returns HAL_TIMEOUT - STOP condition is not set

kraiskil
Associate III

I have a working set of electronics and a I2C Master device.

These work just fine with legacy software on a I2C Slave built on STM32F0.

Now I try out STMCubeMX, HAL and FreeRTOS. I let CubeMX do all the initialization of i2c-1

My code is simple:

uint8_t buf[2];
int rv;
rv = HAL_I2C_Slave_Receive(&hi2c1, buf, 1, 1000);
if( rv == HAL_OK )
   buf[0]=0x12; buf[1]=0x34;
else
   return;
 
rv = HAL_I2C_Slave_Transmit(&hi2c1, buf, 2, 1000);
if( rv == HAL_TIMEOUT )
  print("this triggers all the time");

I can see on the logic analyzer that the Master transmitted message arrives to slave ok, and the slave reply is sent fine. Master even receives this.

But after the slave reply, there is no STOP condition on the I2C bus.

This should be caused by Master (I think?), but it is not.

The master side is unchanged, the only thing I have changed is create a stub Slave software with CubeMX and HAL.

Is what I am doing on the Slave side correct? Or am I missing something?

(apart from the HAL documentation - the inline function documentation is not too thorough)

I see the same question here: https://community.st.com/s/question/0D50X00009XkYy7SAF/stm32f0-i2c-example-code, but that suggests something called Standard Peripheral Library - the download link of which says it is superseded by HAL and CubeMX.

Is there any working examples with HAL and I2C?

thanks in advance,

kalle

1 REPLY 1
T J
Lead

IIC is not the best interface, try to be low power, it just cant drive hard, so you need a stronger pullup...

@Community member​  suggest a 2k7 in extreme cases.

and maybe slow it down, I had to slow down to 40KHz on this latest project, now looking to use the DMA so as to not wait around.