Skip to main content
Visitor II
March 2, 2017
Question

EEPROM read/write

  • March 2, 2017
  • 3 replies
  • 3935 views
Posted on March 02, 2017 at 09:46

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

    This topic has been closed for replies.

    3 replies

    Visitor II
    March 2, 2017
    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++;
     }
    }
    �?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Visitor II
    March 2, 2017
    Posted on March 02, 2017 at 10:17

    Try this 

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

     
    Visitor II
    March 2, 2019

    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​

    Visitor II
    January 10, 2024

    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