cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM read/write

Chayan Roy
Associate III
Posted on March 02, 2017 at 09:46

Hello, Does any one STM8s EEPROM data memory read and write example.

4 REPLIES 4
martonmiklos
Senior
Posted on March 02, 2017 at 10:00

void EEWriteU8(uint16_t address, uint8_t value)
{
 // Check if the EEPROM is write-protected. If it is then unlock the EEPROM.
 if (FLASH_IAPSR_bits.DUL == 0) {
 FLASH_DUKR = 0xAE;
 FLASH_DUKR = 0x56;
 }
 // Write the data to the EEPROM.
 (*(uint8_t *) (0x4000 + address)) = value;
 // Now write protect the EEPROM.
 FLASH_IAPSR_bits.DUL = 0;
}
void EEWriteArray(uint16_t address, uint8_t *src, uint8_t count)
{
 uint8_t i = 0;
 uint8_t *EEAddress;
 // Check if the EEPROM is write-protected. If it is then unlock the EEPROM.
 if (FLASH_IAPSR_bits.DUL == 0) {
 FLASH_DUKR = 0xAE;
 FLASH_DUKR = 0x56;
 }
 // Write the data to the EEPROM.
 EEAddress = (uint8_t *) (0x4000 + address); // EEPROM base address.
 for (; i < count; i++) {
 *EEAddress = src[i];
 EEAddress++;
 }
 // Now write protect the EEPROM.
 FLASH_IAPSR_bits.DUL = 0;
}
void EEReadArray(uint16_t address, uint8_t * dest, uint8_t count)
{
 uint8_t i = 0;
 // Write the data to the EEPROM.
 uint8_t *EEAddress = (uint8_t *) (0x4000 + address); // EEPROM base address.
 for (; i < count; i++) {
 dest[i] = *EEAddress;
 EEAddress++;
 }
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

S.Ma
Principal
Posted on March 02, 2017 at 10:17

Try this 

https://community.st.com/0D50X00009XkW1qSAF

 
SBadd
Associate II

Can any one say how should I store counter value in eeprom so that if power is gone it will store tha value of counter?

Counter is a variable I am using for 5 digit 7 segment display​

ADC WATCH DOG  VOLTAGE LEVEL & INTERRUPT.

measure voltage in the one of the adc chanel & use adc low voltage level watchdog interrupt in the specified voltage