F2837xD_I2C.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. //###########################################################################
  2. //
  3. // FILE: F2837xD_I2C.c
  4. //
  5. // TITLE: F2837xD I2C Initialization & Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. //
  43. // Included Files
  44. //
  45. #include "F2837xD_device.h"
  46. #include "F2837xD_Examples.h"
  47. //
  48. //---------------------------------------------------------------------------
  49. // Example: I2cAGpioConfig(), I2cBGpioConfig()
  50. //---------------------------------------------------------------------------
  51. // These functions configures GPIO pins to function as I2C pins
  52. //
  53. // Each GPIO pin can be configured as a GPIO pin or up to 3 different
  54. // peripheral functional pins. By default all pins come up as GPIO
  55. // inputs after reset.
  56. //
  57. #ifdef CPU1
  58. //
  59. // I2cAGpioConfig - Configure I2CA GPIOs
  60. // 'I2caDataClkPin' should be assign with one of the
  61. // possible I2C_A SDA - SDL GPIO pin Use defined Macros from
  62. // "F2837xD_I2c_defines.h" for assignment
  63. //
  64. void I2cAGpioConfig(Uint16 I2caDataClkPin)
  65. {
  66. EALLOW;
  67. switch(I2caDataClkPin)
  68. {
  69. case I2C_A_GPIO0_GPIO1:
  70. //
  71. // Enable internal pull-up for the selected I2C pins
  72. // Enable pull-up for GPIO0 (SDAA)
  73. // Enable pull-up for GPIO1 (SDLA)
  74. //
  75. GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;
  76. GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;
  77. //
  78. // Set qualification for the selected I2C pins
  79. // Async/no qualification (I/ps sync to SYSCLKOUT by default)
  80. //
  81. GpioCtrlRegs.GPAQSEL1.bit.GPIO0 = 3;
  82. GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 3;
  83. //
  84. // Configure which of the possible GPIO pins will be I2C_A pins
  85. // using GPIO regs
  86. // Configure GPIO0 for SDAA operation
  87. // Configure GPIO0 for SDAA operation
  88. //
  89. GpioCtrlRegs.GPAGMUX1.bit.GPIO0 = 1;
  90. GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 2;
  91. //
  92. // Configure GPIO1 for SDLA operation
  93. // Configure GPIO1 for SDLA operation
  94. //
  95. GpioCtrlRegs.GPAGMUX1.bit.GPIO1 = 1;
  96. GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 2;
  97. break;
  98. case I2C_A_GPIO32_GPIO33:
  99. //
  100. // Enable internal pull-up for the selected I2C pins
  101. //
  102. GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;
  103. GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;
  104. //
  105. // Set qualification for the selected I2C pins
  106. //
  107. GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3;
  108. GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3;
  109. //
  110. // Configure which of the possible GPIO pins will be I2C_A pins
  111. // using GPIO regs
  112. //
  113. GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1;
  114. GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;
  115. break;
  116. case I2C_A_GPIO42_GPIO43:
  117. //
  118. // Enable internal pull-up for the selected I2C pins
  119. //
  120. //
  121. // Set qualification for the selected I2C pins
  122. //
  123. //
  124. // Configure which of the possible GPIO pins will be I2C_A pins
  125. // using GPIO regs
  126. //
  127. break;
  128. case I2C_A_GPIO91_GPIO92:
  129. //
  130. // Enable internal pull-up for the selected I2C pins
  131. //
  132. GpioCtrlRegs.GPCPUD.bit.GPIO91 = 0;
  133. GpioCtrlRegs.GPCPUD.bit.GPIO92 = 0;
  134. //
  135. // Set qualification for the selected I2C pins
  136. //
  137. GpioCtrlRegs.GPCQSEL2.bit.GPIO91 = 3;
  138. GpioCtrlRegs.GPCQSEL2.bit.GPIO92 = 3;
  139. //
  140. // Configure which of the possible GPIO pins will be I2C_A pins
  141. // using GPIO regs
  142. //
  143. GpioCtrlRegs.GPCGMUX2.bit.GPIO91 = 1;
  144. GpioCtrlRegs.GPCMUX2.bit.GPIO91 = 2;
  145. GpioCtrlRegs.GPCGMUX2.bit.GPIO92 = 1;
  146. GpioCtrlRegs.GPCMUX2.bit.GPIO92 = 2;
  147. break;
  148. case I2C_A_GPIO63104_GPIO105:
  149. //
  150. // Enable internal pull-up for the selected I2C pins
  151. //
  152. //
  153. // Set qualification for the selected I2C pins
  154. //
  155. //
  156. // Configure which of the possible GPIO pins will be I2C_A pins
  157. // using GPIO regs
  158. //
  159. break;
  160. default:
  161. break;
  162. } // End of Switch
  163. EDIS;
  164. }
  165. //
  166. // I2cBGpioConfig - Configure I2CB GPIOs
  167. // 'I2cbDataClkPin' should be assign with one of the possible
  168. // I2C_B SDA - SDL GPIO pin Use defined Macros from
  169. // "F2837xD_I2c_defines.h" for assignment
  170. //
  171. void I2cBGpioConfig(Uint16 I2cbDataClkPin)
  172. {
  173. EALLOW;
  174. switch(I2cbDataClkPin)
  175. {
  176. case I2C_B_GPIO2_GPIO3:
  177. //
  178. // Enable internal pull-up for the selected I2C pins
  179. // Enable pull-up for GPIO2 (SDAB)
  180. // Enable pull-up for GPIO3 (SDLB)
  181. //
  182. GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0;
  183. GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;
  184. //
  185. // Set qualification for the selected I2C pins
  186. // Async/no qualification (I/ps sync to SYSCLKOUT by default)
  187. //
  188. GpioCtrlRegs.GPAQSEL1.bit.GPIO2 = 3;
  189. GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3;
  190. //
  191. // Configure which of the possible GPIO pins will be I2C_B pins
  192. // using GPIO regs
  193. // Configure GPIO2 for SDAB operation
  194. // Configure GPIO3 for SDAB operation
  195. // Configure GPIO1 for SDLB operation
  196. // Configure GPIO1 for SDLB operation
  197. //
  198. GpioCtrlRegs.GPAGMUX1.bit.GPIO2 = 1;
  199. GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 2;
  200. GpioCtrlRegs.GPAGMUX1.bit.GPIO3 = 1;
  201. GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2;
  202. break;
  203. case I2C_B_GPIO134_GPIO35:
  204. //
  205. // Enable internal pull-up for the selected I2C pins
  206. //
  207. //
  208. // Set qualification for the selected I2C pins
  209. //
  210. //
  211. // Configure which of the possible GPIO pins will be I2C_B pins
  212. // using GPIO regs
  213. //
  214. break;
  215. case I2C_B_GPIO40_GPIO41:
  216. //
  217. // Enable internal pull-up for the selected I2C pins
  218. //
  219. //
  220. // Set qualification for the selected I2C pins
  221. //
  222. //
  223. // Configure which of the possible GPIO pins will be I2C_B pins
  224. // using GPIO regs
  225. //
  226. break;
  227. case I2C_B_GPIO66_GPIO69:
  228. //
  229. // Enable internal pull-up for the selected I2C pins
  230. //
  231. GpioCtrlRegs.GPCPUD.bit.GPIO66 = 0; //SDAB
  232. GpioCtrlRegs.GPCPUD.bit.GPIO69 = 0; //SCLB
  233. //
  234. // Set qualification for the selected I2C pins
  235. //
  236. GpioCtrlRegs.GPCQSEL1.bit.GPIO66 = 3;
  237. GpioCtrlRegs.GPCQSEL1.bit.GPIO69 = 3;
  238. //
  239. // Configure which of the possible GPIO pins will be I2C_B pins
  240. // using GPIO regs
  241. //
  242. GpioCtrlRegs.GPCGMUX1.bit.GPIO66 = 1; //0x6
  243. GpioCtrlRegs.GPCMUX1.bit.GPIO66 = 2;
  244. GpioCtrlRegs.GPCGMUX1.bit.GPIO69 = 1; //0x6
  245. GpioCtrlRegs.GPCMUX1.bit.GPIO69 = 2;
  246. break;
  247. default:
  248. break;
  249. }
  250. EDIS;
  251. }
  252. #endif
  253. //
  254. // End of file
  255. //