我外挂了一个SRAM,是16位宽的,SRAM的片选引脚接到芯片的(EMC_CS1),那么访问这SRAM的地址为0x90000000,
我写了个测试程序,是往SRAM中写入数据,再把它读出来,经串口发送出来。
但发现写入地址0x90000000,0x90000001等于0xad47时,0x90000003,0x90000004的地址数据也等于0xad47了。
硬件已按照手册上的电路要求连接了,MCU硬件上的A0地址是空着的,试过用网上的初始化EMC例程测试,发现也是有这问题,
串口程序可以确定是正常的。SRAM芯片也换过一只。查了很久,没有发现什么问题,为什么有这问题?
程序如下;
void EMC_GPIO_Init (void)//配置GPIO寄存器
{
LPC_IOCON->P3_0 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D0 @ P3.0 */
LPC_IOCON->P3_1 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D1 @ P3.1 */
LPC_IOCON->P3_2 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D2 @ P3.2 */
LPC_IOCON->P3_3 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D3 @ P3.3 */
LPC_IOCON->P3_4 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D4 @ P3.4 */
LPC_IOCON->P3_5 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D5 @ P3.5 */
LPC_IOCON->P3_6 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D6 @ P3.6 */
LPC_IOCON->P3_7 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D7 @ P3.7 */
LPC_IOCON->P3_8 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D8 @ P3.8 */
LPC_IOCON->P3_9 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D9 @ P3.9 */
LPC_IOCON->P3_10 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D10 @ P3.10 */
LPC_IOCON->P3_11 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D11 @ P3.11 */
LPC_IOCON->P3_12 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D12 @ P3.12 */
LPC_IOCON->P3_13 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D13 @ P3.13 */
LPC_IOCON->P3_14 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D14 @ P3.14 */
LPC_IOCON->P3_15 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D15 @ P3.15 */
// LPC_IOCON->P4_0 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A0 @ P4.0 */
LPC_IOCON->P4_1 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A1 @ P4.1 */
LPC_IOCON->P4_2 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A2 @ P4.2 */
LPC_IOCON->P4_3 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A3 @ P4.3 */
LPC_IOCON->P4_4 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A4 @ P4.4 */
LPC_IOCON->P4_5 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A5 @ P4.5 */
LPC_IOCON->P4_6 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A6 @ P4.6 */
LPC_IOCON->P4_7 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A7 @ P4.7 */
LPC_IOCON->P4_8 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A8 @ P4.8 */
LPC_IOCON->P4_9 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A9 @ P4.9 */
LPC_IOCON->P4_10 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A10 @ P4.10 */
LPC_IOCON->P4_11 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A11 @ P4.11 */
LPC_IOCON->P4_12 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A12 @ P4.12 */
LPC_IOCON->P4_13 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A13 @ P4.13 */
LPC_IOCON->P4_14 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A14 @ P4.14 */
LPC_IOCON->P4_15 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A15 @ P4.15 */
LPC_IOCON->P4_16 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A16 @ P4.16 */
LPC_IOCON->P4_17 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A17 @ P4.17 */
LPC_IOCON->P4_18 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A18 @ P4.18 */
LPC_IOCON->P4_25 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* WEN @ P4.25 */
LPC_IOCON->P4_24 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* OEN @ P4.24 */
LPC_IOCON->P4_26 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* BLSN[0] @ P4.26 */
LPC_IOCON->P4_27 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* BLSN[1] @ P4.27 */
LPC_IOCON->P4_31 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* M_CS[1] @ P4.31 */
}
void SRAM_Init(void)
{
LPC_SC->PCONP |= 0x00000800; /* Enable External Memory Controller power/clock */
EMC_GPIO_Init(); //静态存储器管脚配置
Delay_Ms(200);
LPC_EMC->Control = 0x00000001; /*EMC enable*/
LPC_SC->EMCCLKSEL = 0x00000001; /* The EMC uses a clock at half the rate of the CPU*/
//LPC_SC->EMCCAL /*EMC 延时校验*/
LPC_EMC->Config = 0x00000000; /*little endian mode*/
Delay_Ms(200);
LPC_EMC->StaticConfig1 = 0x00000081; /* 存储器宽度16位,页读模式禁能,低电平有效片选,
端口BLS3:0配置:为读取,各自有效为低电平,为写入,各自有效位为低电平
延长等待禁能,缓冲禁能,写未受保护*/
Delay_Ms(200);
LPC_EMC->StaticWaitWen1=0x0000000F; /* 设置从片选到写使能的延时,低四位有效*/
Delay_Ms(200);
LPC_EMC->StaticWaitOen1=0x0000000C; /* 设置从片选或地址变化(两者中较晚的)到输出使能的延时,低四位有效*/
Delay_Ms(200);
LPC_EMC->StaticWaitRd1=0x00000005; /* 设置从片选到读取的延时,与EMCStaticConfig延长等待位有关系,低五位有效*/
Delay_Ms(200);
LPC_EMC->StaticWaitPage1=0x00000004; /* 设置异步页读模式的顺序存取延时,低五位有效*/
Delay_Ms(200);
LPC_EMC->StaticWaitWr1=0x00000005; /* 设置从片选到写入的延时,与EMCStaticConfig延长等待位有关系,低五位有效*/
Delay_Ms(200);
LPC_EMC->StaticWaitTurn1=0x00000004; /* 设置总线的周转周期数,控制着静态存储器读,写操作之间增加的总线周转周期数,低四位有效*/
Delay_Ms(200);
}
#define SRAM_BASE (0x90000000)
void sram_test( void )
{
INT16U *pshort_wr;
INT16U aa;
SRAM_Init();
for (Uart[UART0].Rec_Cnt=0; Uart[UART0].Rec_Cnt<BUFSIZE;Uart[UART0].Rec_Cnt++)
{
Uart[UART0].Rec_Buff[Uart[UART0].Rec_Cnt] = 0; //清空缓冲区
}
pshort_wr = (INT16U*)(SRAM_BASE);//指向(0x90000000)
*pshort_wr = 0xad47; //写入0xad47 (0x90000000)与(0x90000001)地址
Delay_Ms(500); //延时等待
pshort_wr = (INT16U*)(SRAM_BASE);
aa = *pshort_wr; //读回(0x90000000)与(0x90000001)地址 aa = 0xad47
Uart[UART0].Rec_Buff[0] = ((INT8U)(aa>>8));
Uart[UART0].Rec_Buff[1] = ((INT8U)(aa)); //写入串口缓冲区
Delay_Ms(500); //延时等待
pshort_wr = (INT16U*)(SRAM_BASE+2);//指向(0x90000002)
aa = *pshort_wr; //问题在这里,读回(0x90000002)与(0x90000003)这地址 上aa 也等于 0xad47
Uart[UART0].Rec_Buff[2] = ((INT8U)(aa>>8));
Uart[UART0].Rec_Buff[3] = ((INT8U)(aa)); //写入串口缓冲区
UARTSend(UART0, &Uart[UART0].Rec_Buff[0], BUFSIZE );//发送
}
这是串口接收到的数据,可以看出,Rec_Buff[2] ,Rec_Buff[3],的数据也等于 0xad47,(好像硬件把数据自动重复写了两次,而且地址还自动增加两个字节)
AD 47 AD 47 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|