AT24CXX_ATY.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * @file AT24CXX_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2025 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Familiar functions of AT24CXX for all embedded device
  20. *
  21. * @version
  22. * - 1_01_220602 > ATY
  23. * -# Preliminary version, first Release
  24. * - 1_01_221212 > ATY
  25. * -# Change to general I2C function
  26. * -# Change and remove several functions
  27. * - 1_02_231229 > ATY
  28. * -# add multy addr and channel
  29. ********************************************************************************
  30. */
  31. /*
  32. | **Model** | **Structure** | **RegisterAddress** | **BytesPerPage** | **DeviceAddress** |
  33. |:--------------:|:-------------:|:-------------------:|:----------------:|:--------------------:|
  34. | **AT24C01C** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  35. | **AT24C01D** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  36. | **AT24C02C** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  37. | **AT24C02D** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  38. | **AT24C04C** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  39. | **AT24C04D** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  40. | **AT24C08C** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  41. | **AT24C08D** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  42. | **AT24C16C** | 2048x8(16K) | 11 Bit(1 Register) | 16 Byte | 1 0 1 0 P2 P1 P0 R/W |
  43. | **AT24C16D** | 2048x8(16K) | 11 Bit(1 Register) | 16 Byte | 1 0 1 0 P2 P1 P0 R/W |
  44. | **AT24C32D** | 4096x8(32K) | 12 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  45. | **AT24C32E** | 4096x8(32K) | 12 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  46. | **AT24C64B** | 8192x8(64K) | 13 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  47. | **AT24C64D** | 8192x8(64K) | 13 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  48. | **AT24C128C** | 16384x8(128K) | 14 Bit(2 Register) | 64 Byte | 1 0 1 0 A2 A1 A0 R/W |
  49. | **AT24C256C** | 32768x8(256K) | 15 Bit(2 Register) | 64 Byte | 1 0 1 0 A2 A1 A0 R/W |
  50. | **AT24C512C** | 65536x8(512K) | 16 Bit(2 Register) | 128 Byte | 1 0 1 0 A2 A1 A0 R/W |
  51. | **AT24CM01** | 131072x8(1M) | 17 Bit(2 Register) | 256 Byte | 1 0 1 0 A2 A1 P0 R/W |
  52. | **AT24CM02** | 262144x8(2M) | 18 Bit(2 Register) | 256 Byte | 1 0 1 0 A2 P1 P0 R/W |
  53. | **AT24CS01** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  54. | **AT24CS02** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  55. | **AT24CS04** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  56. | **AT24CS08** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  57. | **AT24CS16** | 2048x8(16K) | 11 Bit(1 Register) | 16 Byte | 1 0 1 0 P2 P1 P0 R/W |
  58. | **AT24CS32** | 4096x8(32K) | 12 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  59. | **AT24CS64** | 8192x8(64K) | 13 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  60. | **AT24CSW010** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  61. | **AT24CSW020** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  62. | **AT24CSW040** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  63. | **AT24CSW080** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  64. | **AT24HC02C** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  65. | **AT24HC04B** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  66. | **AT24MAC402** | 256x8(2K) | 8 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 A0 R/W |
  67. | **AT24MAC602** | 256x8(2K) | 8 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 A0 R/W |
  68. */
  69. #ifndef __AT24CXX_ATY_H
  70. #define __AT24CXX_ATY_H
  71. #include "INCLUDE_ATY.h"
  72. #include "stdlib.h"
  73. #include "string.h"
  74. #include "HW_TIMER_ATY.h"
  75. #include "HW_I2C_ATY.h"
  76. /******************************* For user *************************************/
  77. // #define __DEBUG_AT24CXX_ATY
  78. #define AT24CXX_TYPE AT24C64
  79. #define AT24CXX_A2 0
  80. #define AT24CXX_A1 0
  81. #define AT24CXX_A0 0
  82. /*
  83. The next 3 bits are the A2, A1 and A0 device address bits for the 2K EEPROM.
  84. These 3 bits must compare to their corresponding hardwired input pins.
  85. The 4K EEPROM only uses the A2 and A1 device address bits with the third bit
  86. being a memory page address bit. The two device address bits must compare to
  87. their corresponding hardwired input pins. The A0 pin is no connect.
  88. The 8K EEPROM only uses the A2 device address bit with the next 2 bits being
  89. for memory page addressing. The A2 bit must compare to its corresponding
  90. hard-wired input pin. The A1 and A0 pins are no connect.
  91. The 16K does not use any device address bits but instead the 3 bits are used
  92. for memory page addressing.
  93. Upon a compare of the device address, the EEPROM will output a "0".
  94. If a compare is not made, the chip will return to a standby state.
  95. */
  96. // 1 0 1 0 A2 A1 A0 R/W
  97. #define AT24CXX_ADDRESS (0x50 | (AT24CXX_A2 << 2) | (AT24CXX_A1 << 1) | AT24CXX_A0)
  98. // #define AT4CXX_I2C I2C_C1
  99. #define AT24CXX_WRITE_DELAY 16
  100. /******************************************************************************/
  101. #define AT24C01 127
  102. #define AT24C02 255
  103. #define AT24C04 511
  104. #define AT24C08 1023
  105. #define AT24C16 2047
  106. #define AT24C32 4095
  107. #define AT24C64 8191
  108. #define AT24C128 16383
  109. #define AT24C256 32767
  110. #define AT24C512 65535
  111. #define AT24CM01 131072
  112. #define AT24CM02 262144
  113. #if (AT24CXX_TYPE == AT24C01) || (AT24CXX_TYPE == AT24C02)
  114. #define AT24CXX_PAGE_SIZE 8
  115. #elif (AT24CXX_TYPE == AT24C04) || (AT24CXX_TYPE == AT24C08) || (AT24CXX_TYPE == AT24C16)
  116. #define AT24CXX_PAGE_SIZE 16
  117. #elif (AT24CXX_TYPE == AT24C32) || (AT24CXX_TYPE == AT24C64)
  118. #define AT24CXX_PAGE_SIZE 32
  119. #elif (AT24CXX_TYPE == AT24C128) || (AT24CXX_TYPE == AT24C256)
  120. #define AT24CXX_PAGE_SIZE 64
  121. #elif (AT24CXX_TYPE == AT24C512)
  122. #define AT24CXX_PAGE_SIZE 128
  123. #elif (AT24CXX_TYPE == AT24CM01) || (AT24CXX_TYPE == AT24CM02)
  124. #define AT24CXX_PAGE_SIZE 256
  125. #endif
  126. uint8_t AT24CXX_ReadByte(uint16_t regAddr, uint8_t addr, uint8_t channel);
  127. void AT24CXX_WriteByte(uint16_t regAddr, uint8_t data_t, uint8_t addr, uint8_t channel);
  128. void AT24CXX_Read(uint16_t regAddr, uint8_t* pbuf, uint16_t len, uint8_t addr, uint8_t channel);
  129. void AT24CXX_Write(uint16_t regAddr, uint8_t* pbuf, uint16_t len, uint8_t addr, uint8_t channel);
  130. void AT24CXX_WriteRandom(uint16_t regAddr, uint8_t* pbuf, uint16_t len, uint8_t addr, uint8_t channel);
  131. uint8_t AT24CXX_Check(, uint8_t addr, uint8_t channel);
  132. void AT24CXX_Init(uint8_t addr, uint8_t channel);
  133. #ifdef __DEBUG_AT24CXX_ATY
  134. uint8_t AT24CXX_Test(uint8_t addr, uint8_t channel);
  135. #endif /* __DEBUG_AT24CXX_ATY */
  136. #endif /* __AT24CXX_ATY_H */
  137. /******************************** End Of File *********************************/