KSDK I2C driver get stuck if SCL is shorted to ground

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KSDK I2C driver get stuck if SCL is shorted to ground

1,906 Views
giacomopetrini
Contributor IV

Hi,

so using KSDK 1.1 and KDS 2.0.0. I also use Processor Expert for module configuration.

 

I was testin how well behave my code when something bad happens to the external I2C module (it's a Adafruit 10DOF) connected with a long cable.

So when I shorted SCL to ground the program just got stuck. CPU was still working but I2C communication stopped.

I2C is configured to use interrupts.

It seems that the program got stuck here (in ../SDK/platform/hal/src/i2c/fsl_i2c_hal.c)

 

bool I2C_HAL_WriteByteBlocking(uint32_t baseAddr, uint8_t byte)

{

 

#if FSL_FEATURE_I2C_HAS_DOUBLE_BUFFERING

    while (!BR_I2C_S2_EMPTY(baseAddr))

    {}

#endif

 

    /* Write byte into I2C data register. */

    HW_I2C_D_WR(baseAddr, byte);

 

 

    /* Wait till byte transfer complete. */

   while (!BR_I2C_S_IICIF(baseAddr) )    <<<<<<<< STUCK HERE!!!!!!

    {}

 

    /* Clear interrupt flag */

    BW_I2C_S_IICIF(baseAddr, 0x1U);

 

    /* Return 0 if no acknowledge is detected. */

    return !BR_I2C_S_RXAK(baseAddr);

}

   

I also tried to put a timeout in the while, but then the program crashed with a failed assertion:

"assertion "BR_I2C_C1_MST(baseAddr) == 1" failed: file "../SDK/platform/hal/src/i2c/fsl_i2c_hal.c", line 253, function: I2C_HAL_SendStop"

 

Any ideas how to improve this? The program should be able to fucntion even if the I2C bus is not working

 

Thanks Best Regards

Giacomo

 

Edit: same thing happens if I short to ground the SDA line.

Labels (1)
Tags (2)
0 Kudos
6 Replies

1,140 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello giacomopetrini:

Are you using the Peripheral Driver (fsl_i2c) or the component for the HAL layer (fsl_i2c_hal)?

The function you show above is "I2C_HAL_WriteByteBlocking()". It is expected that the program hangs if the transaction of the byte is not completed because of the SDA or SCL lines tied to GND, since the STOP signal cannot be generated, hence IICIF flag is never set.

In case you do not want the execution to hang even if the I2C bus is failing then these are your options:

- Call the non-blocking HAL APIs (I2C_HAL_ReadByte and I2C_HAL_WriteByte) instead of the blocking functions.

- Use the Peripheral Driver component (fsl_i2c) and use the non-blocking functions for data transmission (I2C_DRV_MasterSendData and I2C_DRV_MasterReceiveData).


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,140 Views
albertolubeiro
Contributor III

Hi Jorge,

I am using KDS3.0 with PEX and im having the same issue.

In my case, the code get stuck in the following line.

/* Wait for the transfer to finish.*/

    I2C_DRV_MasterWait(instance, timeout_ms);

I use the non-blocking function I2C_DRV_MasterSendDat.

Any idea?

Thanks and best regards

0 Kudos

1,140 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Alberto Lubeiro:

Did you call OSA_Init() before using the I2C driver?

Regards!

Jorge Gonzalez

0 Kudos

1,140 Views
albertolubeiro
Contributor III

Hi Jorge,

I have started my project with PEX so this function is called at the begining. Inside main, there is "PE_low_level_init();" and inside this, there is "PEX_RTOS_INIT();"

#define PEX_RTOS_INIT OSA_Init.

I have created a new MQX proyect only with I2C component and it happens the same wierd issue as in my project.

Thanks and best regards.

0 Kudos

1,140 Views
giacomopetrini
Contributor IV

Hi,

I'm using fsl_i2c through PEx component.

I modified  I2C_DRV_SendAddress() to use the I2C_HAL_WriteByteBlocking() instead fo the I2C_HAL_WriteByte() because I have a strict timing in my application.


Could you please advice how to solve (or workaround) the hangs?

In any case there should be some kind of failsafe in the blocking functions to avoid hangs...


Best Regards

Giacomo

0 Kudos

1,140 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Giacomo:

As the name indicates, those functions are blocking and would not return unless the I2C transfer is complete. If you need to use blocking functions but do not want the program to hang, then you could modify the API and add some timeout using a hardware timer. This way the API call would be semi-blocking and would return after the timeout.

Regards!

Jorge Gonzalez

0 Kudos