hello everybody
finally, I success i2c communication using LPI2C.
but another problem has occured.
I using LPTMR example. lptmr_periodic_interrupt_s32k116
and, add components i2c. set master mode 50kHz
and than,
void LPTMR_ISR(void)
{
/* Clear compare flag */
LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
/* Toggle LED_GREEN */
PINS_DRV_TogglePins(LED_GPIO_PORT, (1 << LED_GREEN));
I2C_MasterSendDataBlocking(&i2c1_instance, masterTxBuffer, TRANSFER_SIZE, false, 10);
masterTxBuffer[0] = 0x01;
I2C_MasterReceiveDataBlocking(&i2c1_instance, masterTxBuffer, TRANSFER_SIZE, false, 10);
}
in LPTMR ISR loop.
but, when start program, It going to OSIF_SemaWait(&(master->idleSemaphore), 0); function in LPI2C_DRV_MasterSendDataBlocking.
why this? how to escape OSIF_SemaWait?
it is hard to using LPTMR with LPI2C?
Hi@skb
try to use this function.
Tips:
Because in the blocking API function, the API function of the OSIF component-OSIF_SemaWait() is called to check the data transmission and reception semaphore in the peripheral driver global state structure, if RTOS is used in the application project, such as FreeRTOS , The task that calls the blocking API function will be blocked, and the CPU resources are released to run other ready high-priority thinking, until the receipt and delivery is completed (semaphore release) or timeout, so the CPU execution efficiency will be greatly improved; and if the application If RTOS is not used in the project, the blocking API function will always occupy the CPU, resulting in a waste of CPU resources;
In summary, if the application project uses RTOS, it is recommended to use the blocking API function; if the application project does not use the RTOS, it is recommended to use the non-blocking API function, and cooperate with the interrupt callback function to determine the data receiving and sending status and do corresponding processing.
BR!
Jim,
hi @Senlent
Thank you, It operated. but not well.
void LPTMR_ISR(void)
{
/* Clear compare flag */
LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
/* Toggle LED_GREEN */
PINS_DRV_TogglePins(LED_GPIO_PORT, (1 << LED_GREEN));
LPI2C_DRV_MasterSendData(INST_LPI2C1, buffer, TRANSFER_SIZE, false);
LPI2C_DRV_MasterReceiveData(INST_LPI2C1, buffer, TRANSFER_SIZE, false);
}
when I insert non-blocking i2c code in LPTMR, SDA pulse is not changed.
I search some solution like that.
while ((retCode = LPI2C_DRV_MasterGetTransferStatus(INST_LPI2C1, NULL))
== STATUS_BUSY) {
};
but this code do like blocking i2c function.
how can i?
Hi@skb
Is there any problem with this usage? I2C is not parallel communication, it always needs some waiting time。
You can try to use FlexIO to simulate I2C, which is also a way to realize I2C communication. You can even use the GPIO port to simulate I2C communication, but this requires you to write your own software code.
These ways of implementing I2C communication all depend on the user.
BR!
Jim,