#ifndef __EEPROM_H #define __EEPROM_H #include "main.h" #define EE_MODEL_NAME "M24C64" #define EE_DEV_ADDR 0xA0 /* 设备地址 */ #define EE_PAGE_SIZE 32 /* 页面大小(字节) */ #define EE_SIZE (8*1024) /* 总容量(字节) */ #define EE_ADDR_BYTES 2 /* 地址字节个数 */ #define EEPROM_WriteAddress1 0x00 #define EEPROM_ReadAddress1 0x00 #define BufferSize1 sizeof(Tx1_Buffer) #define PRO1_ADDR EEPROM_WriteAddress1 #define PRO2_ADDR EEPROM_WriteAddress1 + 12 extern uint8_t Tx1_Buffer[]; extern uint8_t Rx1_Buffer[]; #define I2C_WR 0 #define I2C_RD 1 // 定义I2C总线连接的GPIO端口, 用户只需要修改下面3行代码即可任意改变SCL和SDA的引脚 #define GPIO_PORT_I2C GPIOB // GPIO端口 #define I2C_SCL_PIN GPIO_PIN_6 // 连接到SCL时钟线的GPIO #define I2C_SDA_PIN GPIO_PIN_7 // 连接到SDA数据线的GPIO /* 定义读写SCL和SDA的宏 */ #define I2C_SCL_1() GPIO_PORT_I2C->BSRR = I2C_SCL_PIN // SCL = 1 #define I2C_SCL_0() GPIO_PORT_I2C->BSRR = (uint32_t)I2C_SCL_PIN << 16U // SCL = 0 #define I2C_SDA_1() GPIO_PORT_I2C->BSRR = I2C_SDA_PIN // SDA = 1 #define I2C_SDA_0() GPIO_PORT_I2C->BSRR = (uint32_t)I2C_SDA_PIN << 16U // SDA = 0 #define I2C_SDA_READ() (GPIO_PORT_I2C->IDR & I2C_SDA_PIN) // 读SDA口线状态 #define I2C_SCL_READ() (GPIO_PORT_I2C->IDR & I2C_SCL_PIN) // 读SCL口线状态 void ee_io_init(void); uint8_t ee_writebytes(uint8_t *_pWriteBuf, uint16_t _usAddress, uint16_t _usSize); uint8_t ee_readbytes(uint8_t *_pReadBuf, uint16_t _usAddress, uint16_t _usSize); void ee_writefloats(uint16_t _usAddress, float wr_data[3], uint8_t _usSize); void ee_readfloats(uint16_t _usAddress, float rd_data[3], uint8_t _usSize); #endif /*! end of the file */