#define EXT_SEG00 0x008000
//#define EXT_SEG00 (*((INT8U *)0x008000))
#define FLASH_DATA(n) n
#define FLASH_ADDR(a) ((INT8U *)(EXT_SEG00 + a))
#define FLASH_WRITE(addr, word) (*FLASH_ADDR(addr) = FLASH_DATA(word))
void main(void) {
// INT8U i;
//没有赋初值
// DISABLE_INTERRUPTS;
DisableInterrupts;
CRG_init(); //系统时钟初始化40M
SCIInit(9600); //串口初始化,波特率为9600
//设置数据口,D口 ,C 口 PD0-PD7<->DATA0-DATA7,PC0-PC7<->DATA8-DATA15
//本系统使用的是窄模式,只用到低八位。
PORTD=0xFF; //PORTD=0xFF;
DDRD =0xFF; //Set PotrD as output
PORTC=0xFF; //PORTC=0xFF;
DDRC=0xFF; //Set PortC as output
//设置地址口, A口和K口,PB0-PB7<->ADDR0-ADDR7,
//PA0-PA7<-> ADDR8-ADDR15,PK0-PK6<->ADDR16-ADDR22
PORTA=0xFF; //PORTA=0xFF;
DDRA=0xFF; //Set PortA as output
PORTB=0xFF; //PORTA=0xFF;
DDRB=0xFF; //Set PortA as output
PORTK=0xFF; //PORTK=0xFF;
DDRK=0xFF; //Set PortK as output
//Enable EBI
//setting EBI
//1.Set the intput threshold
EBICTL0=0x06; //0b00010110
// ||||||
//扩展模式设置 // || | -
// ||-------10110:ASIZ[4:0]:ADDR[21-1]
// |---------0,DATA[15:8] UDS and LDS disabled ,只用到低8位
//2.Enable appropriate chip select signal (CS3E:CS0E)through the MMCCTRLO register
//MMC control register
MMCCTL0 = 0x08; //Enable CS3 chip select 0x00_0800-0x0F_FFFF
//3.Select the desired number of stretch cycles (6 read m,2Write) and disable
//the external wait feature through the EBICTRL1 register
//4.Set MCU into normal expanded mode through the MODE Register
MODE=0xA0;//Normal expanded mode,MODC = 1, MODB = 0, MODA = 1 (Normal Expanded Mode)
// EBICTL1=0x18; //>=8 cycles
//对FLASH操作时,MODA口和CS口打低电平信号MODA:PE5.CS3:PJ0
//定义PE5为输出 0
delayms(400);
// PORTE = PORTE&0xFB; //11111011 PE5=0 OE使能有效
DDRE = DDRE|0x20; //00100000
PORTE = PORTE&0xDF; //11011111
//
//PE2=0, WE使能有效
DDRE = DDRE|0x04; //00000100
PORTE = PORTE&0xFB; //11111011
//
//定义PJ0为输出 0
DDRJ = DDRJ|0x01; //00000001
PTJ = PTJ&0xFE; //11111110
// EXT_SEG00=0xAA; //写入数据
delayms(100); //等待数据稳定
// PORTE = PORTE|0x04; //00000100 PE2=1 WE使能无效
// SCISend1(temp); // 读出数据为0xFF;'
// SCISend1(EXT_SEG00);
//reset
FLASH_WRITE(0x555,0xAA);
FLASH_WRITE(0x2AA,0x55);
FLASH_WRITE(0x555,0xF0);
//chip erase 555 AA 2AA 55 555 80 555 AA 2AA 55 555 10
FLASH_WRITE(0x555,0xAA);
FLASH_WRITE(0x2AA,0x55);
FLASH_WRITE(0x555,0x80);
FLASH_WRITE(0x555,0xAA);
FLASH_WRITE(0x2AA,0x55);
FLASH_WRITE(0x555,0x10);
//延时40S
delayms(40000);
//programe 555 AA 2AA 55 555 A0 PA PD
FLASH_WRITE(0x555,0xAA);
FLASH_WRITE(0x2AA,0x55);
FLASH_WRITE(0x555,0xA0);
FLASH_WRITE(0x555,0xAA);
delayus(200);
// FLASH_WRITE(0x555,0xAA);
// FLASH_WRITE(0x2AA,0x55);
// FLASH_WRITE(0x555,0xF0);
// delayms(100);
SCISend1((INT8U)(*FLASH_ADDR(0x555))); // 读出数据为0xFF;
读出来的数据总是0XFF。为什么数据没有写进去呢?
项目研发等着用,急啊。。。请大家帮帮忙。。。
来个人帮忙解答一下啊?
[em04]我从FLASH的固定地址读数据,读出来的数据是0XFF。是不是代表我的EBI和FLASH通讯没有成功啊?重新贴代码:
如下:
DisableInterrupts;
CRG_init(); //系统时钟初始化40M
SCIInit(9600); //串口初始化,波特率为9600
//setting EBI
//1.Set the intput threshold
EBICTL0=0x17; //0b00010111
// ||||||
//扩展模式设置 // || | -
// ||-------10110:ASIZ[4:0]:ADDR[22-1]
// |---------0,DATA[15:8] UDS and LDS disabled ,只用到低8位
//2.Enable appropriate chip select signal (CS3E:CS0E)through the MMCCTRLO register
//MMC control register
MMCCTL0 = 0x08; //Enable CS3 chip select 0x00_0800-0x0F_FFFF
MMCCTL1 = 0x07; // Enable Flash or ROM in the memory map.
//3.Select the desired number of stretch cycles (6 read m,2Write) and disable
EBICTL1 = 0x00; // Stretch=1 cycle
//4.Set MCU into normal expanded mode through the MODE Register
MODE=0xA0;//Normal expanded mode,MODC = 1, MODB = 0, MODA = 1 (Normal Expanded Mode)
//对FLASH操作时
//定义PE5为输出 0
delayms(400);
SCISend1((INT8U)(*((INT8U *)0x0010)));
SCISend1((INT8U)(*((INT8U *)0x0810))); // 读出数据为0xFF;
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |