SPI FLASH 状态寄存器一直忙碌
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);
}
先贴程序
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);
}
...全文
相关推荐
STM32-SPI-FLASH.zip
STM32-SPI-FLASH.zip
AT45DB161大容量SPI串行FLASH存储器在ARM7中的应用
介绍AT45DB161的应用,关键是控制字的操作,和时序的配置,而且这个应用是ARM方面的,值得借鉴
spi flash.zip
华大:HC32L196 驱动 spi 片外flash W25Q64源码
W25Q64_FLASH存储器芯片驱动代码(SPI硬件+SPI模拟时序).zip
这是STM32F103读写华邦W25Q64 FLASH存储器的完整驱动代码,资料包里包含了SPI硬件时序和SPI模拟时序两个工程。实现对W25Q64读写。
stm32f405驱动W25N01G demo
stm32f405驱动W25N01G demo


驱动开发/核心开发
