ISD94100 Series Technical Reference Manual
Sep 9, 2019
Page
630
of 928
Rev1.09
IS
D
9
410
0
S
ER
IE
S
T
E
C
HN
ICA
L
RE
F
E
RE
NCE
M
AN
U
AL
g_u8DeviceAddr = slvaddr;
I2C_SET_CONTROL_REG(I2C0, I2C_STA);
/* again, generates START condition */
…
/* ------- I2C interrupt service routine: I2C_MasterTx ------ */
/* see sample code for Figure 6.13-13 */
/* ------- I2C interrupt service routine: I2C_MasterRx ------ */
if (u32Status == 0x08) {
/* START has been transmitted and prepare SLA+W */
I2C_SET_DATA(I2C0, (g_u8DeviceAddr << 1));
/* Write SLA+W to Register I2CDAT */
I2C_SET_CONTROL_REG(I2C0, I2C_SI);
/* write 1 to SI to clear the I2C interrupt flag */
}
else if (u32Status == 0x18) {
/* SLA+W has been transmitted and ACK has been received */
I2C_SET_DATA(I2C0, g_au8TxData[g_u8+]);
I2C_SET_CONTROL_REG(I2C0, I2C_SI);
}
else if (u32Status == 0x20) {
/* SLA+W has been transmitted and NACK has been received */
I2C_SET_CONTROL_REG(I2C0, I2C_STA | I2C_STO | I2C_SI);
}
else if (u32Status == 0x28) {
/* DATA has been transmitted and ACK has been received */
if (g_u8DataLen != 2) {
I2C_SET_DATA(I2C0, g_au8TxData[g_u8+]);
I2C_SET_CONTROL_REG(I2C0, I2C_SI);
} else {
I2C_SET_CONTROL_REG(I2C0, I2C_STA | I2C_SI);
}
}
else if (u32Status == 0x10) { /* Repeat START has been transmitted and prepare SLA+R */
I2C_SET_DATA(I2C0, (g_u8DeviceAddr << 1) | 0x01); /* Write SLA+R to Register I2CDAT */
I2C_SET_CONTROL_REG(I2C0, I2C_SI);
}
else if (u32Status == 0x40) { /* SLA+R has been transmitted and ACK has been received */
I2C_SET_CONTROL_REG(I2C0, I2C_SI);
}
else if (u32Status == 0x58) { /* DATA has been received and NACK has been returned */
g_u8RxData = I2C_GET_DATA(I2C0);
I2C_SET_CONTROL_REG(I2C0, I2C_STO | I2C_SI);
g_u8EndFlag = 1;
}
else {
/* To be added: handling for other status such as Arbitration Lost code 0x38, etc. */
}
In master mode if the device gets arbitration lost after START condition (status code 0x38), software
may set (STA, STO, SI, AA) = (1, 0, 1, X) to send repeated START so the master operation can
resume when bus is free, or set (STA, STO, SI, AA) = (0, 0, 1, X) to release I
2
C bus and enter not
addressed Slave mode.