这是我的读写函数,这个应该是没问题的,因为我这个是教程上的代码
void iic_24c02_write(uint8_t *pucBuf,uint8_t ucAddr,uint8_t ucNum)
{
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(ucAddr);
I2CWaitAck();
while(ucNum--)
{
I2CSendByte(*pucBuf++);
I2CWaitAck();
}
I2CStop();
delay1(500);
}
void iic_24c02_read(unsigned char *pucBuf,unsigned char ucAddr,unsigned char ucNum)
{
uint8_t data = 0;
uint8_t i ;
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(ucAddr);
I2CWaitAck();
I2CStart();
I2CSendByte(0xa1);
I2CWaitAck();
while(ucNum--)
{
*pucBuf++ = I2CReceiveByte();
if(ucNum)
{
I2CSendAck();
}
else
{
I2CSendNotAck();
}
}
I2CStop();
}
这是我在main.c中定义的两个数组与我的main函数
//EEPROM相关变量
unsigned char EEPROM_String_1[5]={0x11,0x22,0x33,0x44,0x55};
unsigned char EEPROM_String_2[5]={0};
int main(void)
{
HAL_Init();
SystemClock_Config();
LED_Init();
KEY_Init();
LCD_Init();
LCD_Clear(White);
LCD_SetBackColor(White);
LCD_SetTextColor(Blue);
I2CInit();
iic_24c02_write(EEPROM_String_1,0,5); //将数据写入
HAL_Delay(10);
iic_24c02_read(EEPROM_String_2,0,5); //读取数据
while (1)
{
Lcd_proc(); //显示读取的结果
}
}