赞
踩
W25Q32JV是华邦推出的一款spi flash,32J表示32M-bit,相当于4M
关于型号命名如下

对于W25Q32JV:
page为最大编程单位,1page = 256bytes
sector为最小擦除单位,1sector = 16pages = 4KB = 4096bytes
还支持半块擦除(32KB block erase)、块擦除(64KB block erase)和整片擦除(chip erase)
W25Q32JV提供了三个状态和配置寄存器。

void FLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { /*Set /CS bit low*/ GPIO_ResetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN); /*Send write enable*/ FLASH_SendByte(0x06); /*Set /CS bit high */ GPIO_SetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN); /*Select the FLASH: Chip Select low */ GPIO_ResetBits(FLASH_CS_GPIO_PORT, sFLASH_CS_PIN) /*Send page program*/ FLASH_SendByte(0x02); /*Send WriteAddr high nibble address byte to write to */ FLASH_SendByte((WriteAddr & 0xFF0000) >> 16); /*Send WriteAddr medium nibble address byte to write to */ FLASH_SendByte((WriteAddr & 0xFF00) >> 8); /*Send WriteAddr low nibble address byte to write to */ FLASH_SendByte(WriteAddr & 0xFF); /*while there is data to be written on the FLASH */ while (NumByteToWrite--) { /*Send the current byte */ FLASH_SendByte(*pBuffer); /*Point on the next byte to be written */ pBuffer++; } /*Deselect the FLASH: Chip Select high */ GPIO_SetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN); /*Wait the end of Flash writing */ FLASH_WaitForWriteEnd(); }
void FLASH_ReadPage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { /*Set /CS bit low*/ GPIO_ResetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN) /*!Send read data */ FLASH_SendByte(0x03); /*Send ReadAddr high nibble address byte to read from */ FLASH_SendByte((ReadAddr & 0xFF0000) >> 16); /*Send ReadAddr medium nibble address byte to read from */ FLASH_SendByte((ReadAddr& 0xFF00) >> 8); /*Send ReadAddr low nibble address byte to read from */ FLASH_SendByte(ReadAddr & 0xFF); /*! Read data */ while (NumByteToRead--) { /*Read a byte from the FLASH */ *pBuffer = sFLASH_SendByte(sFLASH_DUMMY_BYTE); /*Point to the next location where the byte read will be saved */ pBuffer++; } /*Set /CS bit high */ GPIO_SetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN) }
void FLASH_EraseSector(uint32_t SectorAddr) { /*Set /CS bit low*/ GPIO_ResetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN); /*Send write enable*/ FLASH_SendByte(0x06); /*Set /CS bit high */ GPIO_SetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN); /*Select the FLASH: Chip Select low */ GPIO_ResetBits(FLASH_CS_GPIO_PORT, sFLASH_CS_PIN) /*Send Sector Erase instruction */ FLASH_SendByte(0x20); /*Send SectorAddr high nibble address byte */ FLASH_SendByte((SectorAddr & 0xFF0000) >> 16); /*Send SectorAddr medium nibble address byte */ FLASH_SendByte((SectorAddr & 0xFF00) >> 8); /*Send SectorAddr low nibble address byte */ FLASH_SendByte(SectorAddr & 0xFF); /*Deselect the FLASH: Chip Select high */ GPIO_SetBits(FLASH_CS_GPIO_PORT, FLASH_CS_PIN); /*Wait the end of Flash writing */ FLASH_WaitForWriteEnd(); }
注:
Flash在写数据之前,先进行Erase操作,其实Erase操作就是往Flash中写FF,最小Erase单位为Sector,也支持32KB Block Erase(52h),64KB Block Erase(D8h)和Chip Erase(C7h/60h)。
如有不足,还望大家指正,互相学习,谢谢!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。