2 * Copyright (c) 2014, Texas Instruments Incorporated
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
9 * * Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\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
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
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
32 //*****************************************************************************
\r
34 // eusci_b_i2c.h - Driver for the EUSCI_B_I2C Module.
\r
36 //*****************************************************************************
\r
38 #ifndef __MSP430WARE_EUSCI_B_I2C_H__
\r
39 #define __MSP430WARE_EUSCI_B_I2C_H__
\r
41 #include "inc/hw_memmap.h"
\r
43 #ifdef __MSP430_HAS_EUSCI_Bx__
\r
45 //*****************************************************************************
\r
47 // If building with a C++ compiler, make all of the definitions in this header
\r
48 // have a C binding.
\r
50 //*****************************************************************************
\r
56 #include "inc/hw_regaccess.h"
\r
57 //*****************************************************************************
\r
59 //! \brief Used in the EUSCI_B_I2C_initMaster() function as the param
\r
62 //*****************************************************************************
\r
63 typedef struct EUSCI_B_I2C_initMasterParam
\r
65 //! Is the clocksource.
\r
66 //! \n Valid values are:
\r
67 //! - \b EUSCI_B_I2C_CLOCKSOURCE_ACLK
\r
68 //! - \b EUSCI_B_I2C_CLOCKSOURCE_SMCLK
\r
69 uint8_t selectClockSource;
\r
70 //! Is the rate of the clock supplied to the I2C module (the frequency in
\r
71 //! Hz of the clock source specified in selectClockSource).
\r
73 //! Setup for selecting data transfer rate.
\r
74 //! \n Valid values are:
\r
75 //! - \b EUSCI_B_I2C_SET_DATA_RATE_400KBPS
\r
76 //! - \b EUSCI_B_I2C_SET_DATA_RATE_100KBPS
\r
78 //! Sets threshold for automatic STOP or UCSTPIFG
\r
79 uint8_t byteCounterThreshold;
\r
80 //! Sets up the STOP condition generation.
\r
81 //! \n Valid values are:
\r
82 //! - \b EUSCI_B_I2C_NO_AUTO_STOP
\r
83 //! - \b EUSCI_B_I2C_SET_BYTECOUNT_THRESHOLD_FLAG
\r
84 //! - \b EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD
\r
85 uint8_t autoSTOPGeneration;
\r
86 } EUSCI_B_I2C_initMasterParam;
\r
88 //*****************************************************************************
\r
90 //! \brief Used in the EUSCI_B_I2C_initSlave() function as the param parameter.
\r
92 //*****************************************************************************
\r
93 typedef struct EUSCI_B_I2C_initSlaveParam
\r
95 //! 7-bit slave address
\r
96 uint8_t slaveAddress;
\r
97 //! Own address Offset referred to- 'x' value of UCBxI2COAx.
\r
98 //! \n Valid values are:
\r
99 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET0
\r
100 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET1
\r
101 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET2
\r
102 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET3
\r
103 uint8_t slaveAddressOffset;
\r
104 //! Selects if the specified address is enabled or disabled.
\r
105 //! \n Valid values are:
\r
106 //! - \b EUSCI_B_I2C_OWN_ADDRESS_DISABLE
\r
107 //! - \b EUSCI_B_I2C_OWN_ADDRESS_ENABLE
\r
108 uint32_t slaveOwnAddressEnable;
\r
109 } EUSCI_B_I2C_initSlaveParam;
\r
111 //*****************************************************************************
\r
113 // The following are values that can be passed to the param parameter for
\r
114 // functions: EUSCI_B_I2C_initMaster().
\r
116 //*****************************************************************************
\r
117 #define EUSCI_B_I2C_NO_AUTO_STOP UCASTP_0
\r
118 #define EUSCI_B_I2C_SET_BYTECOUNT_THRESHOLD_FLAG UCASTP_1
\r
119 #define EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD UCASTP_2
\r
121 //*****************************************************************************
\r
123 // The following are values that can be passed to the param parameter for
\r
124 // functions: EUSCI_B_I2C_initMaster().
\r
126 //*****************************************************************************
\r
127 #define EUSCI_B_I2C_SET_DATA_RATE_400KBPS 400000
\r
128 #define EUSCI_B_I2C_SET_DATA_RATE_100KBPS 100000
\r
130 //*****************************************************************************
\r
132 // The following are values that can be passed to the param parameter for
\r
133 // functions: EUSCI_B_I2C_initMaster().
\r
135 //*****************************************************************************
\r
136 #define EUSCI_B_I2C_CLOCKSOURCE_ACLK UCSSEL__ACLK
\r
137 #define EUSCI_B_I2C_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
\r
139 //*****************************************************************************
\r
141 // The following are values that can be passed to the param parameter for
\r
142 // functions: EUSCI_B_I2C_initSlave().
\r
144 //*****************************************************************************
\r
145 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET0 0x00
\r
146 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET1 0x02
\r
147 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET2 0x04
\r
148 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET3 0x06
\r
150 //*****************************************************************************
\r
152 // The following are values that can be passed to the param parameter for
\r
153 // functions: EUSCI_B_I2C_initSlave().
\r
155 //*****************************************************************************
\r
156 #define EUSCI_B_I2C_OWN_ADDRESS_DISABLE 0x00
\r
157 #define EUSCI_B_I2C_OWN_ADDRESS_ENABLE UCOAEN
\r
159 //*****************************************************************************
\r
161 // The following are values that can be passed to the mode parameter for
\r
162 // functions: EUSCI_B_I2C_setMode() as well as returned by the
\r
163 // EUSCI_B_I2C_getMode() function.
\r
165 //*****************************************************************************
\r
166 #define EUSCI_B_I2C_TRANSMIT_MODE UCTR
\r
167 #define EUSCI_B_I2C_RECEIVE_MODE 0x00
\r
169 //*****************************************************************************
\r
171 // The following are values that can be passed to the mask parameter for
\r
172 // functions: EUSCI_B_I2C_enableInterrupt(), EUSCI_B_I2C_disableInterrupt(),
\r
173 // EUSCI_B_I2C_clearInterrupt(), and EUSCI_B_I2C_getInterruptStatus() as well
\r
174 // as returned by the EUSCI_B_I2C_getInterruptStatus() function.
\r
176 //*****************************************************************************
\r
177 #define EUSCI_B_I2C_NAK_INTERRUPT UCNACKIE
\r
178 #define EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT UCALIE
\r
179 #define EUSCI_B_I2C_STOP_INTERRUPT UCSTPIE
\r
180 #define EUSCI_B_I2C_START_INTERRUPT UCSTTIE
\r
181 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT0 UCTXIE0
\r
182 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT1 UCTXIE1
\r
183 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT2 UCTXIE2
\r
184 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT3 UCTXIE3
\r
185 #define EUSCI_B_I2C_RECEIVE_INTERRUPT0 UCRXIE0
\r
186 #define EUSCI_B_I2C_RECEIVE_INTERRUPT1 UCRXIE1
\r
187 #define EUSCI_B_I2C_RECEIVE_INTERRUPT2 UCRXIE2
\r
188 #define EUSCI_B_I2C_RECEIVE_INTERRUPT3 UCRXIE3
\r
189 #define EUSCI_B_I2C_BIT9_POSITION_INTERRUPT UCBIT9IE
\r
190 #define EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT UCCLTOIE
\r
191 #define EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT UCBCNTIE
\r
193 //*****************************************************************************
\r
195 // The following are values that can be passed toThe following are values that
\r
196 // can be returned by the EUSCI_B_I2C_isBusBusy() function.
\r
198 //*****************************************************************************
\r
199 #define EUSCI_B_I2C_BUS_BUSY UCBBUSY
\r
200 #define EUSCI_B_I2C_BUS_NOT_BUSY 0x00
\r
202 //*****************************************************************************
\r
204 // The following are values that can be passed toThe following are values that
\r
205 // can be returned by the EUSCI_B_I2C_masterIsStopSent() function.
\r
207 //*****************************************************************************
\r
208 #define EUSCI_B_I2C_STOP_SEND_COMPLETE 0x00
\r
209 #define EUSCI_B_I2C_SENDING_STOP UCTXSTP
\r
211 //*****************************************************************************
\r
213 // The following are values that can be passed toThe following are values that
\r
214 // can be returned by the EUSCI_B_I2C_masterIsStartSent() function.
\r
216 //*****************************************************************************
\r
217 #define EUSCI_B_I2C_START_SEND_COMPLETE 0x00
\r
218 #define EUSCI_B_I2C_SENDING_START UCTXSTT
\r
220 //*****************************************************************************
\r
222 // Prototypes for the APIs.
\r
224 //*****************************************************************************
\r
226 //*****************************************************************************
\r
228 //! \brief Initializes the I2C Master block.
\r
230 //! This function initializes operation of the I2C Master block. Upon
\r
231 //! successful initialization of the I2C block, this function will have set the
\r
232 //! bus speed for the master; however I2C module is still disabled till
\r
233 //! EUSCI_B_I2C_enable is invoked.
\r
235 //! \param baseAddress is the base address of the I2C Master module.
\r
236 //! \param param is the pointer to the struct for master initialization.
\r
240 //*****************************************************************************
\r
241 extern void EUSCI_B_I2C_initMaster(uint16_t baseAddress,
\r
242 EUSCI_B_I2C_initMasterParam *param);
\r
244 //*****************************************************************************
\r
246 //! \brief Initializes the I2C Slave block.
\r
248 //! This function initializes operation of the I2C as a Slave mode. Upon
\r
249 //! successful initialization of the I2C blocks, this function will have set
\r
250 //! the slave address but the I2C module is still disabled till
\r
251 //! EUSCI_B_I2C_enable is invoked.
\r
253 //! \param baseAddress is the base address of the I2C Slave module.
\r
254 //! \param param is the pointer to the struct for slave initialization.
\r
258 //*****************************************************************************
\r
259 extern void EUSCI_B_I2C_initSlave(uint16_t baseAddress,
\r
260 EUSCI_B_I2C_initSlaveParam *param);
\r
262 //*****************************************************************************
\r
264 //! \brief Enables the I2C block.
\r
266 //! This will enable operation of the I2C block.
\r
268 //! \param baseAddress is the base address of the USCI I2C module.
\r
270 //! Modified bits are \b UCSWRST of \b UCBxCTLW0 register.
\r
274 //*****************************************************************************
\r
275 extern void EUSCI_B_I2C_enable(uint16_t baseAddress);
\r
277 //*****************************************************************************
\r
279 //! \brief Disables the I2C block.
\r
281 //! This will disable operation of the I2C block.
\r
283 //! \param baseAddress is the base address of the USCI I2C module.
\r
285 //! Modified bits are \b UCSWRST of \b UCBxCTLW0 register.
\r
289 //*****************************************************************************
\r
290 extern void EUSCI_B_I2C_disable(uint16_t baseAddress);
\r
292 //*****************************************************************************
\r
294 //! \brief Sets the address that the I2C Master will place on the bus.
\r
296 //! This function will set the address that the I2C Master will place on the
\r
297 //! bus when initiating a transaction.
\r
299 //! \param baseAddress is the base address of the USCI I2C module.
\r
300 //! \param slaveAddress 7-bit slave address
\r
302 //! Modified bits of \b UCBxI2CSA register.
\r
306 //*****************************************************************************
\r
307 extern void EUSCI_B_I2C_setSlaveAddress(uint16_t baseAddress,
\r
308 uint8_t slaveAddress);
\r
310 //*****************************************************************************
\r
312 //! \brief Sets the mode of the I2C device
\r
314 //! When the receive parameter is set to EUSCI_B_I2C_TRANSMIT_MODE, the address
\r
315 //! will indicate that the I2C module is in receive mode; otherwise, the I2C
\r
316 //! module is in send mode.
\r
318 //! \param baseAddress is the base address of the USCI I2C module.
\r
319 //! \param mode Mode for the EUSCI_B_I2C module
\r
320 //! Valid values are:
\r
321 //! - \b EUSCI_B_I2C_TRANSMIT_MODE [Default]
\r
322 //! - \b EUSCI_B_I2C_RECEIVE_MODE
\r
324 //! Modified bits are \b UCTR of \b UCBxCTLW0 register.
\r
328 //*****************************************************************************
\r
329 extern void EUSCI_B_I2C_setMode(uint16_t baseAddress,
\r
332 //*****************************************************************************
\r
334 //! \brief Gets the mode of the I2C device
\r
336 //! Current I2C transmit/receive mode.
\r
338 //! \param baseAddress is the base address of the I2C module.
\r
340 //! Modified bits are \b UCTR of \b UCBxCTLW0 register.
\r
342 //! \return One of the following:
\r
343 //! - \b EUSCI_B_I2C_TRANSMIT_MODE
\r
344 //! - \b EUSCI_B_I2C_RECEIVE_MODE
\r
345 //! \n indicating the current mode
\r
347 //*****************************************************************************
\r
348 extern uint8_t EUSCI_B_I2C_getMode(uint16_t baseAddress);
\r
350 //*****************************************************************************
\r
352 //! \brief Transmits a byte from the I2C Module.
\r
354 //! This function will place the supplied data into I2C transmit data register
\r
355 //! to start transmission.
\r
357 //! \param baseAddress is the base address of the I2C Slave module.
\r
358 //! \param transmitData data to be transmitted from the I2C module
\r
360 //! Modified bits of \b UCBxTXBUF register.
\r
364 //*****************************************************************************
\r
365 extern void EUSCI_B_I2C_slavePutData(uint16_t baseAddress,
\r
366 uint8_t transmitData);
\r
368 //*****************************************************************************
\r
370 //! \brief Receives a byte that has been sent to the I2C Module.
\r
372 //! This function reads a byte of data from the I2C receive data Register.
\r
374 //! \param baseAddress is the base address of the I2C Slave module.
\r
376 //! \return Returns the byte received from by the I2C module, cast as an
\r
379 //*****************************************************************************
\r
380 extern uint8_t EUSCI_B_I2C_slaveGetData(uint16_t baseAddress);
\r
382 //*****************************************************************************
\r
384 //! \brief Indicates whether or not the I2C bus is busy.
\r
386 //! This function returns an indication of whether or not the I2C bus is busy.
\r
387 //! This function checks the status of the bus via UCBBUSY bit in UCBxSTAT
\r
390 //! \param baseAddress is the base address of the I2C module.
\r
392 //! \return One of the following:
\r
393 //! - \b EUSCI_B_I2C_BUS_BUSY
\r
394 //! - \b EUSCI_B_I2C_BUS_NOT_BUSY
\r
395 //! \n indicating whether the bus is busy
\r
397 //*****************************************************************************
\r
398 extern uint16_t EUSCI_B_I2C_isBusBusy(uint16_t baseAddress);
\r
400 //*****************************************************************************
\r
402 //! \brief Indicates whether STOP got sent.
\r
404 //! This function returns an indication of whether or not STOP got sent This
\r
405 //! function checks the status of the bus via UCTXSTP bit in UCBxCTL1 register.
\r
407 //! \param baseAddress is the base address of the I2C Master module.
\r
409 //! \return One of the following:
\r
410 //! - \b EUSCI_B_I2C_STOP_SEND_COMPLETE
\r
411 //! - \b EUSCI_B_I2C_SENDING_STOP
\r
412 //! \n indicating whether the stop was sent
\r
414 //*****************************************************************************
\r
415 extern uint16_t EUSCI_B_I2C_masterIsStopSent(uint16_t baseAddress);
\r
417 //*****************************************************************************
\r
419 //! \brief Indicates whether Start got sent.
\r
421 //! This function returns an indication of whether or not Start got sent This
\r
422 //! function checks the status of the bus via UCTXSTT bit in UCBxCTL1 register.
\r
424 //! \param baseAddress is the base address of the I2C Master module.
\r
426 //! \return One of the following:
\r
427 //! - \b EUSCI_B_I2C_START_SEND_COMPLETE
\r
428 //! - \b EUSCI_B_I2C_SENDING_START
\r
429 //! \n indicating whether the start was sent
\r
431 //*****************************************************************************
\r
432 extern uint16_t EUSCI_B_I2C_masterIsStartSent(uint16_t baseAddress);
\r
434 //*****************************************************************************
\r
436 //! \brief Enables individual I2C interrupt sources.
\r
438 //! Enables the indicated I2C interrupt sources. Only the sources that are
\r
439 //! enabled can be reflected to the processor interrupt; disabled sources have
\r
440 //! no effect on the processor.
\r
442 //! \param baseAddress is the base address of the I2C module.
\r
443 //! \param mask is the bit mask of the interrupt sources to be enabled.
\r
444 //! Mask value is the logical OR of any of the following:
\r
445 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
\r
446 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
\r
448 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
\r
449 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt
\r
450 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0
\r
451 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1
\r
452 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2
\r
453 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3
\r
454 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0
\r
455 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1
\r
456 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2
\r
457 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3
\r
458 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt
\r
459 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout
\r
460 //! interrupt enable
\r
461 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt
\r
464 //! Modified bits of \b UCBxIE register.
\r
468 //*****************************************************************************
\r
469 extern void EUSCI_B_I2C_enableInterrupt(uint16_t baseAddress,
\r
472 //*****************************************************************************
\r
474 //! \brief Disables individual I2C interrupt sources.
\r
476 //! Disables the indicated I2C interrupt sources. Only the sources that are
\r
477 //! enabled can be reflected to the processor interrupt; disabled sources have
\r
478 //! no effect on the processor.
\r
480 //! \param baseAddress is the base address of the I2C module.
\r
481 //! \param mask is the bit mask of the interrupt sources to be disabled.
\r
482 //! Mask value is the logical OR of any of the following:
\r
483 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
\r
484 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
\r
486 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
\r
487 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt
\r
488 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0
\r
489 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1
\r
490 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2
\r
491 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3
\r
492 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0
\r
493 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1
\r
494 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2
\r
495 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3
\r
496 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt
\r
497 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout
\r
498 //! interrupt enable
\r
499 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt
\r
502 //! Modified bits of \b UCBxIE register.
\r
506 //*****************************************************************************
\r
507 extern void EUSCI_B_I2C_disableInterrupt(uint16_t baseAddress,
\r
510 //*****************************************************************************
\r
512 //! \brief Clears I2C interrupt sources.
\r
514 //! The I2C interrupt source is cleared, so that it no longer asserts. The
\r
515 //! highest interrupt flag is automatically cleared when an interrupt vector
\r
516 //! generator is used.
\r
518 //! \param baseAddress is the base address of the I2C module.
\r
519 //! \param mask is a bit mask of the interrupt sources to be cleared.
\r
520 //! Mask value is the logical OR of any of the following:
\r
521 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
\r
522 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
\r
524 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
\r
525 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt
\r
526 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0
\r
527 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1
\r
528 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2
\r
529 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3
\r
530 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0
\r
531 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1
\r
532 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2
\r
533 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3
\r
534 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt
\r
535 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout
\r
536 //! interrupt enable
\r
537 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt
\r
540 //! Modified bits of \b UCBxIFG register.
\r
544 //*****************************************************************************
\r
545 extern void EUSCI_B_I2C_clearInterrupt(uint16_t baseAddress,
\r
548 //*****************************************************************************
\r
550 //! \brief Gets the current I2C interrupt status.
\r
552 //! This returns the interrupt status for the I2C module based on which flag is
\r
555 //! \param baseAddress is the base address of the I2C module.
\r
556 //! \param mask is the masked interrupt flag status to be returned.
\r
557 //! Mask value is the logical OR of any of the following:
\r
558 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
\r
559 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
\r
561 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
\r
562 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt
\r
563 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0
\r
564 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1
\r
565 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2
\r
566 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3
\r
567 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0
\r
568 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1
\r
569 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2
\r
570 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3
\r
571 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt
\r
572 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout
\r
573 //! interrupt enable
\r
574 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt
\r
577 //! \return Logical OR of any of the following:
\r
578 //! - \b EUSCI_B_I2C_NAK_INTERRUPT Not-acknowledge interrupt
\r
579 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT Arbitration lost
\r
581 //! - \b EUSCI_B_I2C_STOP_INTERRUPT STOP condition interrupt
\r
582 //! - \b EUSCI_B_I2C_START_INTERRUPT START condition interrupt
\r
583 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 Transmit interrupt0
\r
584 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 Transmit interrupt1
\r
585 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 Transmit interrupt2
\r
586 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 Transmit interrupt3
\r
587 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 Receive interrupt0
\r
588 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 Receive interrupt1
\r
589 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 Receive interrupt2
\r
590 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 Receive interrupt3
\r
591 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT Bit position 9 interrupt
\r
592 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT Clock low timeout
\r
593 //! interrupt enable
\r
594 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT Byte counter interrupt
\r
596 //! \n indicating the status of the masked interrupts
\r
598 //*****************************************************************************
\r
599 extern uint16_t EUSCI_B_I2C_getInterruptStatus(uint16_t baseAddress,
\r
602 //*****************************************************************************
\r
604 //! \brief Does single byte transmission from Master to Slave
\r
606 //! This function is used by the Master module to send a single byte. This
\r
607 //! function sends a start, then transmits the byte to the slave and then sends
\r
610 //! \param baseAddress is the base address of the I2C Master module.
\r
611 //! \param txData is the data byte to be transmitted
\r
613 //! Modified bits of \b UCBxTXBUF register, bits of \b UCBxCTLW0 register, bits
\r
614 //! of \b UCBxIE register and bits of \b UCBxIFG register.
\r
618 //*****************************************************************************
\r
619 extern void EUSCI_B_I2C_masterSendSingleByte(uint16_t baseAddress,
\r
622 //*****************************************************************************
\r
624 //! \brief Does single byte reception from Slave
\r
626 //! This function is used by the Master module to receive a single byte. This
\r
627 //! function sends start and stop, waits for data reception and then receives
\r
628 //! the data from the slave
\r
630 //! \param baseAddress is the base address of the I2C Master module.
\r
632 //! Modified bits of \b UCBxTXBUF register, bits of \b UCBxCTLW0 register, bits
\r
633 //! of \b UCBxIE register and bits of \b UCBxIFG register.
\r
635 //! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
\r
637 //*****************************************************************************
\r
638 extern uint8_t EUSCI_B_I2C_masterReceiveSingleByte(uint16_t baseAddress);
\r
640 //*****************************************************************************
\r
642 //! \brief Does single byte transmission from Master to Slave with timeout
\r
644 //! This function is used by the Master module to send a single byte. This
\r
645 //! function sends a start, then transmits the byte to the slave and then sends
\r
648 //! \param baseAddress is the base address of the I2C Master module.
\r
649 //! \param txData is the data byte to be transmitted
\r
650 //! \param timeout is the amount of time to wait until giving up
\r
652 //! Modified bits of \b UCBxTXBUF register, bits of \b UCBxCTLW0 register, bits
\r
653 //! of \b UCBxIE register and bits of \b UCBxIFG register.
\r
655 //! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
\r
657 //*****************************************************************************
\r
658 extern bool EUSCI_B_I2C_masterSendSingleByteWithTimeout(uint16_t baseAddress,
\r
662 //*****************************************************************************
\r
664 //! \brief Starts multi-byte transmission from Master to Slave
\r
666 //! This function is used by the master module to start a multi byte
\r
669 //! \param baseAddress is the base address of the I2C Master module.
\r
670 //! \param txData is the first data byte to be transmitted
\r
672 //! Modified bits of \b UCBxTXBUF register, bits of \b UCBxCTLW0 register, bits
\r
673 //! of \b UCBxIE register and bits of \b UCBxIFG register.
\r
677 //*****************************************************************************
\r
678 extern void EUSCI_B_I2C_masterSendMultiByteStart(uint16_t baseAddress,
\r
681 //*****************************************************************************
\r
683 //! \brief Starts multi-byte transmission from Master to Slave with timeout
\r
685 //! This function is used by the master module to start a multi byte
\r
688 //! \param baseAddress is the base address of the I2C Master module.
\r
689 //! \param txData is the first data byte to be transmitted
\r
690 //! \param timeout is the amount of time to wait until giving up
\r
692 //! Modified bits of \b UCBxTXBUF register, bits of \b UCBxCTLW0 register, bits
\r
693 //! of \b UCBxIE register and bits of \b UCBxIFG register.
\r
695 //! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
\r
697 //*****************************************************************************
\r
698 extern bool EUSCI_B_I2C_masterSendMultiByteStartWithTimeout(
\r
699 uint16_t baseAddress,
\r
703 //*****************************************************************************
\r
705 //! \brief Continues multi-byte transmission from Master to Slave
\r
707 //! This function is used by the Master module continue each byte of a multi-
\r
708 //! byte transmission. This function transmits each data byte of a multi-byte
\r
709 //! transmission to the slave.
\r
711 //! \param baseAddress is the base address of the I2C Master module.
\r
712 //! \param txData is the next data byte to be transmitted
\r
714 //! Modified bits of \b UCBxTXBUF register.
\r
718 //*****************************************************************************
\r
719 extern void EUSCI_B_I2C_masterSendMultiByteNext(uint16_t baseAddress,
\r
722 //*****************************************************************************
\r
724 //! \brief Continues multi-byte transmission from Master to Slave with timeout
\r
726 //! This function is used by the Master module continue each byte of a multi-
\r
727 //! byte transmission. This function transmits each data byte of a multi-byte
\r
728 //! transmission to the slave.
\r
730 //! \param baseAddress is the base address of the I2C Master module.
\r
731 //! \param txData is the next data byte to be transmitted
\r
732 //! \param timeout is the amount of time to wait until giving up
\r
734 //! Modified bits of \b UCBxTXBUF register.
\r
736 //! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
\r
738 //*****************************************************************************
\r
739 extern bool EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(uint16_t baseAddress,
\r
743 //*****************************************************************************
\r
745 //! \brief Finishes multi-byte transmission from Master to Slave
\r
747 //! This function is used by the Master module to send the last byte and STOP.
\r
748 //! This function transmits the last data byte of a multi-byte transmission to
\r
749 //! the slave and then sends a stop.
\r
751 //! \param baseAddress is the base address of the I2C Master module.
\r
752 //! \param txData is the last data byte to be transmitted in a multi-byte
\r
755 //! Modified bits of \b UCBxTXBUF register and bits of \b UCBxCTLW0 register.
\r
759 //*****************************************************************************
\r
760 extern void EUSCI_B_I2C_masterSendMultiByteFinish(uint16_t baseAddress,
\r
763 //*****************************************************************************
\r
765 //! \brief Finishes multi-byte transmission from Master to Slave with timeout
\r
767 //! This function is used by the Master module to send the last byte and STOP.
\r
768 //! This function transmits the last data byte of a multi-byte transmission to
\r
769 //! the slave and then sends a stop.
\r
771 //! \param baseAddress is the base address of the I2C Master module.
\r
772 //! \param txData is the last data byte to be transmitted in a multi-byte
\r
774 //! \param timeout is the amount of time to wait until giving up
\r
776 //! Modified bits of \b UCBxTXBUF register and bits of \b UCBxCTLW0 register.
\r
778 //! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
\r
780 //*****************************************************************************
\r
781 extern bool EUSCI_B_I2C_masterSendMultiByteFinishWithTimeout(
\r
782 uint16_t baseAddress,
\r
786 //*****************************************************************************
\r
788 //! \brief This function is used by the Master module to initiate START
\r
790 //! This function is used by the Master module to initiate START
\r
792 //! \param baseAddress is the base address of the I2C Master module.
\r
794 //! Modified bits are \b UCTXSTT of \b UCBxCTLW0 register.
\r
798 //*****************************************************************************
\r
799 extern void EUSCI_B_I2C_masterSendStart(uint16_t baseAddress);
\r
801 //*****************************************************************************
\r
803 //! \brief Send STOP byte at the end of a multi-byte transmission from Master
\r
806 //! This function is used by the Master module send STOP at the end of a multi-
\r
807 //! byte transmission. This function sends a stop after current transmission is
\r
810 //! \param baseAddress is the base address of the I2C Master module.
\r
812 //! Modified bits are \b UCTXSTP of \b UCBxCTLW0 register.
\r
816 //*****************************************************************************
\r
817 extern void EUSCI_B_I2C_masterSendMultiByteStop(uint16_t baseAddress);
\r
819 //*****************************************************************************
\r
821 //! \brief Send STOP byte at the end of a multi-byte transmission from Master
\r
822 //! to Slave with timeout
\r
824 //! This function is used by the Master module send STOP at the end of a multi-
\r
825 //! byte transmission. This function sends a stop after current transmission is
\r
828 //! \param baseAddress is the base address of the I2C Master module.
\r
829 //! \param timeout is the amount of time to wait until giving up
\r
831 //! Modified bits are \b UCTXSTP of \b UCBxCTLW0 register.
\r
833 //! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
\r
835 //*****************************************************************************
\r
836 extern bool EUSCI_B_I2C_masterSendMultiByteStopWithTimeout(uint16_t baseAddress,
\r
839 //*****************************************************************************
\r
841 //! \brief Starts reception at the Master end
\r
843 //! This function is used by the Master module initiate reception of a single
\r
844 //! byte. This function sends a start.
\r
846 //! \param baseAddress is the base address of the I2C Master module.
\r
848 //! Modified bits are \b UCTXSTT of \b UCBxCTLW0 register.
\r
852 //*****************************************************************************
\r
853 extern void EUSCI_B_I2C_masterReceiveStart(uint16_t baseAddress);
\r
855 //*****************************************************************************
\r
857 //! \brief Starts multi-byte reception at the Master end one byte at a time
\r
859 //! This function is used by the Master module to receive each byte of a multi-
\r
860 //! byte reception. This function reads currently received byte.
\r
862 //! \param baseAddress is the base address of the I2C Master module.
\r
864 //! \return Received byte at Master end.
\r
866 //*****************************************************************************
\r
867 extern uint8_t EUSCI_B_I2C_masterReceiveMultiByteNext(uint16_t baseAddress);
\r
869 //*****************************************************************************
\r
871 //! \brief Finishes multi-byte reception at the Master end
\r
873 //! This function is used by the Master module to initiate completion of a
\r
874 //! multi-byte reception. This function receives the current byte and initiates
\r
875 //! the STOP from master to slave.
\r
877 //! \param baseAddress is the base address of the I2C Master module.
\r
879 //! Modified bits are \b UCTXSTP of \b UCBxCTLW0 register.
\r
881 //! \return Received byte at Master end.
\r
883 //*****************************************************************************
\r
884 extern uint8_t EUSCI_B_I2C_masterReceiveMultiByteFinish(uint16_t baseAddress);
\r
886 //*****************************************************************************
\r
888 //! \brief Finishes multi-byte reception at the Master end with timeout
\r
890 //! This function is used by the Master module to initiate completion of a
\r
891 //! multi-byte reception. This function receives the current byte and initiates
\r
892 //! the STOP from master to slave.
\r
894 //! \param baseAddress is the base address of the I2C Master module.
\r
895 //! \param txData is a pointer to the location to store the received byte at
\r
897 //! \param timeout is the amount of time to wait until giving up
\r
899 //! Modified bits are \b UCTXSTP of \b UCBxCTLW0 register.
\r
901 //! \return STATUS_SUCCESS or STATUS_FAILURE of the reception process
\r
903 //*****************************************************************************
\r
904 extern bool EUSCI_B_I2C_masterReceiveMultiByteFinishWithTimeout(
\r
905 uint16_t baseAddress,
\r
909 //*****************************************************************************
\r
911 //! \brief Sends the STOP at the end of a multi-byte reception at the Master
\r
914 //! This function is used by the Master module to initiate STOP
\r
916 //! \param baseAddress is the base address of the I2C Master module.
\r
918 //! Modified bits are \b UCTXSTP of \b UCBxCTLW0 register.
\r
922 //*****************************************************************************
\r
923 extern void EUSCI_B_I2C_masterReceiveMultiByteStop(uint16_t baseAddress);
\r
925 //*****************************************************************************
\r
927 //! \brief Enables Multi Master Mode
\r
929 //! At the end of this function, the I2C module is still disabled till
\r
930 //! EUSCI_B_I2C_enable is invoked
\r
932 //! \param baseAddress is the base address of the I2C module.
\r
934 //! Modified bits are \b UCSWRST and \b UCMM of \b UCBxCTLW0 register.
\r
938 //*****************************************************************************
\r
939 extern void EUSCI_B_I2C_enableMultiMasterMode(uint16_t baseAddress);
\r
941 //*****************************************************************************
\r
943 //! \brief Disables Multi Master Mode
\r
945 //! At the end of this function, the I2C module is still disabled till
\r
946 //! EUSCI_B_I2C_enable is invoked
\r
948 //! \param baseAddress is the base address of the I2C module.
\r
950 //! Modified bits are \b UCSWRST and \b UCMM of \b UCBxCTLW0 register.
\r
954 //*****************************************************************************
\r
955 extern void EUSCI_B_I2C_disableMultiMasterMode(uint16_t baseAddress);
\r
957 //*****************************************************************************
\r
959 //! \brief receives a byte that has been sent to the I2C Master Module.
\r
961 //! This function reads a byte of data from the I2C receive data Register.
\r
963 //! \param baseAddress is the base address of the I2C Master module.
\r
965 //! \return Returns the byte received from by the I2C module, cast as an
\r
968 //*****************************************************************************
\r
969 extern uint8_t EUSCI_B_I2C_masterReceiveSingle(uint16_t baseAddress);
\r
971 //*****************************************************************************
\r
973 //! \brief Returns the address of the RX Buffer of the I2C for the DMA module.
\r
975 //! Returns the address of the I2C RX Buffer. This can be used in conjunction
\r
976 //! with the DMA to store the received data directly to memory.
\r
978 //! \param baseAddress is the base address of the I2C module.
\r
980 //! \return The address of the I2C RX Buffer
\r
982 //*****************************************************************************
\r
983 extern uint32_t EUSCI_B_I2C_getReceiveBufferAddress(uint16_t baseAddress);
\r
985 //*****************************************************************************
\r
987 //! \brief Returns the address of the TX Buffer of the I2C for the DMA module.
\r
989 //! Returns the address of the I2C TX Buffer. This can be used in conjunction
\r
990 //! with the DMA to obtain transmitted data directly from memory.
\r
992 //! \param baseAddress is the base address of the I2C module.
\r
994 //! \return The address of the I2C TX Buffer
\r
996 //*****************************************************************************
\r
997 extern uint32_t EUSCI_B_I2C_getTransmitBufferAddress(uint16_t baseAddress);
\r
999 //*****************************************************************************
\r
1001 // Mark the end of the C bindings section for C++ compilers.
\r
1003 //*****************************************************************************
\r
1004 #ifdef __cplusplus
\r
1009 #endif // __MSP430WARE_EUSCI_B_I2C_H__
\r