cancel
Showing results for 
Search instead for 
Did you mean: 

I2C always falls into HAL_I2C_ERROR_AF

Thiago Cavalcanti
Associate II
Posted on December 20, 2017 at 13:04

Hi, everyone.

I2C peripheral has been initialized with STM32CubeMX according to the picture bellow:

0690X00000609HAQAY.png

I am using I2C1, pins B9 (data) and B8 (clock) in STM32F4 - Discovery. The device�s address is 0x60 (Says the datasheet). I am using pull-up (8 KOhm) and conflict protection resistors

(1.2 KOhm)

.I can neither read nor write to the slave device. I�ve tried the two following ways:

1)

uint8_t outputData = 0;

HAL_I2C_Mem_Read(&hi2c1, 0x60, 0x0A, I2C_MEMADD_SIZE_8BIT, &outputData, 1, HAL_MAX_DELAY);

 

2)

uint8_t outputData = 0;

 

HAL_StatusTypeDef returnValue = 0;

 

returnValue = HAL_I2C_Master_Transmit(&hi2c1, 0x60, (uint8_t*)0x0A, 1, HAL_MAX_DELAY);

 

if(returnValue != HAL_OK) return returnValue;

 

returnValue = HAL_I2C_Master_Receive(&hi2c1, 0x60, &outputData, 1, HAL_MAX_DELAY);

These functions always falls into the following �if� block:

/* Send Slave Address and Memory Address */

 

if(I2C_RequestMemoryRead(hi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)

 

{

 

if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)

 

{

 

/* Process Unlocked */

 

__HAL_UNLOCK(hi2c);

 

return HAL_ERROR;

 

}

The next picture shows the activity in the I2C bus:

0690X00000609GlQAI.png

#i2c-addressing
12 REPLIES 12
Thiago Cavalcanti
Associate II
Posted on December 22, 2017 at 12:32

I found the problem. The camera needs an input clock and I was using MCO1, with PLLCLK/4. When I checked the signal I saw that the output looked more like noise than an actual clock. Then, I changed it to output the clock from HSI and it worked. Thank you all for your support.

Posted on April 12, 2018 at 15:47

Hi Thiago,

I'm having this same issue with a MAX17205 Fuel Gauge IC. Could you tell me how you probed your I2C lines? More specifically, what lines of code in the HAL I2C driver output the SDA/SCL signals?

Cheers,

Tony

Posted on April 12, 2018 at 21:33

What do you mean by 'same issue'?

Could you tell me how you probed your I2C lines?

Using a logic analyzer, apparently. You can use also an oscilloscope.

Generally it's better to start your own thread.

JW