这里是部分源程序
上面是读取数据,下面是写入数据
Continuous_Array_Read(adr_page_record,8,spi_buf,504);//读取504字节数据函数
TestStatus Continuous_Array_Read(unsigned int PageAddr, unsigned int ByteAddr,
unsigned char *DataBuffer,unsigned long ByteNum)
{
unsigned long i;
if(ByteNum<=2162688)//СÓÚ 4096*528 Bytes
{
while(!(StatusRegisterRead()&0x80));
SPI_CS_LOW();
SPI_WriteByte(Continuous_Array_Read_Cmd);
SPI_WriteByte((unsigned char)(PageAddr>>6));
SPI_WriteByte((unsigned char)((PageAddr<<2)|(ByteAddr>>8)));
SPI_WriteByte((unsigned char)ByteAddr);
SPI_WriteByte(0x00); //
for(i=0;i<ByteNum;i++)
{
DataBuffer[i] = SPI_ReadByte();
}
SPI_CS_HIGH();
return PASSED;
}
return FAILED;
}
TestStatus DataToPage_ViaBuffer_WithErase_SecWay(unsigned char BufferNumber,unsigned int PageAddr,unsigned int ByteAddr,
unsigned char *Data, unsigned int ByteNum)
{
unsigned int i;
if((ByteNum<=(528-ByteAddr))&&(ByteNum>0))
{
while(!(StatusRegisterRead()&0x80));
SPI_CS_LOW();
switch(BufferNumber)
{
case 1: SPI_WriteByte(0x82);break;//
case 2: SPI_WriteByte(0x85);break;//
}
SPI_WriteByte((unsigned char)( PageAddr>>6));
SPI_WriteByte((unsigned char)((PageAddr<<2)|(ByteAddr>>8)));
SPI_WriteByte((unsigned char) ByteAddr);
for(i=0;i<ByteNum;i++)
{
SPI_WriteByte(Data[i]);
}
SPI_CS_HIGH();
return PASSED;
}
return FAILED;
}
|