cancel
Showing results for 
Search instead for 
Did you mean: 

ST33KTPM2I3WBZA9 Interfacing Issue with STM32H735IGT3

SSAIL2023
Associate II

Hi,

We are trying  to interface ST33KTPM2I3WBZA9 with STM32H735IGT3 using I2C communication.We have used following commands and logic for communication.

 

 

#define TPM_I2C_ADDRESS 0x2e << 1

#define TPM_REG_ADDR_COMMAND 0x00



uint8_t command_data = 0x80;

uint8_t read_data1;



uint8_t TPM_WriteReadTest(void) {

if (HAL_I2C_Mem_Write(&hi2c4, TPM_I2C_ADDRESS, TPM_REG_ADDR_COMMAND, I2C_MEMADD_SIZE_8BIT, &command_data, sizeof(command_data), HAL_MAX_DELAY) == HAL_OK) {

//HAL_Delay(10);

} else {

return TEST_FAIL;

}



if (HAL_I2C_Mem_Read(&hi2c4, TPM_I2C_ADDRESS, TPM_REG_ADDR_COMMAND, I2C_MEMADD_SIZE_8BIT, &read_data1, sizeof(read_data1), HAL_MAX_DELAY) == HAL_OK) {

if (read_data1 == command_data) {

return TEST_PASS;

} else {

return TEST_FAIL;

}

} else {

return TEST_FAIL;

}

}



Here when initially tested the "HAL_I2C_Mem_Write" function gets passed for around 2 minutes of power on,after that function fails.With further evaluation the "HAL_I2C_Mem_Write" fails in "I2C_RequestMemoryWrite" function in the API below.

/**

* @brief Write an amount of data in blocking mode to a specific memory address

* @PAram hi2c Pointer to a I2C_HandleTypeDef structure that contains

* the configuration information for the specified I2C.

* @PAram DevAddress Target device address: The device 7 bits address value

* in datasheet must be shifted to the left before calling the interface

* @PAram MemAddress Internal memory address

* @PAram MemAddSize Size of internal memory address

* @PAram pData Pointer to data buffer

* @PAram Size Amount of data to be sent

* @PAram Timeout Timeout duration

* @retval HAL status

*/

HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress,

uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)

{

uint32_t tickstart;



/* Check the parameters */

assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));



if (hi2c->State == HAL_I2C_STATE_READY)

{

if ((pData == NULL) || (Size == 0U))

{

hi2c->ErrorCode = HAL_I2C_ERROR_INVALID_PARAM;

return HAL_ERROR;

}



/* Process Locked */

__HAL_LOCK(hi2c);



/* Init tickstart for timeout management*/

tickstart = HAL_GetTick();



if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_BUSY, tickstart) != HAL_OK)

{

return HAL_ERROR;

}



hi2c->State = HAL_I2C_STATE_BUSY_TX;

hi2c->Mode = HAL_I2C_MODE_MEM;

hi2c->ErrorCode = HAL_I2C_ERROR_NONE;



/* Prepare transfer parameters */

hi2c->pBuffPtr = pData;

hi2c->XferCount = Size;

hi2c->XferISR = NULL;



/* Send Slave Address and Memory Address */

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

{

/* Process Unlocked */

__HAL_UNLOCK(hi2c);

return HAL_ERROR;

}



/* Set NBYTES to write and reload if hi2c->XferCount > MAX_NBYTE_SIZE */

if (hi2c->XferCount > MAX_NBYTE_SIZE)

{

hi2c->XferSize = MAX_NBYTE_SIZE;

I2C_TransferConfig(hi2c, DevAddress, (uint8_t)hi2c->XferSize, I2C_RELOAD_MODE, I2C_NO_STARTSTOP);

}

else

{

hi2c->XferSize = hi2c->XferCount;

I2C_TransferConfig(hi2c, DevAddress, (uint8_t)hi2c->XferSize, I2C_AUTOEND_MODE, I2C_NO_STARTSTOP);

}



do

{

/* Wait until TXIS flag is set */

if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, tickstart) != HAL_OK)

{

return HAL_ERROR;

}



/* Write data to TXDR */

hi2c->Instance->TXDR = *hi2c->pBuffPtr;



/* Increment Buffer pointer */

hi2c->pBuffPtr++;



hi2c->XferCount--;

hi2c->XferSize--;



if ((hi2c->XferCount != 0U) && (hi2c->XferSize == 0U))

{

/* Wait until TCR flag is set */

if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TCR, RESET, Timeout, tickstart) != HAL_OK)

{

return HAL_ERROR;

}



if (hi2c->XferCount > MAX_NBYTE_SIZE)

{

hi2c->XferSize = MAX_NBYTE_SIZE;

I2C_TransferConfig(hi2c, DevAddress, (uint8_t)hi2c->XferSize, I2C_RELOAD_MODE,

I2C_NO_STARTSTOP);

}

else

{

hi2c->XferSize = hi2c->XferCount;

I2C_TransferConfig(hi2c, DevAddress, (uint8_t)hi2c->XferSize, I2C_AUTOEND_MODE,

I2C_NO_STARTSTOP);

}

}



} while (hi2c->XferCount > 0U);



/* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */

/* Wait until STOPF flag is reset */

if (I2C_WaitOnSTOPFlagUntilTimeout(hi2c, Timeout, tickstart) != HAL_OK)

{

return HAL_ERROR;

}



/* Clear STOP Flag */

__HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);



/* Clear Configuration Register 2 */

I2C_RESET_CR2(hi2c);



hi2c->State = HAL_I2C_STATE_READY;

hi2c->Mode = HAL_I2C_MODE_NONE;



/* Process Unlocked */

__HAL_UNLOCK(hi2c);



return HAL_OK;

}

else

{

return HAL_BUSY;

}

}

 

 What may be the reason,how can we debug it?

2 REPLIES 2

Please see the Community Guidelines for how to properly post source code:

How to write your question to maximize your chances to find a solution

How to insert source code

I've edited your post, but the indentation was already lost.

 


@SSAIL2023 wrote:

We are trying  to interface ST33KTPM2I3WBZA9 with STM32H735IGT3 using I2C communication.


Please show your schematics of how you've done that.

 


@SSAIL2023 wrote:

how can we debug it?


The first thing is to discover what's actually going wrong:

  • What, exactly, did you expect your code to do?
  • What, exactly, is your code to actually doing?

As you're using an external hardware interface, the first thing is to use an oscilloscope or logic analyser to see what's actually happening on the wires.

Then use the software debugger and/or add instrumentation to see what the code is doing internally.

Some things to look at:

  • Your code returns TEST_FAIL in many places - you need to identify which test, exactly, is failing.
  • Rather than just test the HAL return codes for != HAL_OK, examine what the actual code returned is; look into why that code is returned

 

Some general debugging tips here:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/706966/highlight/true#M49

if (HAL_I2C_Mem_Write(&hi2c4, TPM_I2C_ADDRESS, TPM_REG_ADDR_COMMAND, I2C_MEMADD_SIZE_8BIT, &command_data, sizeof(command_data), HAL_MAX_DELAY) == HAL_OK) {

//HAL_Delay(10);

} else {

return TEST_FAIL;

}

 

Hi please find below the schematics for the TPM device. Here it is connected to I2C4 of STM32H735IGT3 and presence pin and interrupt are connected as  GPIO input to STM32H735IGT3 and we are reading presence as always high and interrupt pin always low.