onbluesun 发表于 2012-7-30 18:20:02

W25X40的操作程序是不是这样?

W25X40的写使能的程序如下,单片机使用STC12C5A60S2,有SPI接口:#include "reg51.h"
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;

sfr P1M1 = 0x91;
sfr P1M0 = 0x92;

sfr AUXR = 0x8e; //Auxiliary register
sfr SPSTAT = 0xcd; //SPI status register
#define SPIF 0x80 //SPSTAT.7
#define WCOL 0x40 //SPSTAT.6
sfr SPCTL = 0xce; //SPI control register
#define SSIG 0x80 //SPCTL.7
#define SPEN 0x40 //SPCTL.6
#define DORD 0x20 //SPCTL.5
#define MSTR 0x10 //SPCTL.4
#define CPOL 0x08 //SPCTL.3
#define CPHA 0x04 //SPCTL.2
#define SPDHH 0x00 //CPU_CLK/4
#define SPDH 0x01 //CPU_CLK/16
#define SPDL 0x02 //CPU_CLK/64
#define SPDLL 0x03 //CPU_CLK/128
sfr SPDAT = 0xcf; //SPI data register
sfr IE2 = 0xAF; //interrupt enable rgister 2
#define ESPI 0x02 //IE2.1
void InitSPI();

sbit cs = P1^0;
//sbit wp = P1^1;
//sbit hold = P1^2;

void main()
{
P1M1=0xff;
P1M0=0xff;

InitSPI(); //initial SPI
IE2 |= ESPI;

EA = 1;

cs=0;
SPDAT=0x06;

while (1);
}

void spi_isr( ) interrupt 9 using 1 //SPI interrupt routine 9 (004BH)
{
SPSTAT = SPIF | WCOL; //clear SPI status
cs=1;
}
///////////////////////////////////////////////////////////
void InitSPI()
{
SPDAT = 0; //initial SPI data
SPSTAT = SPIF | WCOL; //clear SPI status
SPCTL = SPEN | MSTR; //master mode
}上面的程序对吗?单片机向W25X40发送0x06后,得到一个返回值0x00,之后我又读状态寄存器,发现返回值也是0x00,感觉程序肯定不对。下面是写使能的时序图:
页: [1]
查看完整版本: W25X40的操作程序是不是这样?