lpcware

Writing to the EEPROM on the LPC11U37

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by psatyshur on Thu Dec 26 13:06:55 MST 2013
I am attempting to write to the EEPROM on the LPC11U37 and have run into some difficulties. I first tried the IAP commands:

uint8_t EEPROM_Write(uint8_t AddressToWrite, uint8_t *DataArray, uint8_t BytesToWrite)
{
unsigned int IAP_Command[5];
unsigned int IAP_Result[5];

IAP_Result[0] = 0;

IAP_Command[0] = IAP_EEPROM_WRITE;//EEPROM write command (61)
IAP_Command[1] = (unsigned int)AddressToWrite;//EEPROM address
IAP_Command[2] = *DataArray;//RAM address
IAP_Command[3] = (unsigned int)BytesToWrite;        //Number of bytes to write
IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz

iap_entry(IAP_Command, IAP_Result);

return (uint8_t)IAP_Result[0];
}

uint8_t EEPROM_Read(uint8_t AddressToRead, uint8_t *DataArray, uint8_t BytesToRead)
{
unsigned int IAP_Command[5];
unsigned int IAP_Result[5];

IAP_Result[0] = 0;

IAP_Command[0] = IAP_EEPROM_READ;//EEPROM read command (62)
IAP_Command[1] = (unsigned int)AddressToRead;//EEPROM address
IAP_Command[2] = *DataArray;//RAM address
IAP_Command[3] = (unsigned int)BytesToRead;//Number of bytes to read
IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz

iap_entry(IAP_Command, IAP_Result);

return (uint8_t)IAP_Result[0];
}


I also reserved 32 bytes for the IAP functions following this guide. [s]Note: I did not disable interrupts during this function.[/s] EDIT: I tried disabling interrupts around the iap_entry() function. The same problem occurred.

The returned value is always 14, and nothing is written to the EEPROM. This does not seem to be a valid return value. What does this return value mean?

To remove the requirement to disable interrupts, I decided to use the LPC1100/LPC1300 EEPROM library. This required changes to the code

uint8_t EEPROM_Write(uint8_t AddressToWrite, uint8_t *DataArray, uint8_t BytesToWrite)
{
EELIB_Command IAP_Command;
EELIB_Result IAP_Result;

IAP_Result[0] = 0;

//TODO: check to make sure the address is valid

IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_WRITE;//EEPROM write command
IAP_Command[1] = (unsigned int)AddressToWrite;//EEPROM address
IAP_Command[2] = *DataArray;//RAM address
IAP_Command[3] = (unsigned int)BytesToWrite;//Number of bytes to write
IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz

EELIB_entry(IAP_Command, IAP_Result);

return (uint8_t)IAP_Result[0];
}

uint8_t EEPROM_Read(uint8_t AddressToRead, uint8_t *DataArray, uint8_t BytesToRead)
{
EELIB_Command IAP_Command;
EELIB_Result IAP_Result;

IAP_Result[0] = 0;

//TODO: check to make sure the address is valid

IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_READ;//EEPROM read command
IAP_Command[1] = (unsigned int)AddressToRead;//EEPROM address
IAP_Command[2] = *DataArray;//RAM address
IAP_Command[3] = (unsigned int)BytesToRead;//Number of bytes to read
IAP_Command[4] = SystemCoreClock/1000;//System clock frequency in kHz

EELIB_entry(IAP_Command, IAP_Result);

return (uint8_t)IAP_Result[0];
}


I added the library to the project and included the header file. When I run the EEPROM_Read() function, it hangs the controller. Am I missing something in my implementation of the library functions?

Outcomes