1 /* --COPYRIGHT--,BSD 2 * Copyright (c) 2017, Texas Instruments Incorporated 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of Texas Instruments Incorporated nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * --/COPYRIGHT--*/ 32 #ifndef I2C_H_ 33 #define I2C_H_ 34 35 //***************************************************************************** 36 // 37 //! \addtogroup i2c_api 38 //! @{ 39 // 40 //***************************************************************************** 41 42 //***************************************************************************** 43 // 44 // If building with a C++ compiler, make all of the definitions in this header 45 // have a C binding. 46 // 47 //***************************************************************************** 48 #ifdef __cplusplus 49 extern "C" 50 { 51 #endif 52 53 #include <stdint.h> 54 #include <stdbool.h> 55 #include <ti/devices/msp432p4xx/inc/msp.h> 56 #include <ti/devices/msp432p4xx/driverlib/eusci.h> 57 58 #define EUSCI_B_I2C_NO_AUTO_STOP EUSCI_B_CTLW1_ASTP_0 59 #define EUSCI_B_I2C_SET_BYTECOUNT_THRESHOLD_FLAG EUSCI_B_CTLW1_ASTP_1 60 #define EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD \ 61 EUSCI_B_CTLW1_ASTP_2 62 63 #define EUSCI_B_I2C_SET_DATA_RATE_1MBPS 1000000 64 #define EUSCI_B_I2C_SET_DATA_RATE_400KBPS 400000 65 #define EUSCI_B_I2C_SET_DATA_RATE_100KBPS 100000 66 67 #define EUSCI_B_I2C_CLOCKSOURCE_ACLK EUSCI_B_CTLW0_SSEL__ACLK 68 #define EUSCI_B_I2C_CLOCKSOURCE_SMCLK EUSCI_B_CTLW0_SSEL__SMCLK 69 70 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET0 0x00 71 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET1 0x02 72 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET2 0x04 73 #define EUSCI_B_I2C_OWN_ADDRESS_OFFSET3 0x06 74 75 #define EUSCI_B_I2C_OWN_ADDRESS_DISABLE 0x00 76 #define EUSCI_B_I2C_OWN_ADDRESS_ENABLE EUSCI_B_I2COA0_OAEN 77 78 #define EUSCI_B_I2C_TRANSMIT_MODE EUSCI_B_CTLW0_TR 79 #define EUSCI_B_I2C_RECEIVE_MODE 0x00 80 81 #define EUSCI_B_I2C_TIMEOUT_DISABLE EUSCI_B_CTLW1_CLTO_0 82 #define EUSCI_B_I2C_TIMEOUT_28_MS EUSCI_B_CTLW1_CLTO_1 83 #define EUSCI_B_I2C_TIMEOUT_31_MS EUSCI_B_CTLW1_CLTO_2 84 #define EUSCI_B_I2C_TIMEOUT_34_MS EUSCI_B_CTLW1_CLTO_3 85 86 #define EUSCI_B_I2C_NAK_INTERRUPT EUSCI_B_IE_NACKIE 87 #define EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT EUSCI_B_IE_ALIE 88 #define EUSCI_B_I2C_STOP_INTERRUPT EUSCI_B_IE_STPIE 89 #define EUSCI_B_I2C_START_INTERRUPT EUSCI_B_IE_STTIE 90 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT0 EUSCI_B_IE_TXIE0 91 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT1 EUSCI_B_IE_TXIE1 92 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT2 EUSCI_B_IE_TXIE2 93 #define EUSCI_B_I2C_TRANSMIT_INTERRUPT3 EUSCI_B_IE_TXIE3 94 #define EUSCI_B_I2C_RECEIVE_INTERRUPT0 EUSCI_B_IE_RXIE0 95 #define EUSCI_B_I2C_RECEIVE_INTERRUPT1 EUSCI_B_IE_RXIE1 96 #define EUSCI_B_I2C_RECEIVE_INTERRUPT2 EUSCI_B_IE_RXIE2 97 #define EUSCI_B_I2C_RECEIVE_INTERRUPT3 EUSCI_B_IE_RXIE3 98 #define EUSCI_B_I2C_BIT9_POSITION_INTERRUPT EUSCI_B_IE_BIT9IE 99 #define EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT EUSCI_B_IE_CLTOIE 100 #define EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT EUSCI_B_IE_BCNTIE 101 102 #define EUSCI_B_I2C_BUS_BUSY EUSCI_B_STATW_BBUSY 103 #define EUSCI_B_I2C_BUS_NOT_BUSY 0x00 104 105 #define EUSCI_B_I2C_STOP_SEND_COMPLETE 0x00 106 #define EUSCI_B_I2C_SENDING_STOP EUSCI_B_CTLW0_TXSTP 107 108 #define EUSCI_B_I2C_START_SEND_COMPLETE 0x00 109 #define EUSCI_B_I2C_SENDING_START EUSCI_B_CTLW0_TXSTT 110 111 //***************************************************************************** 112 // 113 //! ypedef eUSCI_I2C_MasterConfig 114 //! \brief Type definition for \link _eUSCI_I2C_MasterConfig \endlink structure 115 //! 116 //! \struct _eUSCI_I2C_MasterConfig 117 //! \brief Configuration structure for master mode in the \b I2C module. See 118 //! \link I2C_initMaster \endlink for parameter documentation. 119 // 120 //***************************************************************************** 121 typedef struct 122 { 123 uint_fast8_t selectClockSource; 124 uint32_t i2cClk; 125 uint32_t dataRate; 126 uint_fast8_t byteCounterThreshold; 127 uint_fast8_t autoSTOPGeneration; 128 } eUSCI_I2C_MasterConfig; 129 130 131 //***************************************************************************** 132 // 133 //! Initializes the I2C Master block. 134 //! 135 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 136 //! parameters vary from part to part, but can include: 137 //! - \b EUSCI_B0_BASE 138 //! - \b EUSCI_B1_BASE 139 //! - \b EUSCI_B2_BASE 140 //! - \b EUSCI_B3_BASE 141 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 142 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 143 //! I2C mode. 144 //! \param config Configuration structure for I2C master mode 145 //! 146 //! <hr> 147 //! <b>Configuration options for \link eUSCI_I2C_MasterConfig \endlink structure.</b> 148 //! <hr> 149 //! 150 //! \param selectClockSource is the clock source. 151 //! Valid values are 152 //! - \b EUSCI_B_I2C_CLOCKSOURCE_ACLK 153 //! - \b EUSCI_B_I2C_CLOCKSOURCE_SMCLK 154 //! \param i2cClk is the rate of the clock supplied to the I2C module 155 //! (the frequency in Hz of the clock source specified in 156 //! selectClockSource). 157 //! \param dataRate set up for selecting data transfer rate. 158 //! Valid values are 159 //! - \b EUSCI_B_I2C_SET_DATA_RATE_1MBPS 160 //! - \b EUSCI_B_I2C_SET_DATA_RATE_400KBPS 161 //! - \b EUSCI_B_I2C_SET_DATA_RATE_100KBPS 162 //! \param byteCounterThreshold sets threshold for automatic STOP or UCSTPIFG 163 //! \param autoSTOPGeneration sets up the STOP condition generation. 164 //! Valid values are 165 //! - \b EUSCI_B_I2C_NO_AUTO_STOP 166 //! - \b EUSCI_B_I2C_SET_BYTECOUNT_THRESHOLD_FLAG 167 //! - \b EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD 168 //! 169 //! This function initializes operation of the I2C Master block. Upon 170 //! successful initialization of the I2C block, this function will have set the 171 //! bus speed for the master; however I2C module is still disabled till 172 //! I2C_enableModule is invoked 173 //! 174 //! Modified bits are \b UCMST,UCMODE_3,\b UCSYNC of \b UCBxCTL0 register 175 //! \b UCSSELx, \b UCSWRST, of \b UCBxCTL1 register 176 //! \b UCBxBR0 and \b UCBxBR1 registers 177 //! \return None. 178 // 179 //***************************************************************************** 180 extern void I2C_initMaster(uint32_t moduleInstance, 181 const eUSCI_I2C_MasterConfig *config); 182 183 //***************************************************************************** 184 // 185 //! Initializes the I2C Slave block. 186 //! 187 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 188 //! parameters vary from part to part, but can include: 189 //! - \b EUSCI_B0_BASE 190 //! - \b EUSCI_B1_BASE 191 //! - \b EUSCI_B2_BASE 192 //! - \b EUSCI_B3_BASE 193 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 194 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 195 //! I2C mode. 196 //! 197 //! \param slaveAddress 7-bit or 10-bit slave address 198 //! \param slaveAddressOffset Own address Offset referred to- 'x' value of 199 //! UCBxI2COAx. Valid values are: 200 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, 201 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, 202 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET2, 203 //! - \b EUSCI_B_I2C_OWN_ADDRESS_OFFSET3 204 //! \param slaveOwnAddressEnable selects if the specified address is enabled 205 //! or disabled. Valid values are: 206 //! - \b EUSCI_B_I2C_OWN_ADDRESS_DISABLE, 207 //! - \b EUSCI_B_I2C_OWN_ADDRESS_ENABLE 208 //! 209 //! This function initializes operation of the I2C as a Slave mode. Upon 210 //! successful initialization of the I2C blocks, this function will have set 211 //! the slave address but the I2C module is still disabled till 212 //! I2C_enableModule is invoked. 213 //! 214 //! The parameter slaveAddress is the value that will be compared against the 215 //! slave address sent by an I2C master. 216 //! 217 //! Modified bits are \b UCMODE_3, \b UCSYNC of \b UCBxCTL0 register 218 //! \b UCSWRST of \b UCBxCTL1 register 219 //! \b UCBxI2COA register 220 //! 221 //! \return None. 222 // 223 //***************************************************************************** 224 extern void I2C_initSlave(uint32_t moduleInstance, uint_fast16_t slaveAddress, 225 uint_fast8_t slaveAddressOffset, uint32_t slaveOwnAddressEnable); 226 227 //***************************************************************************** 228 // 229 //! Enables the I2C block. 230 //! 231 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 232 //! parameters vary from part to part, but can include: 233 //! - \b EUSCI_B0_BASE 234 //! - \b EUSCI_B1_BASE 235 //! - \b EUSCI_B2_BASE 236 //! - \b EUSCI_B3_BASE 237 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 238 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 239 //! I2C mode. 240 //! 241 //! This will enable operation of the I2C block. 242 //! Modified bits are \b UCSWRST of \b UCBxCTL1 register. 243 //! 244 //! \return None. 245 // 246 //***************************************************************************** 247 extern void I2C_enableModule(uint32_t moduleInstance); 248 249 //***************************************************************************** 250 // 251 //! Disables the I2C block. 252 //! 253 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 254 //! parameters vary from part to part, but can include: 255 //! - \b EUSCI_B0_BASE 256 //! - \b EUSCI_B1_BASE 257 //! - \b EUSCI_B2_BASE 258 //! - \b EUSCI_B3_BASE 259 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 260 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 261 //! I2C mode. 262 //! 263 //! This will disable operation of the I2C block. 264 //! Modified bits are \b UCSWRST of \b UCBxCTL1 register. 265 //! 266 //! \return None. 267 // 268 //***************************************************************************** 269 extern void I2C_disableModule(uint32_t moduleInstance); 270 271 //***************************************************************************** 272 // 273 //! Sets the address that the I2C Master will place on the bus. 274 //! 275 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 276 //! parameters vary from part to part, but can include: 277 //! - \b EUSCI_B0_BASE 278 //! - \b EUSCI_B1_BASE 279 //! - \b EUSCI_B2_BASE 280 //! - \b EUSCI_B3_BASE 281 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 282 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 283 //! I2C mode. 284 //! 285 //! \param slaveAddress 7-bit or 10-bit slave address 286 //! 287 //! This function will set the address that the I2C Master will place on the 288 //! bus when initiating a transaction. 289 //! Modified register is \b UCBxI2CSA register 290 //! 291 //! \return None. 292 // 293 //***************************************************************************** 294 extern void I2C_setSlaveAddress(uint32_t moduleInstance, 295 uint_fast16_t slaveAddress); 296 297 //***************************************************************************** 298 // 299 //! Sets the mode of the I2C device 300 //! 301 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 302 //! parameters vary from part to part, but can include: 303 //! - \b EUSCI_B0_BASE 304 //! - \b EUSCI_B1_BASE 305 //! - \b EUSCI_B2_BASE 306 //! - \b EUSCI_B3_BASE 307 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 308 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 309 //! I2C mode. 310 //! 311 //! \param mode indicates whether module is in transmit/receive mode 312 //! - \b EUSCI_B_I2C_TRANSMIT_MODE 313 //! - \b EUSCI_B_I2C_RECEIVE_MODE [Default value] 314 //! 315 //! Modified bits are \b UCTR of \b UCBxCTL1 register 316 //! 317 //! \return None. 318 // 319 //***************************************************************************** 320 extern void I2C_setMode(uint32_t moduleInstance, uint_fast8_t mode); 321 322 //***************************************************************************** 323 // 324 //! Sets the timeout of the I2C device 325 //! 326 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 327 //! parameters vary from part to part, but can include: 328 //! - \b EUSCI_B0_BASE 329 //! - \b EUSCI_B1_BASE 330 //! - \b EUSCI_B2_BASE 331 //! - \b EUSCI_B3_BASE 332 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 333 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 334 //! I2C mode. 335 //! 336 //! \param timeout indicates desired timeout 337 //! - \b EUSCI_B_I2C_TIMEOUT_DISABLE [Default value] 338 //! - \b EUSCI_B_I2C_TIMEOUT_28_MS 339 //! - \b EUSCI_B_I2C_TIMEOUT_31_MS 340 //! - \b EUSCI_B_I2C_TIMEOUT_34_MS 341 //! 342 //! Modified bits are \b UCSWRST of \b UCBxCTL0 and \b UCCLTO of \b UCBxCTL1 343 //! registers 344 //! 345 //! \return None. 346 // 347 //***************************************************************************** 348 extern void I2C_setTimeout(uint32_t moduleInstance, uint_fast16_t timeout); 349 350 //***************************************************************************** 351 // 352 //! \brief Gets the mode of the I2C device 353 //! 354 //! Current I2C transmit/receive mode. 355 //! 356 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 357 //! parameters vary from part to part, but can include: 358 //! - \b EUSCI_B0_BASE 359 //! - \b EUSCI_B1_BASE 360 //! - \b EUSCI_B2_BASE 361 //! - \b EUSCI_B3_BASE 362 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 363 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 364 //! I2C mode. 365 //! 366 //! Modified bits are \b UCTR of \b UCBxCTL1 register. 367 //! 368 //! \return None 369 //! Return one of the following: 370 //! - \b EUSCI_B_I2C_TRANSMIT_MODE 371 //! - \b EUSCI_B_I2C_RECEIVE_MODE 372 //! \n indicating the current mode 373 // 374 //***************************************************************************** 375 extern uint_fast8_t I2C_getMode(uint32_t moduleInstance); 376 377 //***************************************************************************** 378 // 379 //! Transmits a byte from the I2C Module. 380 //! 381 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 382 //! parameters vary from part to part, but can include: 383 //! - \b EUSCI_B0_BASE 384 //! - \b EUSCI_B1_BASE 385 //! - \b EUSCI_B2_BASE 386 //! - \b EUSCI_B3_BASE 387 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 388 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 389 //! I2C mode. 390 //! 391 //! \param transmitData data to be transmitted from the I2C module 392 //! 393 //! This function will place the supplied data into I2C transmit data register 394 //! to start transmission 395 //! Modified register is \b UCBxTXBUF register 396 //! 397 //! \return None. 398 // 399 //***************************************************************************** 400 extern void I2C_slavePutData(uint32_t moduleInstance, uint8_t transmitData); 401 402 //***************************************************************************** 403 // 404 //! Receives a byte that has been sent to the I2C Module. 405 //! 406 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 407 //! parameters vary from part to part, but can include: 408 //! - \b EUSCI_B0_BASE 409 //! - \b EUSCI_B1_BASE 410 //! - \b EUSCI_B2_BASE 411 //! - \b EUSCI_B3_BASE 412 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 413 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 414 //! I2C mode. 415 //! 416 //! This function reads a byte of data from the I2C receive data Register. 417 //! 418 //! \return Returns the byte received from by the I2C module, cast as an 419 //! uint8_t. 420 //! Modified bit is \b UCBxRXBUF register 421 // 422 //***************************************************************************** 423 extern uint8_t I2C_slaveGetData(uint32_t moduleInstance); 424 425 //***************************************************************************** 426 // 427 //! Indicates whether or not the I2C bus is busy. 428 //! 429 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 430 //! parameters vary from part to part, but can include: 431 //! - \b EUSCI_B0_BASE 432 //! - \b EUSCI_B1_BASE 433 //! - \b EUSCI_B2_BASE 434 //! - \b EUSCI_B3_BASE 435 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 436 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 437 //! I2C mode. 438 //! 439 //! 440 //! This function returns an indication of whether or not the I2C bus is 441 //! busy.This function checks the status of the bus via UCBBUSY bit in 442 //! UCBxSTAT register. 443 //! 444 //! \return Returns EUSCI_B_I2C_BUS_BUSY if the I2C Master is busy; otherwise, 445 //! returns EUSCI_B_I2C_BUS_NOT_BUSY. 446 // 447 //***************************************************************************** 448 extern uint8_t I2C_isBusBusy(uint32_t moduleInstance); 449 450 //***************************************************************************** 451 // 452 //! Does single byte transmission from Master to Slave 453 //! 454 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 455 //! parameters vary from part to part, but can include: 456 //! - \b EUSCI_B0_BASE 457 //! - \b EUSCI_B1_BASE 458 //! - \b EUSCI_B2_BASE 459 //! - \b EUSCI_B3_BASE 460 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 461 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 462 //! I2C mode. 463 //! 464 //! \param txData is the data byte to be transmitted 465 //! 466 //! This function is used by the Master module to send a single byte. 467 //! This function 468 //! - Sends START 469 //! - Transmits the byte to the Slave 470 //! - Sends STOP 471 //! 472 //! Modified registers are \b UCBxIE, \b UCBxCTL1, \b UCBxIFG, \b UCBxTXBUF, 473 //! \b UCBxIE 474 //! 475 //! \return none 476 // 477 //***************************************************************************** 478 extern void I2C_masterSendSingleByte(uint32_t moduleInstance, uint8_t txData); 479 480 //***************************************************************************** 481 // 482 //! Does single byte transmission from Master to Slave with timeout 483 //! 484 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 485 //! parameters vary from part to part, but can include: 486 //! - \b EUSCI_B0_BASE 487 //! - \b EUSCI_B1_BASE 488 //! - \b EUSCI_B2_BASE 489 //! - \b EUSCI_B3_BASE 490 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 491 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 492 //! I2C mode. 493 //! 494 //! \param txData is the data byte to be transmitted 495 //! \param timeout is the amount of time to wait until giving up 496 //! 497 //! This function is used by the Master module to send a single byte. 498 //! This function 499 //! - Sends START 500 //! - Transmits the byte to the Slave 501 //! - Sends STOP 502 //! 503 //! Modified registers are \b UCBxIE, \b UCBxCTL1, \b UCBxIFG, \b UCBxTXBUF, 504 //! \b UCBxIE 505 //! 506 //! \return 0x01 or 0x00URE of the transmission process. 507 // 508 //***************************************************************************** 509 extern bool I2C_masterSendSingleByteWithTimeout(uint32_t moduleInstance, 510 uint8_t txData, uint32_t timeout); 511 512 //***************************************************************************** 513 // 514 //! Starts multi-byte transmission from Master to Slave 515 //! 516 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 517 //! parameters vary from part to part, but can include: 518 //! - \b EUSCI_B0_BASE 519 //! - \b EUSCI_B1_BASE 520 //! - \b EUSCI_B2_BASE 521 //! - \b EUSCI_B3_BASE 522 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 523 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 524 //! I2C mode. 525 //! 526 //! \param txData is the first data byte to be transmitted 527 //! 528 //! This function is used by the Master module to send a single byte. 529 //! This function 530 //! - Sends START 531 //! - Transmits the first data byte of a multi-byte transmission to the Slave 532 //! 533 //! Modified registers are \b UCBxIE, \b UCBxCTL1, \b UCBxIFG, \b UCBxTXBUF, 534 //! \b UCBxIE 535 //! 536 //! \return None. 537 // 538 //***************************************************************************** 539 extern void I2C_masterSendMultiByteStart(uint32_t moduleInstance, 540 uint8_t txData); 541 542 //***************************************************************************** 543 // 544 //! Starts multi-byte transmission from Master to Slave with timeout 545 //! 546 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 547 //! parameters vary from part to part, but can include: 548 //! - \b EUSCI_B0_BASE 549 //! - \b EUSCI_B1_BASE 550 //! - \b EUSCI_B2_BASE 551 //! - \b EUSCI_B3_BASE 552 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 553 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 554 //! I2C mode. 555 //! 556 //! \param txData is the first data byte to be transmitted 557 //! \param timeout is the amount of time to wait until giving up 558 //! 559 //! This function is used by the Master module to send a single byte. 560 //! This function 561 //! - Sends START 562 //! - Transmits the first data byte of a multi-byte transmission to the Slave 563 //! 564 //! Modified registers are \b UCBxIE, \b UCBxCTL1, \b UCBxIFG, \b UCBxTXBUF, 565 //! \b UCBxIE 566 //! 567 //! \return 0x01 or 0x00URE of the transmission process. 568 // 569 //***************************************************************************** 570 extern bool I2C_masterSendMultiByteStartWithTimeout(uint32_t moduleInstance, 571 uint8_t txData, uint32_t timeout); 572 573 //***************************************************************************** 574 // 575 //! Continues multi-byte transmission from Master to Slave 576 //! 577 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 578 //! parameters vary from part to part, but can include: 579 //! - \b EUSCI_B0_BASE 580 //! - \b EUSCI_B1_BASE 581 //! - \b EUSCI_B2_BASE 582 //! - \b EUSCI_B3_BASE 583 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 584 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 585 //! I2C mode. 586 //! 587 //! \param txData is the next data byte to be transmitted 588 //! 589 //! This function is used by the Master module continue each byte of a 590 //! multi-byte trasmission. This function 591 //! - Transmits each data byte of a multi-byte transmission to the Slave 592 //! 593 //! Modified registers are \b UCBxTXBUF 594 //! 595 //! \return None. 596 // 597 //***************************************************************************** 598 extern void I2C_masterSendMultiByteNext(uint32_t moduleInstance, 599 uint8_t txData); 600 601 //***************************************************************************** 602 // 603 //! Continues multi-byte transmission from Master to Slave with timeout 604 //! 605 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 606 //! parameters vary from part to part, but can include: 607 //! - \b EUSCI_B0_BASE 608 //! - \b EUSCI_B1_BASE 609 //! - \b EUSCI_B2_BASE 610 //! - \b EUSCI_B3_BASE 611 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 612 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 613 //! I2C mode. 614 //! 615 //! \param txData is the next data byte to be transmitted 616 //! 617 //! \param timeout is the amount of time to wait until giving up 618 //! 619 //! This function is used by the Master module continue each byte of a 620 //! multi-byte transmission. This function 621 //! - Transmits each data byte of a multi-byte transmission to the Slave 622 //! 623 //! Modified registers are \b UCBxTXBUF 624 //! 625 //! \return 0x01 or 0x00URE of the transmission process. 626 // 627 //***************************************************************************** 628 extern bool I2C_masterSendMultiByteNextWithTimeout(uint32_t moduleInstance, 629 uint8_t txData, uint32_t timeout); 630 631 //***************************************************************************** 632 // 633 //! Finishes multi-byte transmission from Master to Slave 634 //! 635 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 636 //! parameters vary from part to part, but can include: 637 //! - \b EUSCI_B0_BASE 638 //! - \b EUSCI_B1_BASE 639 //! - \b EUSCI_B2_BASE 640 //! - \b EUSCI_B3_BASE 641 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 642 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 643 //! I2C mode. 644 //! 645 //! \param txData is the last data byte to be transmitted in a multi-byte 646 //! transmsission 647 //! 648 //! This function is used by the Master module to send the last byte and STOP. 649 //! This function 650 //! - Transmits the last data byte of a multi-byte transmission to the Slave 651 //! - Sends STOP 652 //! 653 //! Modified registers are \b UCBxTXBUF and \b UCBxCTL1. 654 //! 655 //! \return false if NAK occurred, false otherwise 656 // 657 //***************************************************************************** 658 extern bool I2C_masterSendMultiByteFinish(uint32_t moduleInstance, 659 uint8_t txData); 660 661 //***************************************************************************** 662 // 663 //! Finishes multi-byte transmission from Master to Slave with timeout 664 //! 665 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 666 //! parameters vary from part to part, but can include: 667 //! - \b EUSCI_B0_BASE 668 //! - \b EUSCI_B1_BASE 669 //! - \b EUSCI_B2_BASE 670 //! - \b EUSCI_B3_BASE 671 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 672 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 673 //! I2C mode. 674 //! 675 //! \param txData is the last data byte to be transmitted in a multi-byte 676 //! transmission 677 //! \param timeout is the amount of time to wait until giving up 678 //! 679 //! This function is used by the Master module to send the last byte and STOP. 680 //! This function 681 //! - Transmits the last data byte of a multi-byte transmission to the Slave 682 //! - Sends STOP 683 //! 684 //! Modified registers are \b UCBxTXBUF and \b UCBxCTL1. 685 //! 686 //! \return 0x01 or 0x00URE of the transmission process. 687 // 688 //***************************************************************************** 689 extern bool I2C_masterSendMultiByteFinishWithTimeout(uint32_t moduleInstance, 690 uint8_t txData, uint32_t timeout); 691 692 //***************************************************************************** 693 // 694 //! Send STOP byte at the end of a multi-byte transmission from Master to Slave 695 //! 696 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 697 //! parameters vary from part to part, but can include: 698 //! - \b EUSCI_B0_BASE 699 //! - \b EUSCI_B1_BASE 700 //! - \b EUSCI_B2_BASE 701 //! - \b EUSCI_B3_BASE 702 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 703 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 704 //! I2C mode. 705 //! 706 //! 707 //! This function is used by the Master module send STOP at the end of a 708 //! multi-byte transmission 709 //! 710 //! This function 711 //! - Send a STOP after current transmission is complete 712 //! 713 //! Modified bits are \b UCTXSTP bit of \b UCBxCTL1. 714 //! \return None. 715 // 716 //***************************************************************************** 717 extern void I2C_masterSendMultiByteStop(uint32_t moduleInstance); 718 719 //***************************************************************************** 720 // 721 //! Send STOP byte at the end of a multi-byte transmission from Master to Slave 722 //! with timeout 723 //! 724 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 725 //! parameters vary from part to part, but can include: 726 //! - \b EUSCI_B0_BASE 727 //! - \b EUSCI_B1_BASE 728 //! - \b EUSCI_B2_BASE 729 //! - \b EUSCI_B3_BASE 730 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 731 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 732 //! I2C mode. 733 //! 734 //! \param timeout is the amount of time to wait until giving up 735 //! 736 //! This function is used by the Master module send STOP at the end of a 737 //! multi-byte transmission 738 //! 739 //! This function 740 //! - Send a STOP after current transmission is complete 741 //! 742 //! Modified bits are \b UCTXSTP bit of \b UCBxCTL1. 743 //! \return 0x01 or 0x00URE of the transmission process. 744 // 745 //***************************************************************************** 746 extern bool I2C_masterSendMultiByteStopWithTimeout(uint32_t moduleInstance, 747 uint32_t timeout); 748 749 //***************************************************************************** 750 // 751 //! Starts reception at the Master end 752 //! 753 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 754 //! parameters vary from part to part, but can include: 755 //! - \b EUSCI_B0_BASE 756 //! - \b EUSCI_B1_BASE 757 //! - \b EUSCI_B2_BASE 758 //! - \b EUSCI_B3_BASE 759 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 760 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 761 //! I2C mode. 762 //! 763 //! 764 //! This function is used by the Master module initiate reception of a single 765 //! byte. This function 766 //! - Sends START 767 //! 768 //! Modified bits are \b UCTXSTT bit of \b UCBxCTL1. 769 //! \return None. 770 // 771 //***************************************************************************** 772 extern void I2C_masterReceiveStart(uint32_t moduleInstance); 773 774 //***************************************************************************** 775 // 776 //! Starts multi-byte reception at the Master end one byte at a time 777 //! 778 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 779 //! parameters vary from part to part, but can include: 780 //! - \b EUSCI_B0_BASE 781 //! - \b EUSCI_B1_BASE 782 //! - \b EUSCI_B2_BASE 783 //! - \b EUSCI_B3_BASE 784 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 785 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 786 //! I2C mode. 787 //! 788 //! 789 //! This function is used by the Master module to receive each byte of a 790 //! multi-byte reception 791 //! This function reads currently received byte 792 //! 793 //! Modified register is \b UCBxRXBUF. 794 //! \return Received byte at Master end. 795 // 796 //***************************************************************************** 797 extern uint8_t I2C_masterReceiveMultiByteNext(uint32_t moduleInstance); 798 799 //***************************************************************************** 800 // 801 //! Finishes multi-byte reception at the Master end 802 //! 803 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 804 //! parameters vary from part to part, but can include: 805 //! - \b EUSCI_B0_BASE 806 //! - \b EUSCI_B1_BASE 807 //! - \b EUSCI_B2_BASE 808 //! - \b EUSCI_B3_BASE 809 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 810 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 811 //! I2C mode. 812 //! 813 //! 814 //! This function is used by the Master module to initiate completion of a 815 //! multi-byte reception 816 //! This function 817 //! - Receives the current byte and initiates the STOP from Master to Slave 818 //! 819 //! Modified bits are \b UCTXSTP bit of \b UCBxCTL1. 820 //! 821 //! \return Received byte at Master end. 822 // 823 //***************************************************************************** 824 extern uint8_t I2C_masterReceiveMultiByteFinish(uint32_t moduleInstance); 825 826 //***************************************************************************** 827 // 828 //! Finishes multi-byte reception at the Master end with timeout 829 //! 830 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 831 //! parameters vary from part to part, but can include: 832 //! - \b EUSCI_B0_BASE 833 //! - \b EUSCI_B1_BASE 834 //! - \b EUSCI_B2_BASE 835 //! - \b EUSCI_B3_BASE 836 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 837 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 838 //! I2C mode. 839 //! 840 //! \param txData is a pointer to the location to store the received byte at 841 //! master end 842 //! \param timeout is the amount of time to wait until giving up 843 //! 844 //! This function is used by the Master module to initiate completion of a 845 //! multi-byte reception 846 //! This function 847 //! - Receives the current byte and initiates the STOP from Master to Slave 848 //! 849 //! Modified bits are \b UCTXSTP bit of \b UCBxCTL1. 850 //! 851 //! \return 0x01 or 0x00URE of the transmission process. 852 // 853 //***************************************************************************** 854 extern bool I2C_masterReceiveMultiByteFinishWithTimeout(uint32_t moduleInstance, 855 uint8_t *txData, uint32_t timeout); 856 857 //***************************************************************************** 858 // 859 //! Sends the STOP at the end of a multi-byte reception at the Master end 860 //! 861 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 862 //! parameters vary from part to part, but can include: 863 //! - \b EUSCI_B0_BASE 864 //! - \b EUSCI_B1_BASE 865 //! - \b EUSCI_B2_BASE 866 //! - \b EUSCI_B3_BASE 867 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 868 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 869 //! I2C mode. 870 //! 871 //! 872 //! This function is used by the Master module to initiate STOP 873 //! 874 //! Modified bits are UCTXSTP bit of UCBxCTL1. 875 //! 876 //! \return None. 877 // 878 //***************************************************************************** 879 extern void I2C_masterReceiveMultiByteStop(uint32_t moduleInstance); 880 881 //***************************************************************************** 882 // 883 //! Does single byte reception from the slave 884 //! 885 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 886 //! parameters vary from part to part, but can include: 887 //! - \b EUSCI_B0_BASE 888 //! - \b EUSCI_B1_BASE 889 //! - \b EUSCI_B2_BASE 890 //! - \b EUSCI_B3_BASE 891 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 892 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 893 //! I2C mode. 894 //! 895 //! This function is used by the Master module to receive a single byte. 896 //! This function: 897 //! - Sends START and STOP 898 //! - Waits for data reception 899 //! - Receives one byte from the Slave 900 //! 901 //! Modified registers are \b UCBxIE, \b UCBxCTL1, \b UCBxIFG, \b UCBxTXBUF, 902 //! \b UCBxIE 903 //! 904 //! \return The byte that has been received from the slave 905 // 906 //***************************************************************************** 907 extern uint8_t I2C_masterReceiveSingleByte(uint32_t moduleInstance); 908 909 //***************************************************************************** 910 // 911 //! Receives a byte that has been sent to the I2C Master Module. 912 //! 913 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 914 //! parameters vary from part to part, but can include: 915 //! - \b EUSCI_B0_BASE 916 //! - \b EUSCI_B1_BASE 917 //! - \b EUSCI_B2_BASE 918 //! - \b EUSCI_B3_BASE 919 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 920 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 921 //! I2C mode. 922 //! 923 //! 924 //! This function reads a byte of data from the I2C receive data Register. 925 //! 926 //! \return Returns the byte received from by the I2C module, cast as an 927 //! uint8_t. 928 // 929 //***************************************************************************** 930 extern uint8_t I2C_masterReceiveSingle(uint32_t moduleInstance); 931 932 //***************************************************************************** 933 // 934 //! Returns the address of the RX Buffer of the I2C for the DMA module. 935 //! 936 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 937 //! parameters vary from part to part, but can include: 938 //! - \b EUSCI_B0_BASE 939 //! - \b EUSCI_B1_BASE 940 //! - \b EUSCI_B2_BASE 941 //! - \b EUSCI_B3_BASE 942 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 943 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 944 //! I2C mode. 945 //! 946 //! 947 //! Returns the address of the I2C RX Buffer. This can be used in conjunction 948 //! with the DMA to store the received data directly to memory. 949 //! 950 //! \return NONE 951 // 952 //***************************************************************************** 953 extern uint32_t I2C_getReceiveBufferAddressForDMA(uint32_t moduleInstance); 954 955 //***************************************************************************** 956 // 957 //! Returns the address of the TX Buffer of the I2C for the DMA module. 958 //! 959 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 960 //! parameters vary from part to part, but can include: 961 //! - \b EUSCI_B0_BASE 962 //! - \b EUSCI_B1_BASE 963 //! - \b EUSCI_B2_BASE 964 //! - \b EUSCI_B3_BASE 965 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 966 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 967 //! I2C mode. 968 //! 969 //! 970 //! Returns the address of the I2C TX Buffer. This can be used in conjunction 971 //! with the DMA to obtain transmitted data directly from memory. 972 //! 973 //! \return NONE 974 // 975 //***************************************************************************** 976 extern uint32_t I2C_getTransmitBufferAddressForDMA(uint32_t moduleInstance); 977 978 //***************************************************************************** 979 // 980 //! Indicates whether STOP got sent. 981 //! 982 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 983 //! parameters vary from part to part, but can include: 984 //! - \b EUSCI_B0_BASE 985 //! - \b EUSCI_B1_BASE 986 //! - \b EUSCI_B2_BASE 987 //! - \b EUSCI_B3_BASE 988 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 989 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 990 //! I2C mode. 991 //! 992 //! 993 //! This function returns an indication of whether or not STOP got sent 994 //! This function checks the status of the bus via UCTXSTP bit in 995 //! UCBxCTL1 register. 996 //! 997 //! \return Returns EUSCI_B_I2C_STOP_SEND_COMPLETE if the I2C Master 998 //! finished sending STOP; otherwise, returns EUSCI_B_I2C_SENDING_STOP. 999 // 1000 //***************************************************************************** 1001 extern uint8_t I2C_masterIsStopSent(uint32_t moduleInstance); 1002 1003 //***************************************************************************** 1004 // 1005 //! Indicates whether Start got sent. 1006 //! 1007 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1008 //! parameters vary from part to part, but can include: 1009 //! - \b EUSCI_B0_BASE 1010 //! - \b EUSCI_B1_BASE 1011 //! - \b EUSCI_B2_BASE 1012 //! - \b EUSCI_B3_BASE 1013 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1014 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1015 //! I2C mode. 1016 //! 1017 //! 1018 //! This function returns an indication of whether or not Start got sent 1019 //! This function checks the status of the bus via UCTXSTT bit in 1020 //! UCBxCTL1 register. 1021 //! 1022 //! \return Returns EUSCI_B_I2C_BUS_BUSY if the I2C Master is busy; otherwise, 1023 //! returns EUSCI_B_I2C_BUS_NOT_BUSY. 1024 // 1025 //***************************************************************************** 1026 extern bool I2C_masterIsStartSent(uint32_t moduleInstance); 1027 1028 //***************************************************************************** 1029 // 1030 //! This function is used by the Master module to initiate START 1031 //! 1032 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1033 //! parameters vary from part to part, but can include: 1034 //! - \b EUSCI_B0_BASE 1035 //! - \b EUSCI_B1_BASE 1036 //! - \b EUSCI_B2_BASE 1037 //! - \b EUSCI_B3_BASE 1038 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1039 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1040 //! I2C mode. 1041 //! 1042 //! 1043 //! This function is used by the Master module to initiate STOP 1044 //! 1045 //! Modified bits are UCTXSTT bit of UCBxCTLW0. 1046 //! 1047 //! \return None. 1048 // 1049 //***************************************************************************** 1050 extern void I2C_masterSendStart(uint32_t moduleInstance); 1051 1052 //***************************************************************************** 1053 // 1054 //! Enables Multi Master Mode 1055 //! 1056 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1057 //! parameters vary from part to part, but can include: 1058 //! - \b EUSCI_B0_BASE 1059 //! - \b EUSCI_B1_BASE 1060 //! - \b EUSCI_B2_BASE 1061 //! - \b EUSCI_B3_BASE 1062 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1063 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1064 //! I2C mode. 1065 //! 1066 //! 1067 //! At the end of this function, the I2C module is still disabled till 1068 //! I2C_enableModule is invoked 1069 //! 1070 //! Modified bits are \b UCSWRST of \b OFS_UCBxCTLW0, \b UCMM bit of 1071 //! \b UCBxCTLW0 1072 //! 1073 //! \return None. 1074 // 1075 //***************************************************************************** 1076 extern void I2C_enableMultiMasterMode(uint32_t moduleInstance); 1077 1078 //***************************************************************************** 1079 // 1080 //! Disables Multi Master Mode 1081 //! 1082 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1083 //! parameters vary from part to part, but can include: 1084 //! - \b EUSCI_B0_BASE 1085 //! - \b EUSCI_B1_BASE 1086 //! - \b EUSCI_B2_BASE 1087 //! - \b EUSCI_B3_BASE 1088 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1089 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1090 //! I2C mode. 1091 //! 1092 //! 1093 //! At the end of this function, the I2C module is still disabled till 1094 //! I2C_enableModule is invoked 1095 //! 1096 //! Modified bits are \b UCSWRST of \b OFS_UCBxCTLW0, \b UCMM bit of 1097 //! \b UCBxCTLW0 1098 //! 1099 //! \return None. 1100 // 1101 //***************************************************************************** 1102 extern void I2C_disableMultiMasterMode(uint32_t moduleInstance); 1103 1104 //***************************************************************************** 1105 // 1106 //! Enables individual I2C interrupt sources. 1107 //! 1108 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1109 //! parameters vary from part to part, but can include: 1110 //! - \b EUSCI_B0_BASE 1111 //! - \b EUSCI_B1_BASE 1112 //! - \b EUSCI_B2_BASE 1113 //! - \b EUSCI_B3_BASE 1114 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1115 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1116 //! I2C mode. 1117 //! 1118 //! \param mask is the bit mask of the interrupt sources to 1119 //! be enabled. 1120 //! 1121 //! Enables the indicated I2C interrupt sources. Only the sources that 1122 //! are enabled can be reflected to the processor interrupt; disabled sources 1123 //! have no effect on the processor. 1124 //! 1125 //! The mask parameter is the logical OR of any of the following: 1126 //! 1127 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt 1128 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt 1129 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0 1130 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1 1131 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2 1132 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3 1133 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0 1134 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1 1135 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2 1136 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3 1137 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt 1138 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt 1139 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt enable 1140 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout interrupt 1141 //! enable 1142 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt enable 1143 //! 1144 //! Modified registers are UCBxIFG and OFS_UCBxIE. 1145 //! 1146 //! \return None. 1147 // 1148 //***************************************************************************** 1149 extern void I2C_enableInterrupt(uint32_t moduleInstance, uint_fast16_t mask); 1150 1151 //***************************************************************************** 1152 // 1153 //! Disables individual I2C interrupt sources. 1154 //! 1155 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1156 //! parameters vary from part to part, but can include: 1157 //! - \b EUSCI_B0_BASE 1158 //! - \b EUSCI_B1_BASE 1159 //! - \b EUSCI_B2_BASE 1160 //! - \b EUSCI_B3_BASE 1161 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1162 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1163 //! I2C mode. 1164 //! 1165 //! \param mask is the bit mask of the interrupt sources to be 1166 //! disabled. 1167 //! 1168 //! Disables the indicated I2C interrupt sources. Only the sources that 1169 //! are enabled can be reflected to the processor interrupt; disabled sources 1170 //! have no effect on the processor. 1171 //! 1172 //! The mask parameter is the logical OR of any of the following: 1173 //! 1174 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt 1175 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt 1176 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0 1177 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1 1178 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2 1179 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3 1180 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0 1181 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1 1182 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2 1183 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3 1184 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt 1185 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt 1186 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt enable 1187 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout interrupt 1188 //! enable 1189 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt enable 1190 //! 1191 //! Modified register is \b UCBxIE. 1192 //! 1193 //! \return None. 1194 // 1195 //***************************************************************************** 1196 extern void I2C_disableInterrupt(uint32_t moduleInstance, uint_fast16_t mask); 1197 1198 //***************************************************************************** 1199 // 1200 //! Clears I2C interrupt sources. 1201 //! 1202 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1203 //! parameters vary from part to part, but can include: 1204 //! - \b EUSCI_B0_BASE 1205 //! - \b EUSCI_B1_BASE 1206 //! - \b EUSCI_B2_BASE 1207 //! - \b EUSCI_B3_BASE 1208 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1209 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1210 //! I2C mode. 1211 //! 1212 //! \param mask is a bit mask of the interrupt sources to be cleared. 1213 //! 1214 //! The I2C interrupt source is cleared, so that it no longer asserts. 1215 //! The highest interrupt flag is automatically cleared when an interrupt vector 1216 //! generator is used. 1217 //! 1218 //! The mask parameter has the same definition as the mask 1219 //! parameter to I2C_enableInterrupt(). 1220 //! 1221 //! Modified register is \b UCBxIFG. 1222 //! 1223 //! \return None. 1224 // 1225 //***************************************************************************** 1226 extern void I2C_clearInterruptFlag(uint32_t moduleInstance, uint_fast16_t mask); 1227 1228 //***************************************************************************** 1229 // 1230 //! Gets the current I2C interrupt status. 1231 //! 1232 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1233 //! parameters vary from part to part, but can include: 1234 //! - \b EUSCI_B0_BASE 1235 //! - \b EUSCI_B1_BASE 1236 //! - \b EUSCI_B2_BASE 1237 //! - \b EUSCI_B3_BASE 1238 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1239 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1240 //! I2C mode. 1241 //! \param mask is the masked interrupt flag status to be returned. 1242 //! Mask value is the logical OR of any of the following: 1243 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt 1244 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost 1245 //! interrupt 1246 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt 1247 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt 1248 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0 1249 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1 1250 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2 1251 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3 1252 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0 1253 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1 1254 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2 1255 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3 1256 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt 1257 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout 1258 //! interrupt enable 1259 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt 1260 //! enable 1261 //! 1262 //! \return the masked status of the interrupt flag 1263 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt 1264 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt 1265 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0 1266 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1 1267 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2 1268 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3 1269 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0 1270 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1 1271 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2 1272 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3 1273 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt 1274 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt 1275 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt enable 1276 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout interrupt 1277 //! enable 1278 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt enable 1279 // 1280 //***************************************************************************** 1281 extern uint_fast16_t I2C_getInterruptStatus(uint32_t moduleInstance, uint16_t mask); 1282 1283 //***************************************************************************** 1284 // 1285 //! Gets the current I2C interrupt status masked with the enabled interrupts. 1286 //! This function is useful to call in ISRs to get a list of pending interrupts 1287 //! that are actually enabled and could have caused the ISR. 1288 //! 1289 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1290 //! parameters vary from part to part, but can include: 1291 //! - \b EUSCI_B0_BASE 1292 //! - \b EUSCI_B1_BASE 1293 //! - \b EUSCI_B2_BASE 1294 //! - \b EUSCI_B3_BASE 1295 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1296 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1297 //! I2C mode. 1298 //! 1299 //! \return the masked status of the interrupt flag 1300 //! - \b EUSCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt 1301 //! - \b EUSCI_B_I2C_START_INTERRUPT - START condition interrupt 1302 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT0 - Transmit interrupt0 1303 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT1 - Transmit interrupt1 1304 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT2 - Transmit interrupt2 1305 //! - \b EUSCI_B_I2C_TRANSMIT_INTERRUPT3 - Transmit interrupt3 1306 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT0 - Receive interrupt0 1307 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT1 - Receive interrupt1 1308 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT2 - Receive interrupt2 1309 //! - \b EUSCI_B_I2C_RECEIVE_INTERRUPT3 - Receive interrupt3 1310 //! - \b EUSCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt 1311 //! - \b EUSCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt 1312 //! - \b EUSCI_B_I2C_BIT9_POSITION_INTERRUPT - Bit position 9 interrupt enable 1313 //! - \b EUSCI_B_I2C_CLOCK_LOW_TIMEOUT_INTERRUPT - Clock low timeout interrupt 1314 //! enable 1315 //! - \b EUSCI_B_I2C_BYTE_COUNTER_INTERRUPT - Byte counter interrupt enable 1316 // 1317 //***************************************************************************** 1318 extern uint_fast16_t I2C_getEnabledInterruptStatus(uint32_t moduleInstance); 1319 1320 //***************************************************************************** 1321 // 1322 //! Registers an interrupt handler for I2C interrupts. 1323 //! 1324 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1325 //! parameters vary from part to part, but can include: 1326 //! - \b EUSCI_B0_BASE 1327 //! - \b EUSCI_B1_BASE 1328 //! - \b EUSCI_B2_BASE 1329 //! - \b EUSCI_B3_BASE 1330 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1331 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1332 //! I2C mode. 1333 //! 1334 //! \param intHandler is a pointer to the function to be called when the 1335 //! timer capture compare interrupt occurs. 1336 //! 1337 //! This function registers the handler to be called when an I2C 1338 //! interrupt occurs. This function enables the global interrupt in the 1339 //! interrupt controller; specific I2C interrupts must be enabled 1340 //! via I2C_enableInterrupt(). It is the interrupt handler's responsibility to 1341 //! clear the interrupt source via I2C_clearInterruptFlag(). 1342 //! 1343 //! \sa Interrupt_registerInterrupt() for important information about 1344 //! registering interrupt handlers. 1345 //! 1346 //! \return None. 1347 // 1348 //***************************************************************************** 1349 extern void I2C_registerInterrupt(uint32_t moduleInstance, 1350 void (*intHandler)(void)); 1351 1352 //***************************************************************************** 1353 // 1354 //! Unregisters the interrupt handler for the timer 1355 //! 1356 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1357 //! parameters vary from part to part, but can include: 1358 //! - \b EUSCI_B0_BASE 1359 //! - \b EUSCI_B1_BASE 1360 //! - \b EUSCI_B2_BASE 1361 //! - \b EUSCI_B3_BASE 1362 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1363 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1364 //! I2C mode. 1365 //! 1366 //! This function unregisters the handler to be called when timer 1367 //! interrupt occurs. This function also masks off the interrupt in the 1368 //! interrupt controller so that the interrupt handler no longer is called. 1369 //! 1370 //! \sa Interrupt_registerInterrupt() for important information about 1371 //! registering interrupt handlers. 1372 //! 1373 //! \return None. 1374 // 1375 //***************************************************************************** 1376 extern void I2C_unregisterInterrupt(uint32_t moduleInstance); 1377 1378 1379 //***************************************************************************** 1380 // 1381 //! This function is used by the slave to send a NAK out over the I2C line 1382 //! 1383 //! \param moduleInstance is the instance of the eUSCI B (I2C) module. Valid 1384 //! parameters vary from part to part, but can include: 1385 //! - \b EUSCI_B0_BASE 1386 //! - \b EUSCI_B1_BASE 1387 //! - \b EUSCI_B2_BASE 1388 //! - \b EUSCI_B3_BASE 1389 //! <br>It is important to note that for eUSCI modules, only "B" modules such as 1390 //! EUSCI_B0 can be used. "A" modules such as EUSCI_A0 do not support the 1391 //! I2C mode. 1392 //! 1393 //! \return None. 1394 // 1395 //***************************************************************************** 1396 extern void I2C_slaveSendNAK(uint32_t moduleInstance); 1397 1398 /* Backwards Compatibility Layer */ 1399 #define EUSCI_B_I2C_slaveInit I2C_initSlave 1400 #define EUSCI_B_I2C_enable I2C_enableModule 1401 #define EUSCI_B_I2C_disable I2C_disableModule 1402 #define EUSCI_B_I2C_setSlaveAddress I2C_setSlaveAddress 1403 #define EUSCI_B_I2C_setMode I2C_setMode 1404 #define EUSCI_B_I2C_getMode I2C_getMode 1405 #define EUSCI_B_I2C_slaveDataPut I2C_slavePutData 1406 #define EUSCI_B_I2C_slaveDataGet I2C_slaveGetData 1407 #define EUSCI_B_I2C_isBusBusy I2C_isBusBusy 1408 #define EUSCI_B_I2C_masterIsStopSent I2C_masterIsStopSent 1409 #define EUSCI_B_I2C_masterIsStartSent I2C_masterIsStartSent 1410 #define EUSCI_B_I2C_enableInterrupt I2C_enableInterrupt 1411 #define EUSCI_B_I2C_disableInterrupt I2C_disableInterrupt 1412 #define EUSCI_B_I2C_clearInterruptFlag I2C_clearInterruptFlag 1413 #define EUSCI_B_I2C_getInterruptStatus I2C_getEnabledInterruptStatus 1414 #define EUSCI_B_I2C_masterSendSingleByte I2C_masterSendSingleByte 1415 #define EUSCI_B_I2C_masterReceiveSingleByte I2C_masterReceiveSingleByte 1416 #define EUSCI_B_I2C_masterSendSingleByteWithTimeout I2C_masterSendSingleByteWithTimeout 1417 #define EUSCI_B_I2C_masterMultiByteSendStart I2C_masterSendMultiByteStart 1418 #define EUSCI_B_I2C_masterMultiByteSendStartWithTimeout I2C_masterSendMultiByteStartWithTimeout 1419 #define EUSCI_B_I2C_masterMultiByteSendNext I2C_masterSendMultiByteNext 1420 #define EUSCI_B_I2C_masterMultiByteSendNextWithTimeout I2C_masterSendMultiByteNextWithTimeout 1421 #define EUSCI_B_I2C_masterMultiByteSendFinish I2C_masterSendMultiByteFinish 1422 #define EUSCI_B_I2C_masterMultiByteSendFinishWithTimeout I2C_masterSendMultiByteFinishWithTimeout 1423 #define EUSCI_B_I2C_masterSendStart I2C_masterSendStart 1424 #define EUSCI_B_I2C_masterMultiByteSendStop I2C_masterSendMultiByteStop 1425 #define EUSCI_B_I2C_masterMultiByteSendStopWithTimeout I2C_masterSendMultiByteStopWithTimeout 1426 #define EUSCI_B_I2C_masterReceiveStart I2C_masterReceiveStart 1427 #define EUSCI_B_I2C_masterMultiByteReceiveNext I2C_masterReceiveMultiByteNext 1428 #define EUSCI_B_I2C_masterMultiByteReceiveFinish I2C_masterReceiveMultiByteFinish 1429 #define EUSCI_B_I2C_masterMultiByteReceiveFinishWithTimeout I2C_masterReceiveMultiByteFinishWithTimeout 1430 #define EUSCI_B_I2C_masterMultiByteReceiveStop I2C_masterReceiveMultiByteStop 1431 #define EUSCI_B_I2C_enableMultiMasterMode I2C_enableMultiMasterMode 1432 #define EUSCI_B_I2C_disableMultiMasterMode I2C_disableMultiMasterMode 1433 #define EUSCI_B_I2C_masterSingleReceive I2C_masterReceiveSingle 1434 #define EUSCI_B_I2C_getReceiveBufferAddressForDMA I2C_getReceiveBufferAddressForDMA 1435 #define EUSCI_B_I2C_getTransmitBufferAddressForDMA I2C_getTransmitBufferAddressForDMA 1436 1437 1438 //***************************************************************************** 1439 // 1440 // Mark the end of the C bindings section for C++ compilers. 1441 // 1442 //***************************************************************************** 1443 #ifdef __cplusplus 1444 } 1445 #endif 1446 1447 //***************************************************************************** 1448 // 1449 // Close the Doxygen group. 1450 //! @} 1451 // 1452 //***************************************************************************** 1453 1454 #endif /* I2C_H_ */ 1455 1456