// Master Transmitter, then Test on I2C1 EV6 and first EV8 and clear them. case I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED: // 0x00070082. 发出写指定I2C从设备时产生的事件:EV8 just after EV6 // Send the first data. I2C_SendData(I2C1, gstruI2C_ComInst.m_Au8SndOrRecBuf[gstruI2C_ComInst.m_u8DatIdx]); gstruI2C_ComInst.m_u8DatIdx++; break; case I2C_EVENT_MASTER_BYTE_TRANSMITTING: // 0x00070080. 正在发送数据中...... lu8BusyCount = 0; break; // Test on I2C1 EV8 and clear it. case I2C_EVENT_MASTER_BYTE_TRANSMITTED: // 0x00070084. 一个字节数据发送完成. if(gstruI2C_ComInst.m_u8DatIdx < gstruI2C_ComInst.m_u8SndOrRecLen) { // Transmit I2C1 data I2C_SendData(I2C1, gstruI2C_ComInst.m_Au8SndOrRecBuf[gstruI2C_ComInst.m_u8DatIdx]); gstruI2C_ComInst.m_u8DatIdx ++; } else { // Send I2C1 STOP Condition I2C_GenerateSTOP(I2C1, ENABLE); delay( 50 ); // NOTE: 非常关键哟,不同的器件,延时可能不一样. gstruI2C_ComInst.m_u8Finished = CNT_I2C_FINISHED_YES; } lu8BusyCount = 0; // 发送了数据,不为busy. break; // Master Receiver case I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED: // 0x00030002. 发出读指定I2C从设备时产生的事件:EV6 if(gstruI2C_ComInst.m_u8SndOrRecLen == 1) { // Disable I2C1 acknowledgement I2C_AcknowledgeConfig(I2C1, DISABLE); // Send I2C1 STOP Condition I2C_GenerateSTOP(I2C1, ENABLE); } break;
case I2C_EVENT_MASTER_BYTE_RECEIVED: //0x00030040. 主收到一个字节时产生的事件:EV7. // BUSY, MSL and RXNE flags. case 0x00030044: // BUSY, MSL and RXNE, BTF flags. // Store I2C1 received data gstruI2C_ComInst.m_Au8SndOrRecBuf[gstruI2C_ComInst.m_u8DatIdx++] = I2C_ReceiveData(I2C1);