lpcware

EEPROM Wait States

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by Randy Nuss on Sun Mar 24 12:37:11 MST 2013
I could use more explanation of the EEPROM wait-state settings.  The user manual states: (waitstates+1)x Tclk >= duration.  But what duration is required?

I am running the lpc4337 at 80MHz.  With the code below, a write changes an address from 0xffffffff to 0x00000000, but does not store the data.


#define EEPROM_BASE (uint32_t)0x20040000

volatile uint32_t *eeprom_ptr = (uint32_t *)EEPROM_BASE;

/*********************************************************************//**
* @briefeeprom initialization
* @param[in]None
* @return None
**********************************************************************/
void eeprom_init (void)
{
uint32_t ee_clk;

ee_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_EEPROM);


LPC_EEPROM->EECLKDIV = (ee_clk / 1500000) - 1; // 31 ;/CGU_GetPCLKFrequency(CGU_PERIPHERAL_EEPROM)/EEPROM clock=1500 KHz
LPC_EEPROM->EEPWRDWN = 0x0;
//LPC_EEPROM->INT_CLR_STATUS = (1 << 2);
//LPC_EEPROM->EERWSTATE = ((ee_clk / 28571429) << 8) | (ee_clk / 14285714); //(0x3 | 0x5<<8);// Read waitstates.
//LPC_EEPROM->EEWSTATE = ((ee_clk / 50000000) << 16) | ((ee_clk / 25000000) << 8) | (ee_clk / 100000000); // (0x2 | 0x3<<8 | 0x2<<16);//EEPROM wait state register
LPC_EEPROM->EERWSTATE = (7 << 8) | 14;
LPC_EEPROM->EEWSTATE = (4 << 16) | (8 << 8) | 2;
// Enable AUTOPROG -erase program cycle is handled by hardware after each word is written
LPC_EEPROM->EEPAUTOPROG = 0; //0x1;
}

/*********************************************************************//**
* @briefeeprom write
* @param[in]None
* @return None
**********************************************************************/
void eeprom_write (uint32_t offset, uint32_t *buff, uint32_t word_cnt)
{
while (word_cnt--)
{
eeprom_ptr[offset] = *buff;
LPC_EEPROM->INT_CLR_STATUS = 1<<2;   // Clear Program int status bit

++offset;
++buff;
}

LPC_EEPROM->EECMD = 0x6;    // program EEPROM page
while ( !(LPC_EEPROM->INT_STATUS & (1<<2)) );      // Wait until programming is done

}

Outcomes