#ifndef __I2C_EE_H #define __I2C_EE_H /* STM32 I2C 快速模式 */ #define I2C_Speed 400000 //* /* 这个地址只要与 STM32 外挂的 I2C 器件地址不一样即可 */ #define I2Cx_OWN_ADDRESS7 0X0A /* AT24C01/02 每页有 8 个字节 */ //#define I2C_PageSize 8 /* AT24C04/08A/16A每页有16个字节 */ #define I2C_PageSize 16 /* 这个地址只要与STM32外挂的I2C器件地址不一样即可 */ #define I2C_OWN_ADDRESS7 0X0A /*I2C接口*/ #define EEPROM_I2C I2C2 #define EEPROM_I2C_CLK RCC_APB1Periph_I2C2 #define EEPROM_I2C_CLK_INIT RCC_APB1PeriphClockCmd #define EEPROM_I2C_SCL_PIN GPIO_Pin_10 #define EEPROM_I2C_SCL_GPIO_PORT GPIOB #define EEPROM_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB #define EEPROM_I2C_SCL_SOURCE GPIO_PinSource10 #define EEPROM_I2C_SDA_PIN GPIO_Pin_11 #define EEPROM_I2C_SDA_GPIO_PORT GPIOB #define EEPROM_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB #define EEPROM_I2C_SDA_SOURCE GPIO_PinSource11 /*等待超出时间*/ #define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000) #define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT)) /*信息输出*/ #define EEPROM_DEBUG_ON 0 extern int uart_msg_send(u8 uartid, const char *buf, u32 buflen); #define EEPROM_INFO(fmt,arg...) OTP_TRACE(fmt,##arg)//trace_otp_trace1(uart_msg_send, 4, fmt, ##arg); //printf("<<-EEPROM-INFO->> "fmt"\n",##arg) #define EEPROM_ERROR(fmt,arg...) //printf("<<-EEPROM-ERROR->> "fmt"\n",##arg) #define EEPROM_DEBUG(fmt,arg...) /*do{\ if(EEPROM_DEBUG_ON)\ printf("<<-EEPROM-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\ }while(0)*/ /* * AT24C02 2kb = 2048bit = 2048/8 B = 256 B * 32 pages of 8 bytes each * * Device Address * 1 0 1 0 A2 A1 A0 R/W * 1 0 1 0 0 0 0 0 = 0XA0 * 1 0 1 0 0 0 0 1 = 0XA1 */ /* EEPROM Addresses defines */ #define EEPROM_Block0_ADDRESS 0xA0 /* E2 = 0 */ //#define EEPROM_Block1_ADDRESS 0xA2 /* E2 = 0 */ //#define EEPROM_Block2_ADDRESS 0xA4 /* E2 = 0 */ //#define EEPROM_Block3_ADDRESS 0xA6 /* E2 = 0 */ void I2C_EE_Init(void); void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite); uint32_t I2C_EE_ByteWrite(u8* pBuffer, u8 WriteAddr); uint32_t I2C_EE_PageWrite(u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite); uint32_t I2C_EE_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead); void I2C_EE_WaitEepromStandbyState(void); #endif /* __I2C_EE_H */