型号是SST25VF032B
读取ID,操作寄存器之类的都正常,所以应该不是SPI的问题。就是读取数据的时候总是返回状态寄存器里面的值,目前能想到的操作和情况都做了,但是只要READ就返回当前状态寄存器的值。不知道有没有大神指点一下是哪方面的错误,给个思路也行。
代码比较简单,就不都贴出来了,应该也没什么问题。
SPI_FLASH_ERROR_TYPE flash_erase_all(void)
{
// flash_write_enable();
FLASH_SPI_CS_ON();
if(SPI_FLASH_BUSY())
{
FLASH_SPI_CS_OFF();
return SPI_FLASH_ERROR_BUSY;
}
SPI_Flash_Write(FLASH_CMD_WRITE_ENABLE);
SPI_Flash_Write(FLASH_CMD_ALL_ERASE);
while(SPI_FLASH_BUSY());
SPI_Flash_Write(FLASH_CMD_WRITE_DISABLE);
FLASH_SPI_CS_OFF();
// flash_write_disable();
return SPI_FLASH_SUCCESS;
}
SPI_FLASH_ERROR_TYPE flash_write_byte(uint8_t data, uint32_t address)
{
flash_write_enable();
FLASH_SPI_CS_ON();
if(SPI_FLASH_BUSY())
{
FLASH_SPI_CS_OFF();
return SPI_FLASH_ERROR_BUSY;
}
SPI_Flash_Write(FLASH_CMD_WRITE_BYTE);
SPI_Flash_Write(SPI_FLASH_ADDRESS(2));
SPI_Flash_Write(SPI_FLASH_ADDRESS(1));
SPI_Flash_Write(SPI_FLASH_ADDRESS(0));
SPI_Flash_Write(data);
while(SPI_FLASH_BUSY());
FLASH_SPI_CS_OFF();
flash_write_disable();
return SPI_FLASH_SUCCESS;
}
SPI_FLASH_ERROR_TYPE flash_read(uint8_t *buf, uint32_t len, uint32_t address)
{
if(len < 1)
return SPI_FLASH_ERROR_PARAM;
FLASH_SPI_CS_ON();
if(SPI_FLASH_BUSY())
{
FLASH_SPI_CS_OFF();
return SPI_FLASH_ERROR_BUSY;
}
SPI_Flash_Write(FLASH_CMD_READ);
SPI_Flash_Write(SPI_FLASH_ADDRESS(2));
SPI_Flash_Write(SPI_FLASH_ADDRESS(1));
SPI_Flash_Write(SPI_FLASH_ADDRESS(0));
for(uint32_t i = 0; i < len; i ++)
{
while(SPI_FLASH_BUSY());
buf[i] = SPI_Flash_Read();
}
FLASH_SPI_CS_OFF();
return SPI_FLASH_SUCCESS;
}
int main(void)
{
uint8_t MF, ID;
char temp[10];
memset(temp, 0, sizeof(temp));
hal_init();
SPI2_cfg();
SPI2_enalbe(true);
SPI_FLASH_INIT();
//各种情况都做一遍,可惜就是不行,只有寄存器和ID这些可以正常使用。奇怪的是各种擦写操作,状态寄存器的BUSY位从来不会为1
flash_erase_all();
flash_erase(flash_erase_size_4k, 0x000000);
//ID = flash_read_status_register();
flash_write_enable();
flash_fast_read((uint8_t *)&temp, sizeof(temp), 0x000000);
flash_enable_block(true, true, true);
flash_erase(flash_erase_size_4k, 0x001000);
ID = flash_read_status_register();
flash_write_byte('A', 0x000000);
flash_fast_read((uint8_t *)&temp, sizeof(temp), 0x000000);
flash_fast_read((uint8_t *)&temp, sizeof(temp), 0x001000);
ID = flash_read_status_register();
flash_read_id(&MF, &ID);
------解决思路----------------------
几个月前刚好搞过SST25VF032B,有空帮你看看
------解决思路----------------------
应该是你时序没有搞对。
读的话,如果是高速模式,发完三个字节的地址后需要发送一个空字节,然后才能读取数据。高速命令是0b,普通是03.
写的时候,写使能后,需要拉高使能端,再拉低使能端,写入命令地址和数据。单字节命令是02,双字节是AD。