at24cxx.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef __I2C_EE_H
  2. #define __I2C_EE_H
  3. /* STM32 I2C 快速模式 */
  4. #define I2C_Speed 400000 //*
  5. /* 这个地址只要与 STM32 外挂的 I2C 器件地址不一样即可 */
  6. #define I2Cx_OWN_ADDRESS7 0X0A
  7. /* AT24C01/02 每页有 8 个字节 */
  8. //#define I2C_PageSize 8
  9. /* AT24C04/08A/16A每页有16个字节 */
  10. #define I2C_PageSize 16
  11. /* 这个地址只要与STM32外挂的I2C器件地址不一样即可 */
  12. #define I2C_OWN_ADDRESS7 0X0A
  13. /*I2C接口*/
  14. #define EEPROM_I2C I2C2
  15. #define EEPROM_I2C_CLK RCC_APB1Periph_I2C2
  16. #define EEPROM_I2C_CLK_INIT RCC_APB1PeriphClockCmd
  17. #define EEPROM_I2C_SCL_PIN GPIO_Pin_10
  18. #define EEPROM_I2C_SCL_GPIO_PORT GPIOB
  19. #define EEPROM_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB
  20. #define EEPROM_I2C_SCL_SOURCE GPIO_PinSource10
  21. #define EEPROM_I2C_SDA_PIN GPIO_Pin_11
  22. #define EEPROM_I2C_SDA_GPIO_PORT GPIOB
  23. #define EEPROM_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB
  24. #define EEPROM_I2C_SDA_SOURCE GPIO_PinSource11
  25. /*等待超出时间*/
  26. #define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000)
  27. #define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))
  28. /*信息输出*/
  29. #define EEPROM_DEBUG_ON 0
  30. extern int uart_msg_send(u8 uartid, const char *buf, u32 buflen);
  31. #define EEPROM_INFO(fmt,arg...) OTP_TRACE(fmt,##arg)//trace_otp_trace1(uart_msg_send, 4, fmt, ##arg);
  32. //printf("<<-EEPROM-INFO->> "fmt"\n",##arg)
  33. #define EEPROM_ERROR(fmt,arg...) //printf("<<-EEPROM-ERROR->> "fmt"\n",##arg)
  34. #define EEPROM_DEBUG(fmt,arg...) /*do{\
  35. if(EEPROM_DEBUG_ON)\
  36. printf("<<-EEPROM-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
  37. }while(0)*/
  38. /*
  39. * AT24C02 2kb = 2048bit = 2048/8 B = 256 B
  40. * 32 pages of 8 bytes each
  41. *
  42. * Device Address
  43. * 1 0 1 0 A2 A1 A0 R/W
  44. * 1 0 1 0 0 0 0 0 = 0XA0
  45. * 1 0 1 0 0 0 0 1 = 0XA1
  46. */
  47. /* EEPROM Addresses defines */
  48. #define EEPROM_Block0_ADDRESS 0xA0 /* E2 = 0 */
  49. //#define EEPROM_Block1_ADDRESS 0xA2 /* E2 = 0 */
  50. //#define EEPROM_Block2_ADDRESS 0xA4 /* E2 = 0 */
  51. //#define EEPROM_Block3_ADDRESS 0xA6 /* E2 = 0 */
  52. void I2C_EE_Init(void);
  53. void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite);
  54. uint32_t I2C_EE_ByteWrite(u8* pBuffer, u8 WriteAddr);
  55. uint32_t I2C_EE_PageWrite(u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite);
  56. uint32_t I2C_EE_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead);
  57. void I2C_EE_WaitEepromStandbyState(void);
  58. #endif /* __I2C_EE_H */