初始化部分,这个部分可以成功的写入,和读出来
void EEPROM_Init(void)
{
//unlock EEPROM
FLASH->DUKR = 0xAE;
FLASH->DUKR = 0x56;
EEP_Wait_Finished();
if ((eeprom_variable[0]=='T') && (eeprom_variable[1]=='G') && (eeprom_variable[2]==8) && (eeprom_variable[3]==0x00))
{
Remote_ID[0] = E2_ReadMem(0);
Remote_ID[1] = E2_ReadMem(1);
Remote_ID[2] = E2_ReadMem(2);
Remote_ID[3] = E2_ReadMem(3);
}
else
{
Remote_ID[0] = 0xaa; //第一次
Remote_ID[1] = 0xaa;
Remote_ID[2] = 0xaa;
Remote_ID[3] = 0xaa;
E2_WriteBurst(0, 4, Remote_ID);
E2_ResetEEPROM();
}
EEP_Wait_Finished();
}
void E2_ResetEEPROM(void)
{
EEP_Wait_Finished();
eeprom_variable[0] = 'T'; //"TG80" is written in the EEPROM
EEP_Wait_Finished();
eeprom_variable[1] = 'G'; //This allows to check later that the EEPROM content is valid.
EEP_Wait_Finished();
eeprom_variable[2] = 8;
EEP_Wait_Finished();
eeprom_variable[3] = 0x00;
EEP_Wait_Finished();
}
在这个部分,写入ID时就是写不进去。奇怪?
if(Save_ID_标志寄存器 == 1 && RX_buf[4] == 15) //学习模式,保存ID
{
Save_ID_标志寄存器 = 0;
Remote_ID[0] = RX_buf[0]; // ID
Remote_ID[1] = RX_buf[1];
Remote_ID[2] = RX_buf[2];
Remote_ID[3] = RX_buf[3];
//E2_WriteBurst(0, 4, Remote_ID);
EEP_Wait_Finished();
eeprom_variable[4] = Remote_ID[0]; //"TG80" is written in the EEPROM
EEP_Wait_Finished();
eeprom_variable[5] = Remote_ID[1]; //This allows to check later that the EEPROM content is valid.
EEP_Wait_Finished();
eeprom_variable[6] = Remote_ID[2];
EEP_Wait_Finished();
eeprom_variable[7] = Remote_ID[3];
EEP_Wait_Finished();
} |