]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - msp430-bsl/msp430-bsl.git/blob - source/driverlib/MSP430F5xx_6xx/eusci_b_i2c.h
MSP-BSL v3.0
[msp430-bsl/msp430-bsl.git] / source / driverlib / MSP430F5xx_6xx / eusci_b_i2c.h
1 /* --COPYRIGHT--,BSD\r
2  * Copyright (c) 2014, Texas Instruments Incorporated\r
3  * All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without\r
6  * modification, are permitted provided that the following conditions\r
7  * are met:\r
8  *\r
9  * *  Redistributions of source code must retain the above copyright\r
10  *    notice, this list of conditions and the following disclaimer.\r
11  *\r
12  * *  Redistributions in binary form must reproduce the above copyright\r
13  *    notice, this list of conditions and the following disclaimer in the\r
14  *    documentation and/or other materials provided with the distribution.\r
15  *\r
16  * *  Neither the name of Texas Instruments Incorporated nor the names of\r
17  *    its contributors may be used to endorse or promote products derived\r
18  *    from this software without specific prior written permission.\r
19  *\r
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31  * --/COPYRIGHT--*/\r
32 //*****************************************************************************\r
33 //\r
34 // eusci_b_i2c.h - Driver for the EUSCI_B_I2C Module.\r
35 //\r
36 //*****************************************************************************\r
37 \r
38 #ifndef __MSP430WARE_EUSCI_B_I2C_H__\r
39 #define __MSP430WARE_EUSCI_B_I2C_H__\r
40 \r
41 #include "inc/hw_memmap.h"\r
42 \r
43 #ifdef __MSP430_HAS_EUSCI_Bx__\r
44 \r
45 //*****************************************************************************\r
46 //\r
47 // If building with a C++ compiler, make all of the definitions in this header\r
48 // have a C binding.\r
49 //\r
50 //*****************************************************************************\r
51 #ifdef __cplusplus\r
52 extern "C"\r
53 {\r
54 #endif\r
55 \r
56 //******************************************************************************\r
57 //\r
58 // The following is a struct that is passed to EUSCI_B_I2C_initMaster()\r
59 //\r
60 //******************************************************************************\r
61 typedef struct EUSCI_B_I2C_initMasterParam {\r
62         uint8_t selectClockSource;\r
63         uint32_t i2cClk;\r
64         uint32_t dataRate;\r
65         uint8_t byteCounterThreshold;\r
66         uint8_t autoSTOPGeneration;\r
67 } EUSCI_B_I2C_initMasterParam;\r
68 \r
69 //******************************************************************************\r
70 //\r
71 // The following is a struct that is passed to EUSCI_B_I2C_initSlave()\r
72 //\r
73 //******************************************************************************\r
74 typedef struct EUSCI_B_I2C_initSlaveParam {\r
75         uint8_t slaveAddress;\r
76         uint8_t slaveAddressOffset;\r
77         uint32_t slaveOwnAddressEnable;\r
78 } EUSCI_B_I2C_initSlaveParam;\r
79 \r
80 //*****************************************************************************\r
81 //\r
82 // The following are values that can be passed to the autoSTOPGeneration\r
83 // parameter for functions: EUSCI_B_I2C_masterInit().\r
84 //\r
85 //*****************************************************************************\r
86 #define EUSCI_B_I2C_NO_AUTO_STOP                                       UCASTP_0\r
87 #define EUSCI_B_I2C_SET_BYTECOUNT_THRESHOLD_FLAG                       UCASTP_1\r
88 #define EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD     UCASTP_2\r
89 \r
90 //*****************************************************************************\r
91 //\r
92 // The following are values that can be passed to the dataRate parameter for\r
93 // functions: EUSCI_B_I2C_masterInit().\r
94 //\r
95 //*****************************************************************************\r
96 #define EUSCI_B_I2C_SET_DATA_RATE_400KBPS                                400000\r
97 #define EUSCI_B_I2C_SET_DATA_RATE_100KBPS                                100000\r
98 \r
99 //*****************************************************************************\r
100 //\r
101 // The following are values that can be passed to the selectClockSource\r
102 // parameter for functions: EUSCI_B_I2C_masterInit().\r
103 //\r
104 //*****************************************************************************\r
105 #define EUSCI_B_I2C_CLOCKSOURCE_ACLK                               UCSSEL__ACLK\r
106 #define EUSCI_B_I2C_CLOCKSOURCE_SMCLK                             UCSSEL__SMCLK\r
107 \r
108 //*****************************************************************************\r
109 //\r
110 // The following are values that can be passed to the slaveAddressOffset\r
111 // parameter for functions: EUSCI_B_I2C_slaveInit().\r
112 //\r
113 //*****************************************************************************\r
114 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET0                                    0x00\r
115 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET1                                    0x02\r
116 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET2                                    0x04\r
117 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET3                                    0x06\r
118 \r
119 //*****************************************************************************\r
120 //\r
121 // The following are values that can be passed to the slaveOwnAddressEnable\r
122 // parameter for functions: EUSCI_B_I2C_slaveInit().\r
123 //\r
124 //*****************************************************************************\r
125 #define EUSCI_B_I2C_OWN_ADDRESS_DISABLE                                    0x00\r
126 #define EUSCI_B_I2C_OWN_ADDRESS_ENABLE                                   UCOAEN\r
127 \r
128 //*****************************************************************************\r
129 //\r
130 // The following are values that can be passed to the mode parameter for\r
131 // functions: EUSCI_B_I2C_setMode() as well as returned by the\r
132 // EUSCI_B_I2C_getMode() function.\r
133 //\r
134 //*****************************************************************************\r
135 #define EUSCI_B_I2C_TRANSMIT_MODE                                          UCTR\r
136 #define EUSCI_B_I2C_RECEIVE_MODE                                           0x00\r
137 \r
138 //*****************************************************************************\r
139 //\r
140 // The following are values that can be passed to the mask parameter for\r
141 // functions: EUSCI_B_I2C_enableInterrupt(), EUSCI_B_I2C_disableInterrupt(),\r
142 // EUSCI_B_I2C_clearInterruptFlag(), and EUSCI_B_I2C_getInterruptStatus() as\r
143 // well as returned by the EUSCI_B_I2C_getInterruptStatus() function.\r
144 //\r
145 //*****************************************************************************\r
146 #define EUSCI_B_I2C_NAK_INTERRUPT                                      UCNACKIE\r
147 #define EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT                            UCALIE\r
148 #define EUSCI_B_I2C_STOP_INTERRUPT                                      UCSTPIE\r
149 #define EUSCI_B_I2C_START_INTERRUPT                                     UCSTTIE\r
150 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT0                                 UCTXIE0\r
151 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT1                                 UCTXIE1\r
152 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT2                                 UCTXIE2\r
153 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT3                                 UCTXIE3\r
154 #define EUSCI_B_I2C_RECEIVE_INTERRUPT0                                  UCRXIE0\r
155 #define EUSCI_B_I2C_RECEIVE_INTERRUPT1                                  UCRXIE1\r
156 #define EUSCI_B_I2C_RECEIVE_INTERRUPT2                                  UCRXIE2\r
157 #define EUSCI_B_I2C_RECEIVE_INTERRUPT3                                  UCRXIE3\r
158 #define EUSCI_B_I2C_BIT9_POSITION_INTERRUPT                            UCBIT9IE\r
159 #define EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT                        UCCLTOIE\r
160 #define EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT                             UCBCNTIE\r
161 \r
162 //*****************************************************************************\r
163 //\r
164 // The following are values that can be passed toThe following are values that\r
165 // can be returned by the EUSCI_B_I2C_isBusBusy() function.\r
166 //\r
167 //*****************************************************************************\r
168 #define EUSCI_B_I2C_BUS_BUSY                                            UCBBUSY\r
169 #define EUSCI_B_I2C_BUS_NOT_BUSY                                           0x00\r
170 \r
171 //*****************************************************************************\r
172 //\r
173 // The following are values that can be passed toThe following are values that\r
174 // can be returned by the EUSCI_B_I2C_masterIsStopSent() function.\r
175 //\r
176 //*****************************************************************************\r
177 #define EUSCI_B_I2C_STOP_SEND_COMPLETE                                     0x00\r
178 #define EUSCI_B_I2C_SENDING_STOP                                        UCTXSTP\r
179 \r
180 //*****************************************************************************\r
181 //\r
182 // The following are values that can be passed toThe following are values that\r
183 // can be returned by the EUSCI_B_I2C_masterIsStartSent() function.\r
184 //\r
185 //*****************************************************************************\r
186 #define EUSCI_B_I2C_START_SEND_COMPLETE                                    0x00\r
187 #define EUSCI_B_I2C_SENDING_START                                       UCTXSTT\r
188 \r
189 //*****************************************************************************\r
190 //\r
191 // Prototypes for the APIs.\r
192 //\r
193 //*****************************************************************************\r
194 extern void EUSCI_B_I2C_initMaster(uint16_t baseAddress,\r
195                                    EUSCI_B_I2C_initMasterParam *param);\r
196 \r
197 extern void EUSCI_B_I2C_initSlave(uint16_t baseAddress,\r
198                                   EUSCI_B_I2C_initSlaveParam *param);\r
199 \r
200 extern void EUSCI_B_I2C_enable(uint16_t baseAddress);\r
201 \r
202 extern void EUSCI_B_I2C_disable(uint16_t baseAddress);\r
203 \r
204 extern void EUSCI_B_I2C_setSlaveAddress(uint16_t baseAddress,\r
205                                         uint8_t slaveAddress);\r
206 \r
207 extern void EUSCI_B_I2C_setMode(uint16_t baseAddress,\r
208                                 uint8_t mode);\r
209 \r
210 extern uint8_t EUSCI_B_I2C_getMode(uint16_t baseAddress);\r
211 \r
212 extern void EUSCI_B_I2C_slaveDataPut(uint16_t baseAddress,\r
213                                      uint8_t transmitData);\r
214 \r
215 extern uint8_t EUSCI_B_I2C_slaveDataGet(uint16_t baseAddress);\r
216 \r
217 extern uint16_t EUSCI_B_I2C_isBusBusy(uint16_t baseAddress);\r
218 \r
219 extern uint16_t EUSCI_B_I2C_masterIsStopSent(uint16_t baseAddress);\r
220 \r
221 extern uint16_t EUSCI_B_I2C_masterIsStartSent(uint16_t baseAddress);\r
222 \r
223 extern void EUSCI_B_I2C_enableInterrupt(uint16_t baseAddress,\r
224                                         uint16_t mask);\r
225 \r
226 extern void EUSCI_B_I2C_disableInterrupt(uint16_t baseAddress,\r
227                                          uint16_t mask);\r
228 \r
229 extern void EUSCI_B_I2C_clearInterruptFlag(uint16_t baseAddress,\r
230                                            uint16_t mask);\r
231 \r
232 extern uint16_t EUSCI_B_I2C_getInterruptStatus(uint16_t baseAddress,\r
233                                                uint16_t mask);\r
234 \r
235 extern void EUSCI_B_I2C_masterSendSingleByte(uint16_t baseAddress,\r
236                                              uint8_t txData);\r
237 \r
238 extern uint8_t EUSCI_B_I2C_masterReceiveSingleByte(uint16_t baseAddress);\r
239 \r
240 extern bool EUSCI_B_I2C_masterSendSingleByteWithTimeout(uint16_t baseAddress,\r
241                                                         uint8_t txData,\r
242                                                         uint32_t timeout);\r
243 \r
244 extern void EUSCI_B_I2C_masterMultiByteSendStart(uint16_t baseAddress,\r
245                                                  uint8_t txData);\r
246 \r
247 extern bool EUSCI_B_I2C_masterMultiByteSendStartWithTimeout(uint16_t baseAddress,\r
248                                                             uint8_t txData,\r
249                                                             uint32_t timeout);\r
250 \r
251 extern void EUSCI_B_I2C_masterMultiByteSendNext(uint16_t baseAddress,\r
252                                                 uint8_t txData);\r
253 \r
254 extern bool EUSCI_B_I2C_masterMultiByteSendNextWithTimeout(uint16_t baseAddress,\r
255                                                            uint8_t txData,\r
256                                                            uint32_t timeout);\r
257 \r
258 extern void EUSCI_B_I2C_masterMultiByteSendFinish(uint16_t baseAddress,\r
259                                                   uint8_t txData);\r
260 \r
261 extern bool EUSCI_B_I2C_masterMultiByteSendFinishWithTimeout(uint16_t baseAddress,\r
262                                                              uint8_t txData,\r
263                                                              uint32_t timeout);\r
264 \r
265 extern void EUSCI_B_I2C_masterSendStart(uint16_t baseAddress);\r
266 \r
267 extern void EUSCI_B_I2C_masterMultiByteSendStop(uint16_t baseAddress);\r
268 \r
269 extern bool EUSCI_B_I2C_masterMultiByteSendStopWithTimeout(uint16_t baseAddress,\r
270                                                            uint32_t timeout);\r
271 \r
272 extern void EUSCI_B_I2C_masterReceiveStart(uint16_t baseAddress);\r
273 \r
274 extern uint8_t EUSCI_B_I2C_masterMultiByteReceiveNext(uint16_t baseAddress);\r
275 \r
276 extern uint8_t EUSCI_B_I2C_masterMultiByteReceiveFinish(uint16_t baseAddress);\r
277 \r
278 extern bool EUSCI_B_I2C_masterMultiByteReceiveFinishWithTimeout(uint16_t baseAddress,\r
279                                                                 uint8_t *txData,\r
280                                                                 uint32_t timeout);\r
281 \r
282 extern void EUSCI_B_I2C_masterMultiByteReceiveStop(uint16_t baseAddress);\r
283 \r
284 extern void EUSCI_B_I2C_enableMultiMasterMode(uint16_t baseAddress);\r
285 \r
286 extern void EUSCI_B_I2C_disableMultiMasterMode(uint16_t baseAddress);\r
287 \r
288 extern uint8_t EUSCI_B_I2C_masterSingleReceive(uint16_t baseAddress);\r
289 \r
290 extern uint32_t EUSCI_B_I2C_getReceiveBufferAddress(uint16_t baseAddress);\r
291 \r
292 extern uint32_t EUSCI_B_I2C_getTransmitBufferAddress(uint16_t baseAddress);\r
293 \r
294 //*****************************************************************************\r
295 //\r
296 // The following are deprecated APIs.\r
297 //\r
298 //*****************************************************************************\r
299 #define EUSCI_B_I2C_getTransmitBufferAddressForDMA                            \\r
300         EUSCI_B_I2C_getTransmitBufferAddress\r
301 \r
302 //*****************************************************************************\r
303 //\r
304 // The following are deprecated APIs.\r
305 //\r
306 //*****************************************************************************\r
307 #define EUSCI_B_I2C_getReceiveBufferAddressForDMA                             \\r
308         EUSCI_B_I2C_getReceiveBufferAddress\r
309 \r
310 //*****************************************************************************\r
311 //\r
312 // The following are deprecated APIs.\r
313 //\r
314 //*****************************************************************************\r
315 #define EUSCI_B_I2C_masterIsSTOPSent               EUSCI_B_I2C_masterIsStopSent\r
316 \r
317 //*****************************************************************************\r
318 //\r
319 // The following are deprecated APIs.\r
320 //\r
321 //*****************************************************************************\r
322 extern void EUSCI_B_I2C_masterInit(uint16_t baseAddress,\r
323                                    uint8_t selectClockSource,\r
324                                    uint32_t i2cClk,\r
325                                    uint32_t dataRate,\r
326                                    uint8_t byteCounterThreshold,\r
327                                    uint8_t autoSTOPGeneration);\r
328 \r
329 extern void EUSCI_B_I2C_slaveInit(uint16_t baseAddress,\r
330                                   uint8_t slaveAddress,\r
331                                   uint8_t slaveAddressOffset,\r
332                                   uint32_t slaveOwnAddressEnable);\r
333 \r
334 //*****************************************************************************\r
335 //\r
336 // Mark the end of the C bindings section for C++ compilers.\r
337 //\r
338 //*****************************************************************************\r
339 #ifdef __cplusplus\r
340 }\r
341 #endif\r
342 \r
343 #endif\r
344 #endif // __MSP430WARE_EUSCI_B_I2C_H__\r