AnsweredAssumed Answered

In JN-AN-1229,I want to be able to use I2C communication

Question asked by 心有余悸 周 on Aug 5, 2019
Latest reply on Aug 6, 2019 by Mario Ignacio Castaneda Lopez

I saw a case of JN-AN-1221 and then borrowed from the application.

bool i2c_BusWriteReg(uint8 u8Address, uint8 u8Command, uint8 u8Length, uint8* pu8Data)
{
#ifdef DEBUG_I2C_DRIVER
DBG_vPrintf(bTraceI2c, "i2c_BusWriteReg: Enter\n");
#endif

// First write I2C address + WRITE BIT on I2C bus
vAHI_SiMasterWriteSlaveAddr(u8Address, /* bReadStatus */ FALSE);
if (!bAHI_SiMasterSetCmdReg(/* bSetSTA */ E_AHI_SI_START_BIT,
/* bSetSTO */ E_AHI_SI_NO_STOP_BIT,
/* bSetRD */ FALSE,
/* bSetWR */ TRUE,
/* bSetAckCtrl */ FALSE,
/* bSetIACK */ FALSE))
{
#ifdef DEBUG_I2C_DRIVER
DBG_vPrintf(TRUE, "i2c_BusWriteReg: Exit 1\n");
#endif
return FALSE;
}

====================================》》》》》》   #1
while(bAHI_SiMasterPollTransferInProgress());

// Now write Command to I2C device
vAHI_SiMasterWriteData8(u8Command);

// Now write Data to I2C device
while (u8Length)
{
if (!bAHI_SiMasterSetCmdReg(/* bSetSTA */ E_AHI_SI_NO_START_BIT,
/* bSetSTO */ E_AHI_SI_NO_STOP_BIT,
/* bSetRD */ FALSE,
/* bSetWR */ TRUE,
/* bSetAckCtrl */ FALSE,
/* bSetIACK */ FALSE))
{
#ifdef DEBUG_I2C_DRIVER
DBG_vPrintf(TRUE, "i2c_BusWriteReg: Exit 2\n");
#endif
return FALSE;
}
while(bAHI_SiMasterPollTransferInProgress());

================================================》#2

vAHI_SiMasterWriteData8(*pu8Data);
u8Length -= 1;
pu8Data++;
}
if (!bAHI_SiMasterSetCmdReg(/* bSetSTA */ E_AHI_SI_NO_START_BIT,
/* bSetSTO */ E_AHI_SI_STOP_BIT,
/* bSetRD */ FALSE,
/* bSetWR */ TRUE,
/* bSetAckCtrl */ FALSE,
/* bSetIACK */ FALSE))
{
#ifdef DEBUG_I2C_DRIVER
DBG_vPrintf(TRUE, "i2c_BusWriteReg: Exit 3\n");
#endif
return FALSE;
}
while(bAHI_SiMasterPollTransferInProgress());

#ifdef DEBUG_I2C_DRIVER
DBG_vPrintf(bTraceI2c, "i2c_BusWriteReg: Leave\n");
#endif
return TRUE;
}

Outcomes