| 12345678910111213141516171819202122232425262728 |
- #ifndef __INT_EEPROM_H
- #define __INT_EEPROM_H
- #include "main.h"
- /* BL24C16F:16Kbit = 2048 字节 */
- #define INT_EEPROM_SIZE 2048 /* 容量(字节) */
- #define INT_EEPROM_PAGE_SIZE 16 /* 页大小(字节) */
- #define INT_EEPROM_PAGES 128 /* 页数 */
- /* I2C 设备基地址(7 位,A0/A1/A2 接地)
- * 注意 BL24C16F 是 8 x 256B 块结构:高 3 位地址放在器件地址里,
- * 实际器件地址 = 0x50 | ((addr >> 8) & 0x07),块内地址 = addr & 0xFF。
- * 固定用 0x50 + 16bit 地址只能访问到 0x0000~0x00FF,会踩 App 参数区别名,
- * 读 0x0100/0x0140 Boot 记录必然失败(表现为 err=0x51 EEPROM_FAIL)。 */
- #define INT_EEPROM_ADDR 0x50
- #define INT_EEPROM_BLOCK_SIZE 256U /* 器件地址分页大小 */
- /* 初始化 I2C2 并检测芯片应答;返回 0 表示成功(块0 必须应答, 块1 允许不通, 见 .c 说明) */
- uint8_t Int_eeprom_init(void);
- /* 任意地址读取 datalen 字节(支持跨页,I2C 顺序读无页限制) */
- uint8_t Int_eeprom_read(uint8_t *pbuf, uint16_t addr, uint16_t datalen);
- /* 任意地址写入 datalen 字节,自动按页拆分,写入后等待写入周期完成 */
- uint8_t Int_eeprom_write(uint8_t *pbuf, uint16_t addr, uint16_t datalen);
- /* 擦除整片(所有地址写 0xFF) */
- uint8_t Int_eeprom_erase_chip(void);
- #endif
|