2025-01-22 01:42 PM
Anyone familiar with using I3C in HAL? I'm using I3C to talk to an IMU sensor and I got through DAA and can successfully perform private reads (can read from whoami and other registers also tested) but I couldnt get private writes to work.
I followed 9.8 in this doc (\[Introduction to I3C for STM32 MCUs - Application note\](https://www.st.com/resource/en/application\_note/an5879-introduction-to-i3c-for-stm32h5-series-mcu-stmicroelectronics.pdf)) for Private read which works perfectly however we could not implement a working Private write anywhere in the documentation. We found this (https://github.com/STMicroelectronics/STM32CubeH5/blob/main/Projects/NUCLEO-H533RE/Examples/I3C/I3C\_Sensor\_Private\_Command\_IT/Src/main.c#L79) example code and implemented my own function which doesn’t work. I've been debugging for a week now but still no progress :( Thanks in advance.
#define I3C_IDX_FRAME_TX 0U
#define I3C_IDX_FRAME_RX 1U
I3C_XferTypeDef aContextBufs[2]; // Context buffer related to Frame context, contain different buffer value for a communication
uint8_t aTxBuf[15];
uint8_t aRxBuf[31];
uint32_t aControlBuf[0x1F];
I3C_PrivateTypeDef aPrivateDescs[2] =
{
{TARGET1_DYN_ADDR, {aTxBuf, 1}, {NULL, 0}, HAL_I3C_DIRECTION_WRITE},
{TARGET1_DYN_ADDR, {NULL, 0}, {aRxBuf, 1}, HAL_I3C_DIRECTION_READ}};
// callbacks omitted .....
//
int si_io_imu_write_reg(uint8_t reg, const uint8_t *buf, uint32_t len)
{
aTxBuf[0] = reg;
memcpy(&aTxBuf[1], buf, len);
aPrivateDescs[I3C_IDX_FRAME_TX].TxBuf.pBuffer = aTxBuf;
aPrivateDescs[I3C_IDX_FRAME_TX].TxBuf.Size = len + 1;
aContextBufs[I3C_IDX_FRAME_TX].CtrlBuf.pBuffer = aControlBuf;
aContextBufs[I3C_IDX_FRAME_TX].CtrlBuf.Size = 1;
aContextBufs[I3C_IDX_FRAME_TX].TxBuf.pBuffer = aTxBuf;
aContextBufs[I3C_IDX_FRAME_TX].TxBuf.Size = len + 1; // length of the register address + data
// Reset the complete flag
tx_complete_flag = 0;
while (HAL_I3C_GetState(&hi3c1) != HAL_I3C_STATE_READY) {}
if (HAL_I3C_AddDescToFrame(&hi3c1, NULL, &aPrivateDescs[I3C_IDX_FRAME_TX], &aContextBufs[I3C_IDX_FRAME_TX], 1, I3C_PRIVATE_WITH_ARB_STOP) != HAL_OK)
{
return -1;
}
if (HAL_I3C_Ctrl_Transmit_IT(&hi3c1, &aContextBufs[I3C_IDX_FRAME_TX]) != HAL_OK)
{
return -1;
}
while (HAL_I3C_GetState(&hi3c1) != HAL_I3C_STATE_READY)
{
PrintI3CState(&hi3c1);
HAL_Delay(100);
}
// Wait for the transmission to complete
while (tx_complete_flag == 0) {}; tx_complete_flag = 0;
return 0;
}