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);
}
------解决方案--------------------
W25X** C语句
华邦的串口16M/8位FLASH