写部分代码:
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2C1, ENABLE);//发送起始信号
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));//检测EV5
I2C_Send7bitAddress(I2C1, 0xa0, I2C_Direction_Transmitter);//发送从设备地址并设置方向
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));//检测EV6
I2C_SendData(I2C1, 0x05);//发送地址
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));//检测EV8
I2C_SendData(I2C1, 0x05);//发送写数据
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));//检测EV8
I2C_GenerateSTOP(I2C1, ENABLE);//发送停止信号
读代码:
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));//检测EV5
I2C_AcknowledgeConfig(I2C1, DISABLE);
I2C_Send7bitAddress(I2C1, 0xa0, I2C_Direction_Transmitter);//发送从设备地址并设置方向
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));//检测EV6
I2C_SendData(I2C1, 0x05);//发送读地址
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));//检测EV8
I2C_GenerateSTART(I2C1, ENABLE);//发送起始信号
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));//检测EV5
I2C_Send7bitAddress(I2C1, 0xa0, I2C_Direction_Receiver);//从地址并设置方向
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));//检测EV7
I2C_SendData(I2C1, 0x05);
//while(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));//检测EV7
I2C_GenerateSTOP(I2C1, ENABLE);//发送停止信号
EPROM_Rec[0] = I2C_ReceiveData(I2C1);