2025-11-05 6:11 PM - last edited on 2025-11-06 12:29 AM by mƎALLEm
Post edited by ST moderator to be inline with the community rules for the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code.
Hello!
I connect one I2C target and one I3C target device both to PB6/PB7, which is configured to be "mixed I3C and I2C bus" through STM32CubeIDE.
I3C parameter configuration is as below:
/* USER CODE END I3C1_Init 1 */
hi3c1.Instance = I3C1;
hi3c1.Mode = HAL_I3C_MODE_CONTROLLER;
hi3c1.Init.CtrlBusCharacteristic.SDAHoldTime = HAL_I3C_SDA_HOLD_TIME_1_5;
hi3c1.Init.CtrlBusCharacteristic.WaitTime = HAL_I3C_OWN_ACTIVITY_STATE_0;
hi3c1.Init.CtrlBusCharacteristic.SCLPPLowDuration = 0x18; // 5MHz
hi3c1.Init.CtrlBusCharacteristic.SCLI3CHighDuration = 0x18;
hi3c1.Init.CtrlBusCharacteristic.SCLODLowDuration = 0x7b; //1MHz
hi3c1.Init.CtrlBusCharacteristic.SCLI2CHighDuration = 0x7b;
hi3c1.Init.CtrlBusCharacteristic.BusFreeDuration = 0x69;
hi3c1.Init.CtrlBusCharacteristic.BusIdleDuration = 0xf6;
The problem I encountered is :
I3C devices works ok, but I2C device SCL frequency is same as I3C device, so I get wrong data when reading the I2C device , because SCL frequency is 5MHz, it is too fast for I2C device. I want the I2C device works at a lower speed, which is 1MHz in my case.
Below is the I2C waveform.
I use I3C API while comunicating with I2C device when reading one byte, as below code:
I3C_PrivateTypeDef aPrivateDescriptor[2] = {
{0x76, {aTxBuffer, 1}, {NULL, 0}, HAL_I3C_DIRECTION_WRITE},
{0x76, {NULL, 0}, {aRxBuffer, 1}, HAL_I3C_DIRECTION_READ}};
/* Prepare context buffer with the different parameters */
aContextBuffers.CtrlBuf.pBuffer = aControlBuffer;
aContextBuffers.CtrlBuf.Size = 2;
aContextBuffers.TxBuf.pBuffer = aTxBuffer;
aContextBuffers.TxBuf.Size = 1;
aContextBuffers.RxBuf.pBuffer = aRxBuffer;
aContextBuffers.RxBuf.Size = 1;
// Add descriptors to frame
HAL_I3C_AddDescToFrame(&hi3c1, NULL, aPrivateDescriptor, &aContextBuffers, aContextBuffers.CtrlBuf.Size, I3C_PRIVATE_WITHOUT_ARB_RESTART);
// Start the transfer
status = HAL_I3C_Ctrl_MultipleTransfer_IT(&hi3c1, &aContextBuffers);
if (status != HAL_OK) {
Error_Handler();
}
What might be the promblem ? Is it because I use the wrong API to communicate with I2C device ?
Is it possible to make my I2C device to work at a lower speed?
Thanks for any advice.
Solved! Go to Solution.
2025-11-07 1:04 AM
Hello
I you want to made an I2C communication you should select on software side (HAL) this option started with prefix I2C_PRIVATE_xxx like I2C_PRIVATE_WITHOUT_ARB_RESTART instead of I3C_PRIVATE_WITHOUT_ARB_RESTART.
Regards
2025-11-07 12:37 AM
Hello @GH502
To reduce the operating frequency, configure the I3C controller to 1 MHz using STM32CubeMX.
2025-11-07 12:44 AM
Hi Saket_Om,
If I change the I3C frequency to 1MHz, My I3C device could only work at 1MHz, but I want it to work faster at 5MHz. Is it possible?
Thank you very much.
2025-11-07 1:04 AM
Hello
I you want to made an I2C communication you should select on software side (HAL) this option started with prefix I2C_PRIVATE_xxx like I2C_PRIVATE_WITHOUT_ARB_RESTART instead of I3C_PRIVATE_WITHOUT_ARB_RESTART.
Regards
2025-11-07 1:14 AM
Hi JRAUL.1,
That solved my problem, Thank you very much.
2025-11-07 1:26 AM
Great, to share with the usage of this kind of option in your usecase:
If you choice an option I3C_PRIVATE_xxx, as for I3C protocol the address phases is in open drain (as I2C protocol), the frequency will be your open drain frequency (in your case 1Mhz).
And about data phases due to I3C protocol it will be push-pull transfer mode so will be your push pull frequency (in your case 5Mhz).
Now by choice the option I2C_PRIVATE_xxx, all part of the communication will be in open-drain transfer mode, so will be your open drain frequency (1Mhz in your case) in all part of the communication address + data.
Regards.