Dear all,
I hope everything is fine with you. Anybody has an example which demonstrates how to use LPC1788's EEPROM? I have written the following code in C++ and it does not work, I am wondering what the problem might be:
#include "LPC177x_8x.h" // Device header unsigned int x = 0; int main() { LPC_EEPROM->CLKDIV = 319; LPC_EEPROM->WSTATE = (1<<0)|(6<<8)|(4<<16); LPC_EEPROM->INT_SET_ENABLE = 1<<26; // Enable write operation finished interrupt NVIC_EnableIRQ(EEPROM_IRQn); LPC_EEPROM->ADDR = 0x40; // ******************** LPC_EEPROM->CMD = 0x05; // 32 bit write command LPC_EEPROM->WDATA = 0x15; while(1); } void EEPROM_IRQHandler() { LPC_EEPROM->INT_CLR_STATUS = 1<<26; // Clear interrupt flag x = 10; }
Best regards
Hi,
I know it's a bit late to post an answer, but I hope my answer will be useful for other people. I've put my example just in the end of this post. Please always refer to the NXP LPC17xx user manual (the one I use is named UM10470)
With your values, I assume you are running the sysclock @ 120MHz. Be sure that your sysclock is running at 120MHz. Without any clock initialisation, I'm not sure if the CPU run at this speed by default.
CLKDIV ------ This value should be set accordingly with your sysclock. I highly recommend to setup all the internal clocks correctly before doing anything else.
EEWSTATE -------- If your sysclock is running @ 120MHz, your values are correct. Be sure you are running at 120MHz
Interrupt registers ------------------- The User Manual says :
The interrupt request output is asserted when the bitwise AND of STAT and INTEN is nonzero. For the EEPROM read/write operation finished interrupt it is betters not to enable the interrupt, but to only poll the bit in the STAT register. This is because these operations are relatively fast operations that do not justify calling a interrupt service subroutine in software.
So I think you should not use the interrupt service subroutine. I poll the STAT register and everything works fine for me.
****** THIS CODE IS RUNNING WITH EWARM of IAR EMBEDED WORBENCH ****** #define kEEPROM_END_OF_RW (Int32U) 0x1<<26 #define kEEPROM_END_OF_PROG (Int32U) 0x1<<28 void iEEPROM_setup(){ //Enable power (disable power down) EEPWRDWN_bit.PWRDWN = 0; //Set the wait state register EEWSTATE_bit.PHASE3 = 1; //96'000'000Hz ~= 10ns period, 15ns = 1x10ns + 10ns EEWSTATE_bit.PHASE2 = 5; //55ns = 5x10ns + 10ns EEWSTATE_bit.PHASE1 = 3; //35ns = 3x10ns + 10ns //Set clock preescaler to reach a 375 kHz clock //Th processor clock currently runs at 96 MHz // preescaler = (96 000 000 / 375 000) - 1 EECLKDIV_bit.CLKDIV = 255; //disable the interrupt (recommended by NXP) EEINTENCLR = kEEPROM_END_OF_RW || kEEPROM_END_OF_PROG; EEINTSTATSET = kEEPROM_END_OF_RW || kEEPROM_END_OF_PROG; //The EEPROM is now ready to receive commands }
Hope this will help