cancel
Showing results for 
Search instead for 
Did you mean: 

Why HAL_I2C_IsDeviceReady return HAL_ERROR

SKAŞ.1
Associate II

Hello folks,

Since my last post, I still couldn't solve my I2C communication problem. I thought maybe return is not HAL_OK for my function so that I couldn't find any I2C addresses. And my guess was correct. I'm getting HAL_ERROR but it doesn't mean anything to me. What could be the reason I am getting this error.

0693W00000D0kZYQAZ.jpg 

Last time I couldn't upload my file, so here it is.

RCC -> HSE -> Ceramic

My clock setting is -> 8Mhz for input freq

HCLK = 84MHz

For pins,

PG13 & PG14 for LEDs

PG13 used for every scan is over,

PG14 used for interrupt (Just check if somethings is wrong but seems not!)

PA0 user button for external interrupt

I2C3 is used since others are not available for external usage. from the datasheet.

0693W00000D0Za6QAF.jpgI connect PCF8574T directly.

I can found the address via Arduino but with STM, I can't

my SPI settings is Standard mode (100MHz) set by CubeMX

most of the things set up by CubeMX.

I am waiting for your kind support,

Kind Regards.

12 REPLIES 12
Mike_ST
ST Employee

1) Set PA8 and PC9 with GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HIGH or VERY_HIGH setting is not good.

2) Try to roll the counter up to 255. =>

    for(counter = 0 ; counter < 255; counter++)

I think the dev address has to be shifted 1 bit to the left.

3) Check that you have actual (2.7K for example) pull_up resistors on the I2C lines,

GPIO_InitStruct.Pull = GPIO_PULLUP, is often not enough.

SKAŞ.1
Associate II

I switch the frequencies at "stm32f4xx_hal_msp.c" file

I change my counter to 255

and lastly, I put a 4.7k resistor to SDA and SDC each, one terminal connected to the line another terminal connected to the 5V supply at STM. for both lines.

Still can't get rid of the HAL_ERROR

Mike_ST
ST Employee

Next step for me would be to check with the scope whether there is something on SDA/SCL.

May I ask that what is the return value of IsDeviceReady if there is no device?

Now I am checking for debugging mode with counter increase 1 by 1

for counter 0 1 it turns OK but then, it turns ERROR. And never turn HAL_OK again.

I checked the SCL is clocking, and SDA is alternating (kinda randomly since it's fast and I cannot see clearly but I saw some changes.)

SKAŞ.1
Associate II

I am getting error in this line

  while (I2C_Trials < Trials);

  hi2c->State = HAL_I2C_STATE_READY;

  /* Process Unlocked */

  __HAL_UNLOCK(hi2c);

  return HAL_ERROR;

May I ask that what is the return value of IsDeviceReady if there is no device?

HAL_ERROR.

By chance, try to increase timeout value to something bigger.

TDK
Guru

What chip are you trying to talk with? The 7-bit slave address should be shifted left one bit. You're only checking for half of the possible slave values.

If you feel a post has answered your question, please click "Accept as Solution".
SKAŞ.1
Associate II

Let me correct my self, I got HAL_OK at counter 0 and 1, not in 2.

Also I change my code to more clear debugging, but still doesn't get anything.

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 for(counter = 0 ; counter < 255; counter++)

 {

 IDR_Result = HAL_I2C_IsDeviceReady(&hi2c3, counter, 3, 10);

 if(IDR_Result == HAL_OK)

 {

 I2C_Address = counter;

 HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_14);

 }

 }

 HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);

 HAL_Delay(500);

 }

 /* USER CODE END 3 */

PCF8574T