problems writing to internal EEPROM

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

problems writing to internal EEPROM

863 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alex on Fri Jan 25 02:42:11 MST 2013
Hi,

I started software development for the LPC4337 a few days ago. Currently I'm trying to write a driver for the internal EEPROM.

Unfortunately I'm not able to store data in the EEPROM.

Hopefully one of you can help.

Here is the code I've written:

<code>
//class constructor setting wait states and clock divider. The CPU runs at 200 MHz (MCK = 200000000)
CEEPAccess::CEEPAccess(void)
{
  EE_CLKDIV = (MCK / 1500000) - 1; //set clock divider as required for EEPROM usage
  EE_INTENCLR = (1 << 2);   //clear interrupt enable bit
  EE_AUTOPROG = 0;
  EE_PWRDWN = 0;
  EE_RWSTATE = (7 << 8) | 14; //8 waitstates in RPHASE 1 and 15 waitstates in RPHASE 2
  EE_WSTATE = (4 << 16) | (8 << 8) | 2; //5 waitstates in Phase 1, 9 waitstates in Phase 2 and 3 waitstates in Phase 3
}

//adr -> pointer to destination, data -> pointer to source, len -> number of bytes to copy
__ramfunc MEM_ERR CEEPAccess::WriteMemory(unsigned char* adr, unsigned int len, unsigned char* data)
{
  if((reinterpret_cast<int>(adr) < EEP_START_ADDRESS) || ((reinterpret_cast<int>(adr) + len) >= (EEP_START_ADDRESS + EEP_SIZE_BYTES)))
    return MEM_ERR_ADDRESS_ERR;
  do
  {
    *adr++ = *data++;   //copy from source buffer to destination in EEPROM
    --len;
    //if all bytes copied or reached a page boundary start programming the current page
    if((len == 0) || ((reinterpret_cast<int>(adr) & (EEP_PAGE_SIZE_BYTES - 1)) == 0))
    {
      EE_CMD = EEPROM_CMD_WRITE;        //write programming command to EEPROM command register
      unsigned int Time = SystemTimer::GetSystemTime();
      //wait until programming done or timeout
      while((!EE_INTSTAT_bit.END_OF_PROG) && ((SystemTimer::GetSystemTime() - Time) < 100));
      if(!EE_INTSTAT_bit.END_OF_PROG)   //if programming is not finished return error
        return MEM_ERR_ACCESS_DENIED;
      EE_INTSTATCLR = EE_INTSTATCLR_PROG_CLR_ST;  //clear program done interrupt flag
    }
  }while(len > 0);
  return MEM_ERR_NO_ERR;
}
</code>
Labels (1)
0 Kudos
4 Replies

804 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alex on Mon Feb 04 01:53:58 MST 2013
Hi Rolf,

thank you.

I got a little confused because the data sheet says that byte accesses are supported.

"The LPC435x/3x/2x/1x contain 16 kB of on-chip byte-erasable and byte-programmable
EEPROM memory."

Obviously the documentation is slightly inconsistent...

Best regards,
Alex
0 Kudos

804 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Sun Feb 03 23:57:25 MST 2013
Hi Alex,

I can confirm that only 32-bit access is supported.
Writing as byte or half-word is not possible.

The user manual says "...writing a minimum of 1 word (4 bytes) to a maximum of 32 words (128 bytes)...". That's a bit ambiguous, and it should rather explicitely mention that 8-bit and 16-bit access is forbidden.

Regards,
Rolf
0 Kudos

804 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alex on Fri Feb 01 08:15:07 MST 2013
Hi Rolf,

the problem is that the data is not written to the EEPROM. The memory content is still 0xFF on all bytes after applying the write command.

I modified my code to do 32 bit accesses instead of 8 bit. Now it works fine. So obviously bytewise writing is not supported.

Can somone confirm this?

Best regards,
Alex
0 Kudos

804 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Fri Jan 25 09:21:11 MST 2013
Hi Alex,

What exactly doesn't work? Do you get a timeout waiting for the END_OF_PROG bit, or does the data you write not end up in the EEPROM?

Does the constant EEPROM_CMD_WRITE have the value 6?

Regards,
Rolf

0 Kudos