AT24CXX_ATY.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * @file AT24CXX_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2023 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. ********************************************************************************
  28. */
  29. /*
  30. | **Model** | **Structure** | **RegisterAddress** | **BytesPerPage** | **DeviceAddress** |
  31. |:--------------:|:-------------:|:-------------------:|:----------------:|:--------------------:|
  32. | **AT24C01C** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  33. | **AT24C01D** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  34. | **AT24C02C** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  35. | **AT24C02D** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  36. | **AT24C04C** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  37. | **AT24C04D** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  38. | **AT24C08C** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  39. | **AT24C08D** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  40. | **AT24C16C** | 2048x8(16K) | 11 Bit(1 Register) | 16 Byte | 1 0 1 0 P2 P1 P0 R/W |
  41. | **AT24C16D** | 2048x8(16K) | 11 Bit(1 Register) | 16 Byte | 1 0 1 0 P2 P1 P0 R/W |
  42. | **AT24C32D** | 4096x8(32K) | 12 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  43. | **AT24C32E** | 4096x8(32K) | 12 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  44. | **AT24C64B** | 8192x8(64K) | 13 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  45. | **AT24C64D** | 8192x8(64K) | 13 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  46. | **AT24C128C** | 16384x8(128K) | 14 Bit(2 Register) | 64 Byte | 1 0 1 0 A2 A1 A0 R/W |
  47. | **AT24C256C** | 32768x8(256K) | 15 Bit(2 Register) | 64 Byte | 1 0 1 0 A2 A1 A0 R/W |
  48. | **AT24C512C** | 65536x8(512K) | 16 Bit(2 Register) | 128 Byte | 1 0 1 0 A2 A1 A0 R/W |
  49. | **AT24CM01** | 131072x8(1M) | 17 Bit(2 Register) | 256 Byte | 1 0 1 0 A2 A1 P0 R/W |
  50. | **AT24CM02** | 262144x8(2M) | 18 Bit(2 Register) | 256 Byte | 1 0 1 0 A2 P1 P0 R/W |
  51. | **AT24CS01** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  52. | **AT24CS02** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  53. | **AT24CS04** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  54. | **AT24CS08** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  55. | **AT24CS16** | 2048x8(16K) | 11 Bit(1 Register) | 16 Byte | 1 0 1 0 P2 P1 P0 R/W |
  56. | **AT24CS32** | 4096x8(32K) | 12 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  57. | **AT24CS64** | 8192x8(64K) | 13 Bit(2 Register) | 32 Byte | 1 0 1 0 A2 A1 A0 R/W |
  58. | **AT24CSW010** | 128x8(1K) | 7 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  59. | **AT24CSW020** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  60. | **AT24CSW040** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  61. | **AT24CSW080** | 1024x8(8K) | 10 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 P1 P0 R/W |
  62. | **AT24HC02C** | 256x8(2K) | 8 Bit(1 Register) | 8 Byte | 1 0 1 0 A2 A1 A0 R/W |
  63. | **AT24HC04B** | 512x8(4K) | 9 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 P0 R/W |
  64. | **AT24MAC402** | 256x8(2K) | 8 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 A0 R/W |
  65. | **AT24MAC602** | 256x8(2K) | 8 Bit(1 Register) | 16 Byte | 1 0 1 0 A2 A1 A0 R/W |
  66. */
  67. #ifndef __AT24CXX_ATY_H
  68. #define __AT24CXX_ATY_H
  69. #include "INCLUDE_ATY.h"
  70. #include "stdlib.h"
  71. #include "string.h"
  72. #include "HW_TIMER_ATY.h"
  73. #include "HW_I2C_ATY.h"
  74. /******************************* For user *************************************/
  75. // #define __DEBUG_AT24CXX_ATY
  76. #define AT24CXX_TYPE AT24C64
  77. #define AT24CXX_A2 0
  78. #define AT24CXX_A1 0
  79. #define AT24CXX_A0 0
  80. #define AT24CXX_WRITE_DELAY 16
  81. /******************************************************************************/
  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 AT24C01 127
  99. #define AT24C02 255
  100. #define AT24C04 511
  101. #define AT24C08 1023
  102. #define AT24C16 2047
  103. #define AT24C32 4095
  104. #define AT24C64 8191
  105. #define AT24C128 16383
  106. #define AT24C256 32767
  107. #define AT24C512 65535
  108. #define AT24CM01 131072
  109. #define AT24CM02 262144
  110. #if (AT24CXX_TYPE == AT24C01) || (AT24CXX_TYPE == AT24C02)
  111. #define AT24CXX_PAGE_SIZE 8
  112. #elif (AT24CXX_TYPE == AT24C04) || (AT24CXX_TYPE == AT24C08) || (AT24CXX_TYPE == AT24C16)
  113. #define AT24CXX_PAGE_SIZE 16
  114. #elif (AT24CXX_TYPE == AT24C32) || (AT24CXX_TYPE == AT24C64)
  115. #define AT24CXX_PAGE_SIZE 32
  116. #elif (AT24CXX_TYPE == AT24C128) || (AT24CXX_TYPE == AT24C256)
  117. #define AT24CXX_PAGE_SIZE 64
  118. #elif (AT24CXX_TYPE == AT24C512)
  119. #define AT24CXX_PAGE_SIZE 128
  120. #elif (AT24CXX_TYPE == AT24CM01) || (AT24CXX_TYPE == AT24CM02)
  121. #define AT24CXX_PAGE_SIZE 256
  122. #endif
  123. uint8_t AT24CXX_ReadByte(uint16_t addr);
  124. void AT24CXX_WriteByte(uint16_t addr, uint8_t data_t);
  125. void AT24CXX_Read(uint16_t addr, uint8_t* pbuf, uint16_t len);
  126. void AT24CXX_Write(uint16_t addr, uint8_t* pbuf, uint16_t len);
  127. void AT24CXX_WriteRandom(uint16_t addr, uint8_t* pbuf, uint16_t len);
  128. uint8_t AT24CXX_Check(void);
  129. void AT24CXX_Init(void);
  130. #ifdef __DEBUG_AT24CXX_ATY
  131. uint8_t AT24CXX_Test(void);
  132. #endif /* __DEBUG_AT24CXX_ATY */
  133. #endif /* __AT24CXX_ATY_H */
  134. /******************************** End Of File *********************************/