我看了AT系列的datasheet这个的编程方式跟我用的那个flash编程方式相同,我的测试代码如下:麻烦您看看
#include "config.h"
#include "LPC2294.h"
#define CHIP_SEL 0x00000100 /* P0.8 Chip Enable or Disable */
#define CMD_NUM 4
#define CE_Low() (IOCLR=CHIP_SEL)
#define CE_High() (IOSET=CHIP_SEL)
#define SST25VF010A_SCK (1<<4)
#define SST25VF010A_MISO (1<<5)
#define SST25VF010A_MOSI (1<<6)
#define SET_SST25VF010A_SCK() (IO0SET = SST25VF010A_SCK)
#define CLR_SST25VF010A_SCK() (IO0CLR = SST25VF010A_SCK)
#define SET_SST25VF010A_SO() (IO0SET = SST25VF010A_MISO)
#define CLR_SST25VF010A_SO() (IO0CLR = SST25VF010A_MISO)
#define SET_SST25VF010A_SI() (IO0SET = SST25VF010A_MOSI)
#define CLR_SST25VF010A_SI() (IO0CLR = SST25VF010A_MOSI)
/************************************************************************/
/* PROCEDURE: Send_Byte */
/* */
/* This procedure outputs a byte shifting out 1-bit per clock rising */
/* edge on the the SI pin(LSB 1st). */
/* */
/* Input: */
/* out */
/* */
/* Output: */
/* SI */
/************************************************************************/
void Send_Byte(uint8 out)
{
unsigned char i = 0;
for (i = 0; i < 8; i++)
{
if ((out & 0x80) == 0x80) /* check if MSB is high */
//SI = 1;
SET_SST25VF010A_SI();
else
//SI = 0; /* if not, set to low */
CLR_SST25VF010A_SI();
SET_SST25VF010A_SCK(); //SCK = 1; toggle clock high
out = (out << 1); /* shift 1 place for next bit */
CLR_SST25VF010A_SCK(); //SCK = 0; /* toggle clock low */
}
}
/************************************************************************/
/* PROCEDURE: Get_Byte */
/* */
/* This procedure inputs a byte shifting in 1-bit per clock falling */
/* edge on the SO pin(LSB 1st). */
/* */
/* Input: */
/* SO */
/* */
/* Output: */
/* None */
/************************************************************************/
uint8 Get_Byte()
{
unsigned char i = 0, in = 0, temp = 0;
for (i = 0; i < 8; i++)
{
in = (in << 1); /* shift 1 place to the left or shift in 0 */
temp =(( IO0PIN & SST25VF010A_MISO ) >> 5); /* save input */
SET_SST25VF010A_SCK(); //SCK = 1; /* toggle clock high */
if (temp == 1) /* check to see if bit is high */
in = in | 0x01; /* if high, make bit high */
CLR_SST25VF010A_SCK(); //SCK = 0; /* toggle clock low */
}
return in;
}
unsigned char Read_Status_Register()
{
unsigned char byte = 0;
CE_Low(); /* enable device */
Send_Byte(0x05); /* send RDSR command */
byte = Get_Byte(); /* receive byte */
CE_High(); /* disable device */
return byte;
}
unsigned char Read_ID(ID_addr)
{
unsigned char byte;
CE_Low(); /* enable device */
Send_Byte(0x90); /* send read ID command (90h or ABh) */
Send_Byte(0x00); /* send address */
Send_Byte(0x00); /* send address */
Send_Byte(ID_addr); /* send address - either 00H or 01H */
byte = Get_Byte(); /* receive byte */
CE_High(); /* disable device */
return byte;
}
/************************************************************************/
/* PROCEDURE: WREN */
/* */
/* This procedure enables the Write Enable Latch. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void WREN()
{
CE_Low(); /* enable device */
Send_Byte(0x06); /* send WREN command */
CE_High(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: WRDI */
/* */
/* This procedure disables the Write Enable Latch. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void WRDI()
{
CE_Low(); /* enable device */
Send_Byte(0x04); /* send WRDI command */
CE_High(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: Byte_Program */
/* */
/* This procedure programs one address of the device. */
/* Assumption: Address being programmed is already erased and is NOT */
/* block protected. */
/* */
/* */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* byte: byte to be programmed */
/* */
/* */
/* Returns: */
/* Nothing */
/* */
/************************************************************************/
void Byte_Program(unsigned long Dst, unsigned char byte)
{
CE_Low(); /* enable device */
Send_Byte(0x02); /* send Byte Program command */
Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
Send_Byte(((Dst & 0xFFFF) >> 8));
Send_Byte(Dst & 0xFF);
Send_Byte(byte); /* send byte to be programmed */
CE_High(); /* disable device */
}
/************************************************************************/
/* PROCEDURE: Read */
/* */
/* This procedure reads one address of the device. It will return the */
/* byte read in variable byte. */
/* */
/* */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* */
/* */
/* Returns: */
/* byte */
/* */
/************************************************************************/
unsigned char Read(unsigned long Dst)
{
unsigned char byte = 0;
CE_Low(); /* enable device */
Send_Byte(0x03); /* read command */
Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
Send_Byte(((Dst & 0xFFFF) >> 8));
Send_Byte(Dst & 0xFF);
byte = Get_Byte();
CE_High(); /* disable device */
return byte; /* return one byte read */
}
void Delay(unsigned short iTime)
{
unsigned int i,j;
for(i=0;i
{
for (j=0;j<1;j++);
}
}
void Alarm(void)
{
SET_SST25VF010A_SCK();
Delay(2);
CLR_SST25VF010A_SCK();
__asm{ NOP }
}
void DelayNS(uint32 dly)
{ uint32 i;
for (;dly>0;dly--)
for(i=0;i<5000;i++);
}
void MSpiIni(void)
{ SPI_SPCCR=0x4C; //设置SPI时钟分频
SPI_SPCR=0x30; //设置SPI接口模式,MSTR=1,CPOL=1,CPHA=0,LSBF=0
}
uint8 MSendData(uint8 data)
{
CE_Low(); //片选
SPI_SPDR=data;
while(0==(SPI_SPSR&0x80)); //等待SPIF置位,即等待数据发送完毕
CE_High();
return(SPI_SPDR);
}
//Read 0x03
//Byte-Write 0x02
//WREN 0x06
//WRDI 0x04
//Read_Staus_Register 0x05
//Write_Staus_Register 0x01
uint8 const Cmd[CMD_NUM]={0x03, 0x00, 0x00, 0x04/*, 0x05, 0x01*/};
int main(void)
{ uint8 rcv_data;
uint8 i;
PINSEL0 = (PINSEL0 & 0xFFFF00FF);
IODIR = CHIP_SEL | SST25VF010A_SCK | SST25VF010A_MOSI ;
//MSpiIni(); //初始化SPI接口
while(1)
{
//rcv_data =Read_Status_Register();
WREN();
Byte_Program(0x000005, 0xA5);
WRDI();
DelayNS(1);
rcv_data = Read(0x000005);
DelayNS(1);
}
return(0);
}
我用了以上测试,代码含义:先往地址0x000005写一个数据,然后将这个数读出来,可是发现SO因脚始终没有信号.