I'm looking for code examples for internal EEPROM access for the LPC4337 and there is next to nothing out there.
Appreciate any feedback however trivial.
It's a great micro, but support seems limited.
Hi, Stephen,
Pls download the LPC open package from the link:
There is eeprom example code in the directory:
C:\DriveE\LPCOpenDirectory\Keil_IAR\LPC4337\LPC43xx_18xx\examples_43xx_18xx\periph_eeprom\src
I just copy part of the code from eeprom.c
/* Read data from EEPROM */
/* size must be multiple of 4 bytes */
STATIC void EEPROM_Read(uint32_t pageOffset, uint32_t pageAddr, uint32_t* ptr, uint32_t size)
{
uint32_t i = 0;
uint32_t *pEepromMem = (uint32_t*)EEPROM_ADDRESS(pageAddr,pageOffset);
for(i = 0; i < size/4; i++) {
ptr[i] = pEepromMem[i];
}
}
/* Erase a page in EEPROM */
STATIC void EEPROM_Erase(uint32_t pageAddr)
{
uint32_t i = 0;
uint32_t *pEepromMem = (uint32_t*)EEPROM_ADDRESS(pageAddr,0);
for(i = 0; i < EEPROM_PAGE_SIZE/4; i++) {
pEepromMem[i] = 0;
#if AUTOPROG_ON
Chip_EEPROM_WaitForIntStatus(LPC_EEPROM, EEPROM_INT_ENDOFPROG);
#endif
}
#if (AUTOPROG_ON == 0)
Chip_EEPROM_EraseProgramPage(LPC_EEPROM);
#endif
}
/* Write data to a page in EEPROM */
/* size must be multiple of 4 bytes */
STATIC void EEPROM_Write(uint32_t pageOffset, uint32_t pageAddr, uint32_t* ptr, uint32_t size)
{
uint32_t i = 0;
uint32_t *pEepromMem = (uint32_t*)EEPROM_ADDRESS(pageAddr,pageOffset);
if(size > EEPROM_PAGE_SIZE - pageOffset)
size = EEPROM_PAGE_SIZE - pageOffset;
for(i = 0; i < size/4; i++) {
pEepromMem[i] = ptr[i];
#if AUTOPROG_ON
Chip_EEPROM_WaitForIntStatus(LPC_EEPROM, EEPROM_INT_ENDOFPROG);
#endif
}
#if (AUTOPROG_ON == 0)
Chip_EEPROM_EraseProgramPage(LPC_EEPROM);
#endif
}
for lpc43xx, there are 16KB EEPROM, which consists of 128 pages, each pages includes 128 bytes(32 words)
Hope it can help you
BR
XiangJun Rong