MSPM0G1X0X_G3X0X TI-Driver Library  2.01.00.03
Data Structures | Macros
Collaboration diagram for I2C driver APIs:

Data Structures

struct  I2CMSPM0_I2CPinCfg
 I2C Pin Configuration. More...
 
struct  I2CMSPM0_HWAttrs
 I2C Hardware attributes. More...
 
struct  I2CMSPM0_Object
 I2C Object. More...
 

Macros

#define I2C_CONTROLLER_INTERRUPTS_MASK   0xFFFF
 I2C controller interrupt mask.
 

Detailed Description

Overview

Refer to ti_drivers_I2C_Overview for a complete description of APIs and examples of use.

The general I2C API is normally used in application code, e.g. I2C_open() is used instead of I2CMSPM0_open(). The board file will define the device specific config, and casting in the general API will ensure that the correct device specific functions are called.

General Behavior

Before using the I2C:

The following is true for receive operation:

The following apply for transmit operation:

After I2C operation has ended:

Error handling

If an error occurs during operation:

Power Management

The I2C driver sets a power constraint during transactions to keep the device out of standby; so when all tasks are blocked, the device will enter idle mode instead of standby. When the transactions have finished, the power constraint to prohibit standby is released. The following statements are valid:

Supported Functions

Generic API Function API Function Description
I2C_init() I2CMSPM0_initHw() Initialize I2C driver
I2C_open() I2C_open() Initialize I2C HW and set system dependencies
I2C_close() I2C_close() Disable I2C HW and release system dependencies
I2C_transfer() I2CSupport_primeTransfer()Start I2C transfer
Note
All calls should go through the generic API.

Supported Bit Rates

The I2C driver currently does not support:

Use Cases

Basic Receive

Receive 10 bytes over I2C in I2C_MODE_BLOCKING.

// Locals
I2C_Handle handle;
I2C_Params params;
I2C_Transaction i2cTrans;
uint8_t rxBuf[32]; // Receive buffer
uint8_t txBuf[32]; // Transmit buffer
// Configure I2C parameters.
I2C_Params_init(&params);
// Initialize I2C transaction structure
i2cTrans.writeCount = 0;
i2cTrans.writeBuf = txBuf;
i2cTrans.readCount = 10;
i2cTrans.readBuf = rxBuf;
i2cTrans.targetAddress = 0x3C;
// Open I2C
handle = I2C_open(CONFIG_I2C, &params);
// Do I2C transfer receive
I2C_transfer(handle, &i2cTrans);

Basic Transmit

Transmit 16 bytes over I2C in I2C_MODE_CALLBACK.

uint8_t rxBuffer[32]; // Receive buffer
uint8_t txBuffer[32]; // Transmit buffer
bool transferDone = false;
static void transferCallback(I2C_Handle handle, I2C_Transaction *transac, bool result)
{
// Set length bytes
if (result) {
transferDone = true;
} else {
// Transaction failed, act accordingly...
.
.
}
}
static void taskFxn(uintptr_t a0, uintptr_t a1)
{
// Locals
I2C_Handle handle;
I2C_Params params;
I2C_Transaction i2cTrans;
// Configure I2C parameters.
I2C_Params_init(&params);
params.transferCallbackFxn = transferCallback;
// Prepare data to send, send 0x00, 0x01, 0x02, ...0xFF, 0x00, 0x01...
for(uint32_t i = 0; i < numTxBytes; i++)
txBuffer[i] = (uint8_t) i;
// Initialize I2C transaction structure
i2cTrans.writeCount = 16;
i2cTrans.writeBuf = txBuffer;
i2cTrans.readCount = 0;
i2cTrans.readBuf = rxBuffer;
i2cTrans.targetAddress = 0x3C;
// Open I2C
handle = I2C_open(CONFIG_I2C, &params);
// Do I2C transfer (in callback mode)
I2C_transfer(handle, &i2cTrans);
// Do other stuff while I2C is handling the transfer.
.
.
// Do something if I2C transfer is finished.
if(transferDone) {
.
.
}
// Continue...
.
.
}

Chained Transactions

Transmit 10 bytes and then 32 bytes over I2C in I2C_MODE_CALLBACK.

uint8_t rxBuffer[32]; // Receive buffer
uint8_t txBuffer[32]; // Transmit buffer
uint8_t rxBuffer2[64]; // Receive buffer 2
uint8_t txBuffer2[64]; // Transmit buffer 2
bool transferDone = false;
static void writeCallbackDefault(I2C_Handle handle, I2C_Transaction *transac, bool result)
{
// Set length bytes
if (result) {
transferDone = true;
} else {
// Transaction failed, act accordingly...
.
.
}
}
static void taskFxn(uintptr_t a0, uintptr_t a1)
{
// Locals
I2C_Handle handle;
I2C_Params params;
I2C_Transaction i2cTrans;
I2C_Transaction i2cTrans2;
// Configure I2C parameters.
I2C_Params_init(&params);
params.transferCallbackFxn = writeCallbackDefault;
// Prepare data to send, send 0x00, 0x01, 0x02, ...0xFF, 0x00, 0x01...
for(uint32_t i = 0; i < numTxBytes; i++)
txBuffer[i] = (uint8_t) i;
// Initialize first I2C transaction structure
i2cTrans.writeCount = 10;
i2cTrans.writeBuf = txBuffer;
i2cTrans.readCount = 0;
i2cTrans.readBuf = rxBuffer;
i2cTrans.targetAddress = 0x3C;
// Second transaction
i2cTrans2.writeCount = 32;
i2cTrans2.writeBuf = txBuffer2;
i2cTrans2.readCount = 0;
i2cTrans2.readBuf = rxBuffer2;
i2cTrans2.targetAddress = 0x2E;
// Open I2C
handle = I2C_open(CONFIG_I2C, &params);
// Do chained I2C transfers (in callback mode).
I2C_transfer(handle, &i2cTrans);
I2C_transfer(handle, &i2cTrans2);
// Do other stuff while I2C is handling the transfers.
.
.
// Do something if I2C transfers are finished.
if(transferDone) {
.
.
}
// Continue...
.
.
}

Instrumentation

The I2C driver interface produces log statements if instrumentation is enabled.

Diagnostics Mask Log details
Diags_USER1 basic I2C operations performed
Diags_USER2 detailed I2C operations performed
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale