本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
在C8051F340 MCU 下SPI读写 MA25L1605 操作
请教哪里错问题了 读写都不行 各位老兄帮下忙
//往SPI口写一个字节的数据
void SPI_WriteByte(uchar Data)
{
SPI0DAT = Data;
while(!SPIF);
SPIF = FALSE;
}
//从SPI口读一个字节的数据
uchar SPI_ReadByte()
{
SPI0DAT = 0x00;
while (!SPIF);
SPIF = FALSE;
return (SPI0DAT);
}
// 按地址写数据
void Wtire_Page(ulong ADDR ,uchar WDATA)
NSSMD0 = FALSE;
SPI_WriteByte(0x06); //写使能
Delay(1);
SPI_WriteByte(0x01); //写操作命令
SPI_WriteByte( (ADDR & 0x00FF0000) >> 16);
SPI_WriteByte( (ADDR & 0x0000FF00) >> 8);
SPI_WriteByte( (ADDR & 0x000000FF));
SPI_WriteByte(WDATA);
NSSMD0 =TRUE;
}
//按地址读数据
uchar Read_Page(ulong ADDR)
{
uchar RDATA=0;
NSSMD0 = FALSE;
SPI_WriteByte(0x03);
SPI_WriteByte( (ADDR & 0x00FF0000) >> 16); // send out the address, high byte, middle byte, then low byte
SPI_WriteByte( (ADDR & 0x0000FF00) >> 8);
SPI_WriteByte( (ADDR & 0x000000FF));
RDATA=SPI_ReadByte();
return RDATA;
NSSMD0 =TRUE;
}
//读取ID
void Read_ID()
{
uchar rnum1=0,rnum2=0,rnum3=0;
NSSMD0 = FALSE; ///选中FLASH
SPI_WriteByte(0X9f); //读ID 命令
rnum1= SPI_ReadByte();
rnum2= SPI_ReadByte();
rnum3= SPI_ReadByte();
if(rnum1==0xc2) //是否是ID号
{
P3=0Xff; //硬件指示是否成功。
P2=0Xff;
}
NSSMD0 = TRUE;
} |