Skip to main content
Associate II
November 7, 2023
Question

Getting HAL_ERROR while using I2C in Fast mode pulse

  • November 7, 2023
  • 12 replies
  • 14192 views

Hi All,

I trying to interface MAX6651 Device using I2C module using STM32F410C8U6 MCU.

Device address is 0x36 But when i'm using 

HAL_FMPI2C_IsDeviceReady(&hfmpi2c1, 0x36 , 2, 100); this API returning the value
HAL_ERROR.

Here are some snaps

Screenshot 2023-11-07 151633.pngScreenshot 2023-11-07 151523.png

Anybody look into it send some solutions

 

This topic has been closed for replies.

12 replies

Pierre_Paris
ST Employee
November 8, 2023

Hello @Advance_tech,

Thank you for your question.

In the MAX6650 document from Analog Devices you shared, it specified that the rise/fall time should be between 20ns and 300ns (cf the figure below) 

PierrePARIS_0-1699449191054.png

But on your CubeMx screenshot, you enter 0 ns, please change it and try again.

Let me know !

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate II
November 9, 2023

Hello,

I think I2C start bit not generating.

FMPI2C1->CR1 |= (1 << 0);

FMPI2C1->CR2 |= (1 << 13);

printf("Hi\r\n");

while(!(FMPI2C1->CR2 & (1 << 13)));

printf("Hello\r\n");

 

program is struct inside the while(1)

after while(1) nothing is executing.

Is there is any chance the I2C Peripheral is gone


please answer

 

Pierre_Paris
ST Employee
November 13, 2023

Hello @Advance_tech,

Several I2C multi-masters can be connected to the same I2C bus and operate concurrently. By constantly monitoring SDA and SCL for start and stop conditions, they can determine whether the bus is currently idle or not. If the bus is busy, masters delay pending I2C transfers until a stop condition indicates that the bus is free again.

However, it may happen that two masters start a transfer at the same time. During the transfer, the masters constantly monitor SDA and SCL. If one of them detects that SDA is low when it should actually be high, it assumes that another master is active and immediately stops its transfer. This process is called arbitration.

Here some remark :

  • Have you corrected the rise/fall time ?
  • How many masters does your I2C bus have ? 
  • Check your data frame with an analyzer if possible
  • Do you switch the I2C device on your microcontroller between slave and master mode in your code ?

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate II
November 20, 2023

hi @Pierre_Paris 

we have single master and two slave devices in I2C line.

HAL_FMPI2C_IsDeviceReady(&hfmpi2c1, max6551_add_2 , 1, 2000);

when i use this API error code is 32 means timeout error

 

HAL_FMPI2C_Master_Transmit(&hfmpi2c1, i,(uint8_t *)&pdata, sizeof(pdata), HAL_MAX_DELAY);

when i use this API the error code is 2 means arbitration error.

Pierre_Paris
ST Employee
November 20, 2023

Hello @Advance_tech,

Before I investigate further, can you please confirm you corrected the rise/fall time. (Timeout fault can be the consequence because the slave cannot follow...)

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate II
November 20, 2023

hi @Pierre_Paris thanks for quick response

i have given rise time and fall time as 300ns as mentioned in datasheet.

But i don't know how to calculate rise time and fall time  

Pierre_Paris
ST Employee
November 20, 2023

Hello @Advance_tech,

300ns is the maximum limit value, please check with 200ns (just in case).

You don't need to calculate rise and fall time. There is, indeed, a calculation with the I2C_TIMINGR but it's unnecessary to do it (tools do). However, if you want to learn more, you can read the chapter 2.2.4 of AN4235 by clicking here.

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate II
November 21, 2023

Hi @Pierre_Paris  i would like to thank for all your responses. i slowly heading into solve the problem.

retval = HAL_FMPI2C_IsDeviceReady(&hfmpi2c1, max6551_add_2, 1, 100);

error_code = HAL_FMPI2C_GetError(&hfmpi2c1);

 

printf("return value %d\r\n",retval);

HAL_Delay(100);

printf("error code is = %ld\r\n",error_code);

HAL_Delay(100);

Now i getting HAL_BUSY From this HAL_FMPI2C_IsDeviceReady API and error code is 32 which means

HAL_FMPI2C_ERROR_TIMEOUT

please let me know what may cause these problems

 

 

 

Pierre_Paris
ST Employee
November 21, 2023

Hello @Advance_tech,

Here some possible solution for your issue :

  • First, can you check the trace scope SCL & SDA ? The slave most likely don't ACK the master (which wait until the end of timeout) and return your "HAL_FMPI2C_ERROR_TIMEOUT" error.
  • What is your STM32F4xx HAL Drivers version ? I checked on the V1.8.0 and there are no such function HAL_FMPI2C_IsDeviceReady(). Please use the last software version and call HAL_I2C_IsDeviceReady().
  • Maybe you are not writing at the good address ? Check your ADD value. 
     

     

    Pierre_P_2-1700583156673.png

     

  • Also, Can you try to write in the component memory with HAL_I2C_Mem_Write() and then read it thanks to HAL_I2C_Mem_Read(). Choose any register existing in the doc.

Best Regards,

Pierre
 

 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate II
November 22, 2023

hello @Pierre_Paris

 

  • We have checked the SDA and SCL signals in scope refer the attached pic.
  • we cannot use HAL_I2C_IsDeviceReady(). because we are using FMPI2C In STM32F410C8U6
    only we can use HAL_FMPI2C_IsDeviceReady().
  • we have connected the 10k to ADD pin so our address becomes the 3ERigolDS10.pngplease refer to waveform only serial clock coming but there is not serial data
  • Is there any chance that IC's I2C peripheral not working???  

     
Pierre_Paris
ST Employee
November 22, 2023

Hello @Advance_tech,

  • "Is there any chance that IC's I2C peripheral not working???  " : If you comply the absolute maximum ratings given in the Datasheet, it should work.
  • Understood, have you respected the following initialization of the FMPI2C before using HAL_FMPI2C_IsDeviceReady() to check if target device is ready?
    • Enable the FMPI2Cx interface clock
    • FMPI2C pins configuration (Enable the clock for the FMPI2C GPIOs + Configure FMPI2C pins as alternate function open-drain)
    • NVIC configuration if you need to use interrupt process
    • DMA Configuration if you need to use DMA process
    •  Configure the Communication Clock Timing, Own Address1, Master Addressing mode, Dual Addressing mode, Own Address2, Own Address2 Mask, General call and Nostretch mode in the hfmpi2c Init structure.
    • Initialize the FMPI2C registers by calling the HAL_FMPI2C_Init(), configures also the low level Hardware (GPIO, CLOCK, NVIC...etc) by calling the customized HAL_FMPI2C_MspInit(&hfmpi2c) API.
  • "Pease refer to waveform only serial clock coming but there is not serial data" : It seems that's the opposite but I don't understand this behavior. You can find here the errata sheet. Please read the I2C chapter.

Best Regards,

Pierre

 
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.