/*******************************************************************************
* Function Name? : AT24CXX_Init? ?
* Description? ? : Initializes AT24xx EEPROM.?
* Input? ? ? ? ? : None
* Return? ? ? ? ?: None
********************************************************************************/
void AT24CXX_Init(void)
{
IIC_Init( 100000, 0xA0);
}
/*******************************************************************************
* Function Name? : AT24CXX_ReadOneByte? ?
* Description? ? : Read one data from EEPROM.?
* Input? ? ? ? ? : ReadAddr: Read frist address.
* Return? ? ? ? ?: temp: Read data.
********************************************************************************/
u8 AT24CXX_ReadOneByte(u16 ReadAddr)
{
u8 temp=0;
while( I2C_GetFlagStatus( I2C1, I2C_FLAG_BUSY ) != RESET );
I2C_GenerateSTART( I2C1, ENABLE );
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_MODE_SELECT ) );??
I2C_Send7bitAddress( I2C1, 0XA0, I2C_Direction_Transmitter );
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) );?
#if (Address_Lenth? == Address_8bit)
I2C_SendData( I2C1, (u8)(ReadAddr&0x00FF) );
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );??
#elif (Address_Lenth? == Address_16bit)
I2C_SendData( I2C1, (u8)(ReadAddr>>8) );? ?
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );?
I2C_SendData( I2C1, (u8)(ReadAddr&0x00FF) );??
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );?
#endif
I2C_GenerateSTART( I2C1, ENABLE );
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_MODE_SELECT ) );?
I2C_Send7bitAddress( I2C1, 0XA0, I2C_Direction_Receiver );
while( !I2C_CheckEvent( I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ) );? ?
?
? while( I2C_GetFlagStatus( I2C1, I2C_FLAG_RXNE ) ==? RESET )
I2C_AcknowledgeConfig( I2C1, DISABLE );---------------改為ENABLE,不行,,
temp = I2C_ReceiveData( I2C1 );
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--------------視乎這里還要添加代碼,但不知如何寫。。。。
? I2C_GenerateSTOP( I2C1, ENABLE );
return temp;
}
------------------
哪為高手做過,給個示例代碼參考。。。謝謝。