Int_eeprom.h 1.3 KB

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