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 //
44 // Included Files
45 //
46 #include "F2837xD_device.h"
47 #include "F2837xD_Examples.h"
48
49 //
50 //---------------------------------------------------------------------------
51 // Example: I2cAGpioConfig(), I2cBGpioConfig()
52 //---------------------------------------------------------------------------
53 // These functions configures GPIO pins to function as I2C pins
54 //
55 // Each GPIO pin can be configured as a GPIO pin or up to 3 different
56 // peripheral functional pins. By default all pins come up as GPIO
57 // inputs after reset.
58 //
59
60 #ifdef CPU1
61 //
62 // I2cAGpioConfig - Configure I2CA GPIOs
63 // 'I2caDataClkPin' should be assign with one of the
64 // possible I2C_A SDA - SDL GPIO pin Use defined Macros from
65 // "F2837xD_I2c_defines.h" for assignment
66 //
I2cAGpioConfig(Uint16 I2caDataClkPin)67 void I2cAGpioConfig(Uint16 I2caDataClkPin)
68 {
69 EALLOW;
70
71 switch(I2caDataClkPin)
72 {
73 case I2C_A_GPIO0_GPIO1:
74
75 //
76 // Enable internal pull-up for the selected I2C pins
77 // Enable pull-up for GPIO0 (SDAA)
78 // Enable pull-up for GPIO1 (SDLA)
79 //
80 GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;
81 GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;
82
83 //
84 // Set qualification for the selected I2C pins
85 // Async/no qualification (I/ps sync to SYSCLKOUT by default)
86 //
87 GpioCtrlRegs.GPAQSEL1.bit.GPIO0 = 3;
88 GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 3;
89
90 //
91 // Configure which of the possible GPIO pins will be I2C_A pins
92 // using GPIO regs
93 // Configure GPIO0 for SDAA operation
94 // Configure GPIO0 for SDAA operation
95 //
96 GpioCtrlRegs.GPAGMUX1.bit.GPIO0 = 1;
97 GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 2;
98
99 //
100 // Configure GPIO1 for SDLA operation
101 // Configure GPIO1 for SDLA operation
102 //
103 GpioCtrlRegs.GPAGMUX1.bit.GPIO1 = 1;
104 GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 2;
105
106 break;
107
108 case I2C_A_GPIO32_GPIO33:
109 //
110 // Enable internal pull-up for the selected I2C pins
111 //
112 GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;
113 GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;
114
115 //
116 // Set qualification for the selected I2C pins
117 //
118 GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3;
119 GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3;
120
121 //
122 // Configure which of the possible GPIO pins will be I2C_A pins
123 // using GPIO regs
124 //
125 GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1;
126 GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;
127
128 break;
129
130 case I2C_A_GPIO42_GPIO43:
131 //
132 // Enable internal pull-up for the selected I2C pins
133 //
134
135 //
136 // Set qualification for the selected I2C pins
137 //
138
139 //
140 // Configure which of the possible GPIO pins will be I2C_A pins
141 // using GPIO regs
142 //
143 break;
144
145 case I2C_A_GPIO91_GPIO92:
146 //
147 // Enable internal pull-up for the selected I2C pins
148 //
149 GpioCtrlRegs.GPCPUD.bit.GPIO91 = 0;
150 GpioCtrlRegs.GPCPUD.bit.GPIO92 = 0;
151
152 //
153 // Set qualification for the selected I2C pins
154 //
155 GpioCtrlRegs.GPCQSEL2.bit.GPIO91 = 3;
156 GpioCtrlRegs.GPCQSEL2.bit.GPIO92 = 3;
157
158 //
159 // Configure which of the possible GPIO pins will be I2C_A pins
160 // using GPIO regs
161 //
162 GpioCtrlRegs.GPCGMUX2.bit.GPIO91 = 1;
163 GpioCtrlRegs.GPCMUX2.bit.GPIO91 = 2;
164 GpioCtrlRegs.GPCGMUX2.bit.GPIO92 = 1;
165 GpioCtrlRegs.GPCMUX2.bit.GPIO92 = 2;
166 break;
167
168 case I2C_A_GPIO63104_GPIO105:
169 //
170 // Enable internal pull-up for the selected I2C pins
171 //
172
173 //
174 // Set qualification for the selected I2C pins
175 //
176
177 //
178 // Configure which of the possible GPIO pins will be I2C_A pins
179 // using GPIO regs
180 //
181 break;
182
183 default:
184
185 break;
186
187 } // End of Switch
188 EDIS;
189 }
190
191 //
192 // I2cBGpioConfig - Configure I2CB GPIOs
193 // 'I2cbDataClkPin' should be assign with one of the possible
194 // I2C_B SDA - SDL GPIO pin Use defined Macros from
195 // "F2837xD_I2c_defines.h" for assignment
196 //
I2cBGpioConfig(Uint16 I2cbDataClkPin)197 void I2cBGpioConfig(Uint16 I2cbDataClkPin)
198 {
199 EALLOW;
200
201 switch(I2cbDataClkPin)
202 {
203 case I2C_B_GPIO2_GPIO3:
204 //
205 // Enable internal pull-up for the selected I2C pins
206 // Enable pull-up for GPIO2 (SDAB)
207 // Enable pull-up for GPIO3 (SDLB)
208 //
209 GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0;
210 GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;
211
212 //
213 // Set qualification for the selected I2C pins
214 // Async/no qualification (I/ps sync to SYSCLKOUT by default)
215 //
216 GpioCtrlRegs.GPAQSEL1.bit.GPIO2 = 3;
217 GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3;
218
219 //
220 // Configure which of the possible GPIO pins will be I2C_B pins
221 // using GPIO regs
222 // Configure GPIO2 for SDAB operation
223 // Configure GPIO3 for SDAB operation
224 // Configure GPIO1 for SDLB operation
225 // Configure GPIO1 for SDLB operation
226 //
227 GpioCtrlRegs.GPAGMUX1.bit.GPIO2 = 1;
228 GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 2;
229
230 GpioCtrlRegs.GPAGMUX1.bit.GPIO3 = 1;
231 GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2;
232
233 break;
234
235 case I2C_B_GPIO134_GPIO35:
236 //
237 // Enable internal pull-up for the selected I2C pins
238 //
239
240 //
241 // Set qualification for the selected I2C pins
242 //
243
244 //
245 // Configure which of the possible GPIO pins will be I2C_B pins
246 // using GPIO regs
247 //
248 break;
249
250 case I2C_B_GPIO40_GPIO41:
251 //
252 // Enable internal pull-up for the selected I2C pins
253 //
254
255 //
256 // Set qualification for the selected I2C pins
257 //
258
259 //
260 // Configure which of the possible GPIO pins will be I2C_B pins
261 // using GPIO regs
262 //
263 break;
264
265 case I2C_B_GPIO66_GPIO69:
266 //
267 // Enable internal pull-up for the selected I2C pins
268 //
269 GpioCtrlRegs.GPCPUD.bit.GPIO66 = 0; //SDAB
270 GpioCtrlRegs.GPCPUD.bit.GPIO69 = 0; //SCLB
271
272 //
273 // Set qualification for the selected I2C pins
274 //
275 GpioCtrlRegs.GPCQSEL1.bit.GPIO66 = 3;
276 GpioCtrlRegs.GPCQSEL1.bit.GPIO69 = 3;
277
278 //
279 // Configure which of the possible GPIO pins will be I2C_B pins
280 // using GPIO regs
281 //
282 GpioCtrlRegs.GPCGMUX1.bit.GPIO66 = 1; //0x6
283 GpioCtrlRegs.GPCMUX1.bit.GPIO66 = 2;
284
285 GpioCtrlRegs.GPCGMUX1.bit.GPIO69 = 1; //0x6
286 GpioCtrlRegs.GPCMUX1.bit.GPIO69 = 2;
287 break;
288
289 default:
290 break;
291
292 }
293 EDIS;
294 }
295
296 #endif
297
298
299 //
300 // End of file
301 //
302