Content originally posted in LPCWare by alimicro on Mon May 13 12:05:27 MST 2013Hi have used below address as a reference for EMC:
<a href="http://www.embedinfo.com/en/list.asp?id=107">http://www.embedinfo.com/en/list.asp?id=107</a>
in this schematic have used 2xMT48lc16m16 which is obtain 64MB in 32bit structure.
I'am trying to change the CMSIS sample codes for OEM509 board but I can't
here is the SDRAMInit code:
<h4>void SDRAMInit( void )</h4><h4>{</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>volatile uint32_t i;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>volatile unsigned long Dummy;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_16 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_17 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_18 = 0x21;</h4><h4> </h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_19 = 0x21;</h4><h4> </h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_20 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_24 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_28 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_29 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_30 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P2_31 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_0 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_1 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_2 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_3 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_4 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_5 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_6 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_7 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_8 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_9 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_10 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_11 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_12 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_13 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_14 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_15 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_16 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_17 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_18 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_19 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_20 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_21 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_22 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_23 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_24 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_25 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_26 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_27 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_28 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_29 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_30 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P3_31 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_0 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_1 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_2 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_3 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_4 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_5 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_6 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_7 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_8 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_9 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_10 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_11 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_12 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_13 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_14 = 0x21;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_IOCON->P4_25 = 0x21;</h4><h4> </h4><h4> </h4><h4> </h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>//<span class="Apple-tab-span" style="white-space: pre;"> </span>EMC_Init();</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// Init SDRAM controller</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_SC->PCONP <span class="Apple-tab-span" style="white-space: pre;"> </span>|= 0x00000800;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>/*Init SDRAM controller*/</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_SC->EMCDLYCTL |= (8<<0);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>/*Set data read delay*/</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_SC->EMCDLYCTL |=(8<<8);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_SC->EMCDLYCTL |= (0x08 <<16);</h4><h4> </h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->Control =1;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicReadConfig = 1;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRasCas0 = 0;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRasCas0 |=(3<<8);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRasCas0 |= (3<<0);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRP = P2C(SDRAM_TRP);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRAS = P2C(SDRAM_TRAS);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicSREX = P2C(SDRAM_TXSR);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicAPR = SDRAM_TAPR;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicDAL = SDRAM_TDAL+P2C(SDRAM_TRP);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicWR = SDRAM_TWR;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRC = P2C(SDRAM_TRC);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRFC = P2C(SDRAM_TRFC);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicXSR = P2C(SDRAM_TXSR);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRRD = P2C(SDRAM_TRRD);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicMRD = SDRAM_TMRD;</h4><h4> </h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// 13 row, 9 - col, SDRAM</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicConfig0 = 0x0004680;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// JEDEC General SDRAM Initialization Sequence</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// DELAY to allow power and clocks to stabilize ~100 us</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// NOP</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicControl = 0x0183;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>for(i= 200*30; i;i--);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// PALL</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicControl = 0x0103;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRefresh = 2;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>for(i= 256; i; --i); // > 128 clk</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicRefresh = P2C(SDRAM_REFRESH) >> 4;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// COMM</h4><h4> </h4><h4> LPC_EMC->DynamicControl = 0x00000083; /* Issue MODE command */</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>Dummy = *((volatile uint32_t *)(SDRAM_BASE_ADDR | (0x32<<13)));</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>// NORM</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicControl = 0x0000;</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>LPC_EMC->DynamicConfig0 |=(1<<19);</h4><h4><span class="Apple-tab-span" style="white-space: pre;"> </span>for(i = 100000; i;i--);</h4><h4> </h4><h4>}</h4>
with such a source code controller can write values less than 0x200000
above that it will be crazy. here is part of source code:
<h3>wr_ptr = (uint32_t *)SDRAM_BASE_ADDR;</h3><h3>*wr_ptr = 0xFFFF0A0A;</h3><h3>v1=(unsigned long)(*wr_ptr);</h3><h3>*wr_ptr = 0x00000012;</h3><h3>v2=(unsigned long)(*wr_ptr);</h3><h4>and results are:</h4><h4>v1=0x88C9760A</h4><h4>v2=0x00000012</h4>
the datasheet is so mysterious and there is no forum and no discussion about it.
please help me
<code>
</code>