前言
MCU:STC8G1K08-16Pin (DIP-16)
Flash 存储芯片:W25Q16BVAIG
便宜,W25Q16 不包邮只需要 ¥1.38。
推荐一个网站:alldatasheetcn
主流 Flash 存储芯片1
名称 | 特点 | 常用案例 |
---|---|---|
IIC EEPROM | 容量小,I2C 协议 | AT24C02 (2K ~ 64K bits) FM24C02 CAT24C02 |
SPI NorFlash | 容量略大,SPI 协议 扇区或整片擦写 | S25FL128 MX25L1605 W25Q64 (8M ~ 512M bits) |
SPI NandFlash | 与 SPI NorFlash 一致 擦写寿命长,擦写速度快 | |
eMMC Flash | 标准 MMC 接口 等效于 NandFlash + 主控IC | KLMAG8DEDD THGBMAG8B4JBAIM EMMC04G-S100 |
SD卡 | 由 MMC 发展而来 支持 SD 模式和 SPI 模式 |
基本信息2
- 采用 2.7V 至 3.6V 单电源供电
- 有8192个可编程页(256Byte),共计 2MB,寻找地址:000000h ~ 1FFFFFh
- 16个页面组成1个扇区(4096Byte 扇区擦除)
- 128个页面组成1个块(32KB块擦除)
- 256个页面组成1个组(64KB块擦除)
- 芯片擦除
- 支持标准串行外设接口(SPI)
引脚定义3
PIN NO. | PIN NAME | I/O | FUNCTION |
---|---|---|---|
1 | CS | I | Chip Select Input (片选输入) |
2 | DO(IO1) | I/O | MISO |
3 | /WP(IO2) | I/O | Write Protect Input (写保护输入) |
4 | GND | Ground | |
5 | DI(IO0) | I/O | MOSI |
6 | CLK | I | Serial Clock Input (时钟输入) |
7 | /HOLD(IO3) | I/O | Hold Input (保持输入) |
8 | VCC | Power Supply |
CS:低电平选中,高电平取消。
The SPI Chip Select (/CS) pin enables and disables device operation.
DO (MISO) & DI (MOSI)
The W25Q16BV supports standard SPI, Dual SPI and Quad SPI operation.
- 标准 SPI 使用单向 DI 在 CLK 的上升沿向器件串行写入指令、地址或数据。
- 标准 SPI 使用单向 DO 在 CLK 的下降沿上读取器件的数据或状态。
/WP:写保护,低电平有效,用来保护状态寄存器。
/HOLD:低电平有效,允许芯片在被主动选择时暂停,保持输出。
- 当 /HOLD 变为低电平,而 /CS 为低电平时,DO 引脚将处于高阻态,DI 和 CLK 引脚上的信号将被忽略(无关)
- 当 /HOLD 变为高电平时,器件可以恢复工作
CLK:SPI串行时钟输入。
Block Diagram
Status Register
Register 1
S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
---|---|---|---|---|---|---|---|
SRP0 | SEC | TB | BP2 | BP1 | BP0 | WEL | BUSY |
Register 2
S15 | S14 | S13 | S12 | S11 | S10 | S9 | S8 |
---|---|---|---|---|---|---|---|
SUS | (R) | (R) | (R) | (R) | (R) | QE | SRP1 |
Details
BUSY:忙位(只读),0 表示空闲,1 表示正忙。
WEL:写保护位(只读),执行 Write Enable(06h)指令后 WEL 置 1,写禁用时的 WEL 为 0。
BP2, BP1, BP0:块保护位,默认设置均为 0,不包含任何块。
TB:顶部/底部保护位(非易失读写),控制 BP2/1/0 的保护对象是从顶部(TB=0)还是底部(TB=1)开始,出厂默认设置为 TB=0。
SEC:扇区保护位(非易失读写),控制 TB 和 BP2/1/0 的保护对象是 4KB 扇区(SEC=1)还是 64KB 块(SEC=0),出厂默认设置为 SEC=0。
SRP1, SRP0:状态寄存器保护位(非易失读写),控制写保护方法:
SRP1 | SRPT0 | /WP | Status Register | Description |
---|---|---|---|---|
0 | 0 | X | Software Protection | /WP 引脚无控制。 写使能指令 WEL=1 后,可以写入状态寄存器。(出厂默认设置) |
0 | 1 | 0 | Hardware Protected | 当 /WP 引脚为低电平时,状态寄存器锁定,无法写入。 |
0 | 1 | 1 | Hardware Unprotected | 当 /WP 引脚为高电平时,状态寄存器解锁,可以在写入使能指令后写入,WEL=1。 |
1 | 0 | X | Power Supply Lock-Down(1) | 状态寄存器受到保护,在下一个掉电、上电周期之前不能再次写入。(2) |
1 | 1 | X | One Time Program(1) | 状态寄存器被永久保护,不能写入。 |
Notes:
- These features are available upon special order. Please refer to Ordering Information.
- When SRP1, SRP0 = (1, 0), a power-down, power-up cycle will change SRP1, SRP0 to (0, 0) state.
SUS:挂起状态位(只读),执行 Erase Suspend(75h)后 SUS=0。
QE:四通道使能位(非易失读写),QE=0(出厂默认设置)使能 /WP 和 /HOLD,QE=1 使能 IO2 和 IO3。
Instruction Set Table
Instruction Set Table 1
(Erase, Program Instructions) (1)
INSTRUCTION NAME | BYTE1 (CODE) | BYTE2 | BYTE3 | BYTE4 | BYTE5 | BYTE6 |
---|---|---|---|---|---|---|
Write Enable | 06h | |||||
Write Disable | 04h | |||||
Read Status Register-1 | 05h | (S7-S0)(2) | ||||
Read Status Register-2 | 35h | (S15-S8)(2) | ||||
Write Status Register | 01h | S7-S0 | S15-S8 | |||
Page Program | 02h | A23-A16 | A15-A8 | A7-A0 | (D7-D0) | |
Quad Page Program | 32h | A23-A16 | A15-A8 | A7-A0 | (D7-D0)(3) | |
Sector Erase (4KB) | 20h | A23-A16 | A15-A8 | A7-A0 | ||
Block Erase (32KB) | 52h | A23-A16 | A15-A8 | A7-A0 | ||
Block Erase (64KB) | D8h | A23-A16 | A15-A8 | A7-A0 | ||
Chip Erase | C7h/60h | |||||
Erase Suspend | 75h | |||||
Erase Resume | 7Ah | |||||
Power-down | B9h | |||||
Continuous Read Mode Reset(4) | FFh | FFh |
Notes:
- Data bytes are shifted with Most Significant Bit first. Byte fields with data in parenthesis “()” indicate data being read from the device on the DO pin.
- The Status Register contents will repeat continuously until /CS terminates the instruction.
- Quad Page Program Input Data:
- IO0 = (D4, D0, ……)
- IO1 = (D5, D1, ……)
- IO2 = (D6, D2, ……)
- IO3 = (D7, D3, ……)
- This instruction is recommended when using the Dual or Quad “Continuous Read Mode” feature. See section 11.2.32 for more information.
Instruction Set Table 2
Read Instructions
INSTRUCTION NAME | BYTE1 (CODE) | BYTE2 | BYTE3 | BYTE4 | BYTE5 | BYTE6 |
---|---|---|---|---|---|---|
Read Data | 03h | A23-A16 | A15-A8 | A7-A0 | (D7-D0) | |
Fast Read | 0Bh | A23-A16 | A15-A8 | A7-A0 | dummy | (D7-D0) |
Fast Read Dual Output | 3Bh | A23-A16 | A15-A8 | A7-A0 | dummy | (D7-D0, …)(1) |
Fast Read Dual I/O | BBh | A23-A8 (2) | A7-A0, M7-M0 (2) | (D7-D0, …)(1) | ||
Fast Read Quad Output | 6Bh | A23-A16 | A15-A8 | A7-A0 | dummy | (D7-D0, …)(3) |
Fast Read Quad I/O | EBh | A23-A0, M7-M0 (4) | (x,x,x,x, D7-D0, …)(5) | (D7-D0, …)(3) | ||
Word Read Quad I/O(7) | E7h | A23-A0, M7-M0 (4) | (x,x, D7-D0, …)(6) | (D7-D0, …)(3) | ||
Octal Word Read Quad I/O(8) | E3h | A23-A0, M7-M0 (4) | (D7-D0, …)(3) |
Notes:
- Dual Output data
- IO0 = (D6, D4, D2, D0)
- IO1 = (D7, D5, D3, D1)
- Dual Input Address
- IO0 = A22, A20, A18, A16, A14, A12, A10, A8 A6, A4, A2, A0, M6, M4, M2, M0
- IO1 = A23, A21, A19, A17, A15, A13, A11, A9 A7, A5, A3, A1, M7, M5, M3, M1
- Quad Output Data
- IO0 = (D4, D0, …..)
- IO1 = (D5, D1, …..)
- IO2 = (D6, D2, …..)
- IO3 = (D7, D3, …..)
- Quad Input Address
- IO0 = A20, A16, A12, A8, A4, A0, M4, M0
- IO1 = A21, A17, A13, A9, A5, A1, M5, M1
- IO2 = A22, A18, A14, A10, A6, A2, M6, M2
- IO3 = A23, A19, A15, A11, A7, A3, M7, M3
- Fast Read Quad I/O Data
- IO0 = (x, x, x, x, D4, D0, …..)
- IO1 = (x, x, x, x, D5, D1, …..)
- IO2 = (x, x, x, x, D6, D2, …..)
- IO3 = (x, x, x, x, D7, D3, …..)
- Word Read Quad I/O Data
- IO0 = (x, x, D4, D0, …..)
- IO1 = (x, x, D5, D1, …..)
- IO2 = (x, x, D6, D2, …..)
- IO3 = (x, x, D7, D3, …..)
- The lowest address bit must be 0. ( A0 = 0 )
- The lowest 4 address bits must be 0. ( A0, A1, A2, A3 = 0 )
Instruction Set Table 3
ID, Security Instructions
INSTRUCTION NAME | BYTE1 (CODE) | BYTE2 | BYTE3 | BYTE4 | BYTE5 | BYTE6 |
---|---|---|---|---|---|---|
Release Power down/Device ID | ABh | dummy | dummy | dummy | (ID7-ID0)(1) | |
Manufacturer/Device ID(2) | 90h | dummy | dummy | 00h | (MF7-MF0) | (ID7-ID0) |
Manufacturer/Device ID by Dual I/O | 92h | A23-A8 | A7-A0, M[7:0] | (MF[7:0], ID[7:0]) | ||
Manufacture/Device ID by Quad I/O | 94h | A23-A0, M[7:0] | xxxx, (MF[7:0], ID[7:0]) | (MF[7:0], ID[7:0], …) | ||
JEDEC ID | 9Fh | (MF7-MF0) Manufacturer | (ID15-ID8) Memory Type | (ID7-ID0) Capacity | ||
Read Unique ID | 4Bh | dummy | dummy | dummy | dummy | (ID63-ID0) |
Notes:
- The Device ID will repeat continuously until /CS terminates the instruction.
- See Manufacturer and Device Identification table for Device ID information.
案例
FLASH 状态确认/设备测试
在初始化阶段判断 FLASH 状态的常用方法有两种,分别是 JEDEC ID 和 S0-BUSY。
JEDEC ID
W25Q16 的 JEDEC ID 由3个字节组成,分别是:
- Manufacturer ID (0xEF)
- Memory Type
- Capacity
以我 W25Q16JVSSIQ 为例,发送 0x9F 后,读取3个字节(0xEF : 0x40 : 0x15)。
unsigned char SPI_FLASH_CheckStatus(void){ unsigned char b1, b2, b3; unsigned char i = 0; while (i++ < 200) { SPI_FLASH_CS=0; SPI_WriteByte(W25X_ReadJEDECID); b1 = SPI_ReadByte(); b2 = SPI_ReadByte(); b3 = SPI_ReadByte(); SPI_FLASH_CS=1; if (b1 == 0xEF & b2 == 0x40 & b3 == 0x15) return 1; delayms(1); } return 0;}
S0-BUSY
unsigned char SPI_FLASH_CheckStatus(void){ unsigned char b1; unsigned char i = 0; while(i++ < 200) { SPI_FLASH_CS=0; SPI_WriteByte(W25X_ReadStatus1); b1 = SPI_ReadByte(); SPI_FLASH_CS=1; if (!(b1 & 0x01)) return 1; delayms(1); } return 0;}