SPI FLASH 状态寄存器一直忙碌

star143133 star143133 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
LPC2132外接W25X16 无论怎么样读写擦除还是向状态寄存器里写数据。都是忙碌状态。
先贴程序

void SPI_init() //初始化
{
PINSEL0 = (PINSEL0&(~(0xff<<8))|0x55<<8);
S0SPCCR = 0x52;
S0SPCR = (0<<3)|(1<<4)|(1<<5)|(0<<6)|(0<<7);

}
void Send_Byte(uint8 out) //发送单字节
{
S0SPDR = out;
while(!(S0SPSR & 0x80))
;
}

uint8 Get_Byte()//接收单字节

{
Send_Byte(0xff);
while(!(S0SPSR & 0x80))
;
return(S0SPDR);
}

void CS_High() //取消片选
{
IOSET0 |= 0x01<<29;
}

void CS_Low() //选中片选
{
IOCLR0 |= 0x01<<29;
}

unsigned char Read_Status_Register() //读状态寄存器
{
uint8 byte = 0;
// char s[5] = {0};
CS_Low(); /* enable device */
Send_Byte(0x05); /* send RDSR command */
byte = Get_Byte(); /* receive byte */
CS_High(); /* disable device */
return byte;
}

void Write_Status_Register(uint8 sr) //写状态寄存器
{
CS_Low();
Send_Byte(0x01);
Send_Byte(sr);
CS_High();
}

void Wait_Busy() //判忙
{
while ((Read_Status_Register()& 0x01) == 0x01) /* wait until not busy */
;
//UARTSend("free\r\n",6);
}
...全文
评论 7
收藏 已收藏
分享
返回顶部