Both examples mentioned before use the EMC interface, is a good starting point to understand how the External Memory Controller works. What I forgot to mentioned is that you can refer also to the periph_memtest demo in LPCOpen library to adjust the SDRAM initialization code to your needs.

Thanks for the link for lpcopen v2.10. I'm using an old one (v2.00). The code is very different so I will compare with mine.

To be more precise, my question is : on microcontroller' startup, my SDRAM is on self-refresh. How do you initialize the EMC and wake up the SDRAM? Do I have to follow the classic procedure then just add LPC_EMC->CONTROL &= ~(1 << 2); ?

No, the code is inside the microcontroller. Actually, I'm wondering if there is not nothing wrong with the schematic.

I made another test. I enter successfully (I think) in self-refresh with the code I posted two posts above. And I also successfully exit self-refresh (no lost of data) by running the same code I use to init the RAM (see my first post) WITHOUT shutting down the power.

So there's something wrong with power off.

I tried to use a bigger battery (3.6V) without success. I also tried to replace the external RAM (IS42S16800F-7TL) with another same RAM (MT48LC8M16A2P-6A:L) from another constructor and I have the same problem.

Regarding your doubt that you are not sure you are actually entering the self-refresh mode. I was checking the example periph_memtest of the LPCOpen. And when you reset the EMC module you go into self-refresh mode, I was able to see this change directly in the registers.

And after, in the function initDynMem once you make all the configurations of the memory you change to normal mode by just writing to the DynamicControl register. At this point I'm able to see also in the register that I enter successfully to normal mode.

Are you able to see these changes in your registers? This way you can be sure that you enter/exit correctly the self-refresh mode.

You mentioned that there is something wrong with the power off. A good idea to see if the problem is due to you are powering off the LPC would be to send the memory to self-refresh mode, then send the LPC to a low power mode (where you keep the state of the pins) and when you wake up the LPC you can check the state of the memory.

Sending the LPC to a low power mode instead of powering off the entire LPC will help to maintain the state of the EMC lines. When you power off the LPC you lose immediately the state of the EMC lines but since the memory is still active you might be changing the configuration of the memory.

Yes, I'm able to change the "SR" register from 0 to 1 and 1 to 0. The only difference I have with you is the CE register is always HIGH.

I tried to put this register on POWERSAVE just after writing the SR register to ENTER-SELF-REFRESH and write SR register to NORMAL_MODE at wake up but it's worse. I have much more bits corrupt.

The fact is I put the SDRAM in self refresh in case of low power. I need the memory even without main power (but with external battery). Thanks for pointing me about the state of the EMC lines. I checked the schematic. I have a door that force the CKE pin to down few time after the low power is detected. So I this time, the SDRAM is already in self-refresh when this door is activate and the LPC is not down.

I will check if the door is working as excepted. I also will try to sleep and to wake up the LPC.

After few weeks, I think I solved the problem. At least, it looks better.

It first, I found a "impossible" case in my code that leave self-refresh during the "alim low" interrupt. I removed that code. I can't tell if that was the problem but it looks to work better.

Another thing is I still lose some random bit every time I program the LPC1778. I think it's because the JTAG freeze the CKE pin during programming while the SDRAM is not in self-refresh. Can someone confirm ?