明天就要比赛了,还是把这个发完吧,预祝明天大家取得好成绩>:<
要把官网给的代码拷贝到你的文件当中
因为在这个文件当中,他帮你配置好了
只需要你使用i2c_init() 就可以配置好gpio
再就是i2c的代码
初始化
I2CInit();
uchar eerpom_read( uchar address)
{
uchar dat;
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(address);
I2CWaitAck();
I2CStop();
I2CStart();
I2CSendByte(0xa1);
I2CWaitAck();
dat = I2CReceiveByte();
I2CWaitAck();
I2CStop();
return dat;
}
void eerpom_write(uchar address,uchar dat)
{
I2CStart();
I2CSendByte(0xa0);
I2CWaitAck();
I2CSendByte(address);
I2CWaitAck();
I2CSendByte(dat);
I2CWaitAck();
I2CStop();
}
测试一下
eerpom_write(1,2);
HAL_Delay(5);
eerpom = eerpom_read(1);
HAL_Delay(5);
注意要延时一下,不然数据不对。