write i2c data to EEPROM
This commit is contained in:
parent
d02facf754
commit
df611e4436
33
main.c
33
main.c
|
@ -500,6 +500,39 @@ level pulse on the Hot Plug Detect pin. This pulse shall be at least 100 msec.
|
|||
}
|
||||
}
|
||||
*/
|
||||
if (i2c_prog) { // received data over i2c to be programmed
|
||||
if (EDID_PORT->IDR.reg & EDID_PIN) { // EDID switched off
|
||||
puts("I²C prog disabled\r\n");
|
||||
} else { // EDID programming allowed
|
||||
/*
|
||||
puts("I²C prog ");
|
||||
puth(i2c_data);
|
||||
puts("@");
|
||||
puth(i2c_addr);
|
||||
puts("\r\n");
|
||||
*/
|
||||
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
|
||||
// disable DATA (e.g. EEPROM) write protection
|
||||
if (0 == (FLASH_IAPSR & FLASH_IAPSR_DUL)) {
|
||||
FLASH_DUKR = FLASH_DUKR_KEY1;
|
||||
FLASH_DUKR = FLASH_DUKR_KEY2;
|
||||
}
|
||||
// save need EDID
|
||||
*(uint8_t*)(EEPROM_ADDR + i2c_addr) = i2c_data; // write byte
|
||||
while (FLASH_CR2 & FLASH_CR2_WPRG); // wait for write to complete
|
||||
// check if programming failed
|
||||
// we don't check for WR_PG_DIS (while checking EOP) because EEPROM isn't (and can't be) write protected
|
||||
if (!(FLASH_IAPSR & FLASH_IAPSR_EOP)) {
|
||||
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
|
||||
LED_PORT->ODR.reg &= ~LED_PIN; // switch LED on to indicate programming failed
|
||||
//I2C_CR2 &= I2C_CR2_ACK; // NACK next received byte
|
||||
puts("EEPROM byte prog failed\r\n");
|
||||
}
|
||||
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
|
||||
}
|
||||
action = true; // re-run loop
|
||||
i2c_prog = false; // clear flag
|
||||
}
|
||||
if (action) { // something has been performed, check if other flags have been set meanwhile
|
||||
action = false; // clear flag
|
||||
} else { // nothing down
|
||||
|
|
Loading…
Reference in New Issue