I use i2c0 compentent,How can I control the stop bit,
I change "LDD_I2C_SEND_STOP" to "LDD_I2C_NO_SEND_STOP" flag ,but only will sent out stop bit.
Thanks!
code:
uint8_t GI2C1_ReadAddress(uint8_t i2cAddr, uint8_t *memAddr, uint8_t memAddrSize, uint8_t *data, uint16_t dataSize)
{
uint8_t res = ERR_OK;
if (GI2C1_SelectSlave(i2cAddr)!=ERR_OK) {
return ERR_FAILED;
}
for(;;) { /* breaks */
if(memAddr!=NULL) { /* only if we want to send an address */
/* send device address and memory address */
GI2C1_deviceData.dataTransmittedFlg = FALSE;
res = CI2C1_MasterSendBlock(GI2C1_deviceData.handle, memAddr, memAddrSize, LDD_I2C_NO_SEND_STOP);
if (res!=ERR_OK) {
break; /* break for(;;) */
}
}
do { /* Wait until data is sent */
} while (!GI2C1_deviceData.dataTransmittedFlg);
/* receive data */
GI2C1_deviceData.dataReceivedFlg = FALSE;
res = CI2C1_MasterReceiveBlock(GI2C1_deviceData.handle, data, dataSize, LDD_I2C_NO_SEND_STOP);// LDD_I2C_SEND_STOP);
if (res!=ERR_OK) {
break; /* break for(;;) */
}
do
{ /* Wait until data is received */
} while (!GI2C1_deviceData.dataReceivedFlg);
break; /* break for(;;) */
} /* for(;;) */
if (GI2C1_UnselectSlave()!=ERR_OK) {
return ERR_FAILED;
}
return res;
}
Hi Gordon,
you can use
/*
** ===================================================================
** Method : GI2C1_ReadBlockGeneric (component GenericI2C)
** Description :
** Read from the device a block with using additional control
** and flags.
** Parameters :
** NAME - DESCRIPTION
** * data - Read buffer
** dataSize - Size of read buffer
** flagsSend - flags for the send transaction
** flagsStart - Start flags
** flagsAck - Acknowledge flags
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t GI2C1_ReadBlockGeneric(void* data, uint16_t dataSize, GI2C1_EnumSendFlags flags, GI2C1_EnumStartFlags flagsStart, GI2C1_EnumAckFlags flagsAck);
Which supports flags for sending. But currently this is only supported for software (bit banging I2C), not for the I2C_LDD.
If you would like to provide a contribution, I'm more than happy to include this into the driver.
Thanks,
Erich
I am use component to operate the I2C device.but is read one register all send a stop bit ,
Hi gordon,
Please tell me what the chip you are using? Give me the part number.
Now, take KL25 as an example, the stop code in KSDK is:
status_t I2C_MasterStop(I2C_Type *base)
{
status_t result = kStatus_Success;
uint16_t timeout = UINT16_MAX;
/* Issue the STOP command on the bus. */
base->C1 &= ~(I2C_C1_MST_MASK | I2C_C1_TX_MASK | I2C_C1_TXAK_MASK);
/* Wait until data transfer complete. */
while ((base->S & kI2C_BusBusyFlag) && (--timeout))
{
}
if (timeout == 0)
{
result = kStatus_I2C_Timeout;
}
return result;
}
Actually, you can check our SDK code, which can be download from this link:
Welcome | MCUXpresso SDK Builder
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you very much!, I am newer.
I use KL25demoboard.use component "InternalI2C",It create code mask the "LDD_I2C_NO_SEND_STOP" in receive function.
My project use KL02. I could read different registers and don't send stop bit.When read over then send on stop bit?