Skip to main content
Visitor II
December 19, 2018
Question

Read EEPROM

  • December 19, 2018
  • 2 replies
  • 838 views

Hi.

I want to read the EEPROM but i don't see any function for this. i write my data in eeprom by hal_flashex_dataeeprom_program() function and i want transmit eeprom's data with uart to pc. how can i do this?

    This topic has been closed for replies.

    2 replies

    Visitor II
    December 19, 2018

    You just read it as if any other const data array in the flash memory. If you want a function then you could write something like this to read from it:

    int read_from_eeprom(uint8_t *destination, unsigned int position, unsigned int len)
    {
     const unsigned int eeprom_length = DATA_EEPROM_END - DATA_EEPROM_BASE + 1;
     unsigned int i;
     
     if (position + len > eeprom_length) {
     return -1;
     }
     
     for (i = 0; i < len; i++) {
     destination[i] = *((volatile uint8_t *)(DATA_EEPROM_BASE + position + i));
     }
     
     return 0;
    }

    ahAuthor
    Visitor II
    February 5, 2019

    Thank you @After Forever​