Skip to main content
ah_it
Associate
Dec 19, 2018 12:06 PM UTC
Question

Read EEPROM

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

After Forever
Senior III
Dec 19, 2018 2:24 PM UTC

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;
}

ah_it
ah_itAuthor
Associate
Feb 5, 2019 8:34 AM UTC

Thank you @After Forever​