Writing/Reading EEPROM on LPC11U6x

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Writing/Reading EEPROM on LPC11U6x

Jump to solution
3,403 Views
sambennett
Contributor II

I'm using an LPC11U67 on a custom designed circuit board. I want to store the board serial number in the eeprom of the LPC. It seemed like this would be a simple task using the functions provided by LPC Open in eeprom.c/eeprom.h. I wrote the following functions to access the serial number. The problem is, every time I tried to read or write to eeprom I get a return code of 14 (#define IAP_ADDR_NOT_MAPPED         14 /*!< Address is not mapped in the memory map */). 

I tried changing the address to no avail. (On a side note, where is the eeprom located in memory, its not listed in the memory map in the datasheet.) I looked at the example code provided with LPC Open and I don't see any additional initialization steps that I'm not taking. I'm not quite sure what I'm missing. Is there another step I need to take before trying to invoke these commands? Is the address an absolute memory address?

#include "eeprom.h"

#define EEPROM_ADDRESS_ECHO_SN 64 //Top 64 bytes of eeprom are locked and cannot be written

uint8_t WriteSN(uint8_t SN){
 return Chip_EEPROM_Write(EEPROM_ADDRESS_ECHO_SN, &SN, 1);
}

uint8_t ReadSN(void){
 uint8_t SN = 255;
 uint8_t retCode = 0;

 retCode = Chip_EEPROM_Read(EEPROM_ADDRESS_ECHO_SN, &SN, 1);
 log_msg("EEPROM Read Return Code: %u", retCode);

return SN;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks,

Sam

Labels (2)
Tags (3)
1 Solution
2,336 Views
brianknittel
Contributor II

[EDIT: the URL in original post is no longer available. I have changed it to point to a link in the Internet Archive ]

Sam, I ran into this tonight too and found that the EEPROM IAP routine works when the buffer address is in main RAM (0x10000000 and up) but not in the smaller RAM blocks (0x20000000 and 0x20004000), which is where I had my data buffer. So, using a buffer on the stack solved the problem for me. YMMV.

By the way, for people landing here through search engines, there is an article about the speed of the on-chip EEPROM and interrupts here: https://web.archive.org/web/20131016034605/https://www.lpcware.com/content/blog/lpc1100lpc1300-eepro...

The built-in IAP routine disables interrupts for potentially many msec during large writes. The alternative library that NXP provides doesn't disable interrupts. 

[EDIT: I'm not finding the library available for download anywhere anymore. Anyone know where it is?]

View solution in original post

0 Kudos
4 Replies
2,337 Views
brianknittel
Contributor II

[EDIT: the URL in original post is no longer available. I have changed it to point to a link in the Internet Archive ]

Sam, I ran into this tonight too and found that the EEPROM IAP routine works when the buffer address is in main RAM (0x10000000 and up) but not in the smaller RAM blocks (0x20000000 and 0x20004000), which is where I had my data buffer. So, using a buffer on the stack solved the problem for me. YMMV.

By the way, for people landing here through search engines, there is an article about the speed of the on-chip EEPROM and interrupts here: https://web.archive.org/web/20131016034605/https://www.lpcware.com/content/blog/lpc1100lpc1300-eepro...

The built-in IAP routine disables interrupts for potentially many msec during large writes. The alternative library that NXP provides doesn't disable interrupts. 

[EDIT: I'm not finding the library available for download anywhere anymore. Anyone know where it is?]

0 Kudos
2,336 Views
athmesh_n
Contributor IV

Hello Brian and Sam, 

I've Similar issue as that of @sam bennet. 

One project that uses EEPROM works fine , the read and write EEPROM works successfully. 

But for another project the similar code does not work, returning 14 as result(memory not mapped). What can be the reason?

That link cannot be opened. 

0 Kudos
2,336 Views
sambennett
Contributor II

Hi,

As Brian figured out, your RAM variable must be in the main block of RAM otherwise the you get error 14. Perhaps in one of your projects the variable ends up in the main ram block and the other it does not. Check where in memory those variables end up.

One thing you could try, is to directly assign the ram variable to the main ram block. In the example below I'm storing a serial number in eeprom

uint8_t *s_ramVar = (uint8_t *)0x10000000; //The ram copy of the variable must be in the block of ram starting at address 0x10000000 otherwise the iap functions do not work

uint8_t Version_WriteSN(uint8_t SN){
*s_ramVar = SN;
uint8_t retCode = 255;
retCode = Chip_EEPROM_Write(EEPROM_ADDRESS_ECHO_SN, s_ramVar, 1);
return retCode;
}
2,336 Views
athmesh_n
Contributor IV

Hi Sam, 

Thank  you very much. Never knew we can write to a specified RAM address.

I solved my issue. Since the MCU setting of my project in IDE contains wrong RAM address, so whenever I use a variable, the address range goes beyond my MCU's RAM address.

So, I corrected the address range in MCU settings.

Anyway, thanks for your tip.

0 Kudos