GPIOB_ModeCfg(GPIO_Pin_13 | GPIO_Pin_12, GPIO_ModeIN_PU);
#if(I2C_MODE == HOST_MODE)
PRINT(“IIC Host modern”);
I2C_Init(I2C_Mode_I2C, 400000, I2C_DutyCycle_16_9, I2C_Ack_Enable, I2C_AckAddr_7bit, TxAdderss);
while(I2C_GetFlagStatus(I2C_FLAG_BUSY) != RESET);
I2C_GenerateSTART(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(RxAdderss, I2C_Direc
tion_Transmitter);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
while(i 《 6)
{
if(I2C_GetFlagStatus(I2C_FLAG_TXE) != RESET)
{
I2C_SendData(TxData[i]);
i++;
}
}
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP(ENABLE);
#elif(I2C_MODE == SLAVE_MODE)
PRINT(“IIC Slave modern”);
I2C_Init(I2C_Mode_I2C, 400000, I2C_DutyCycle_16_9, I2C_Ack_Enable, I2C_AckAddr_7bit, RxAdderss);
while(!I2C_CheckEvent(I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED));
while(i 《 6)
{
if(I2C_GetFlagStatus(I2C_FLAG_RXNE) != RESET)
{
RxData[i] = I2C_ReceiveData();
i++;
}
}
PRINT(“RxData:rn”);
for(i = 0; i 《 6; i++)
{
PRINT(“%02xrn”, RxData[i]);
}
#endif
例程里面提供的IIC例程如上所示,虽然做了很多改动,但是还是无法读写24C256.不知道错在哪里了,帮忙传一个可用的硬件IIC例程。谢谢