一、cubemx
PB6/PB7->gpio_output
二、keil
at24c02手册->地址为1010000R(1)/W(0)0
导入I2c库
i2c.c
uint8_t eeprom_read(uint8_t addr)
{
uint8_t dat;
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(addr);
I2CWaitAck();
I2CStop();
I2CStart();
I2CSendByte(0xa1);
I2CWaitAck();
dat=I2CReceiveByte();
I2CSendNotAck();
I2CStop();
return dat;
}
uint8_t eeprom_write(uint8_t addr,uint8_t dat)
{
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(addr);
I2CWaitAck();
I2CSendByte(dat);
I2CWaitAck();
I2CStop();
}
main.c
uint8_t eep_temp=(eeprom_read(1)<<8)+eeprom_read(2);
sprintf(text," frq_eep=%d ",eep_temp);
LCD_DisplayStringLine(Line9, (unsigned char *)text);