MCUXpresso SDK API Reference Manual  Rev 2.12.1
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

Data Structures

struct  i2c_master_config_t
 Structure with settings to initialize the I2C master module. More...
 

Enumerations

enum  _i2c_master_flags {
  kI2C_MasterPendingFlag = I2C_STAT_MSTPENDING_MASK,
  kI2C_MasterArbitrationLostFlag,
  kI2C_MasterStartStopErrorFlag
}
 I2C master peripheral flags. More...
 
enum  i2c_direction_t {
  kI2C_Write = 0U,
  kI2C_Read = 1U
}
 Direction of master and slave transfers. More...
 

Initialization and deinitialization

void I2C_MasterGetDefaultConfig (i2c_master_config_t *masterConfig)
 Provides a default configuration for the I2C master peripheral. More...
 
void I2C_MasterInit (I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz)
 Initializes the I2C master peripheral. More...
 
void I2C_MasterDeinit (I2C_Type *base)
 Deinitializes the I2C master peripheral. More...
 
uint32_t I2C_GetInstance (I2C_Type *base)
 Returns an instance number given a base address. More...
 
static void I2C_MasterReset (I2C_Type *base)
 Performs a software reset. More...
 
static void I2C_MasterEnable (I2C_Type *base, bool enable)
 Enables or disables the I2C module as master. More...
 

Status

static uint32_t I2C_GetStatusFlags (I2C_Type *base)
 Gets the I2C status flags. More...
 
static void I2C_MasterClearStatusFlags (I2C_Type *base, uint32_t statusMask)
 Clears the I2C master status flag state. More...
 

Interrupts

static void I2C_EnableInterrupts (I2C_Type *base, uint32_t interruptMask)
 Enables the I2C master interrupt requests. More...
 
static void I2C_DisableInterrupts (I2C_Type *base, uint32_t interruptMask)
 Disables the I2C master interrupt requests. More...
 
static uint32_t I2C_GetEnabledInterrupts (I2C_Type *base)
 Returns the set of currently enabled I2C master interrupt requests. More...
 

Bus operations

void I2C_MasterSetBaudRate (I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
 Sets the I2C bus frequency for master transactions. More...
 
static bool I2C_MasterGetBusIdleState (I2C_Type *base)
 Returns whether the bus is idle. More...
 
status_t I2C_MasterStart (I2C_Type *base, uint8_t address, i2c_direction_t direction)
 Sends a START on the I2C bus. More...
 
status_t I2C_MasterStop (I2C_Type *base)
 Sends a STOP signal on the I2C bus. More...
 
static status_t I2C_MasterRepeatedStart (I2C_Type *base, uint8_t address, i2c_direction_t direction)
 Sends a REPEATED START on the I2C bus. More...
 

Data Structure Documentation

struct i2c_master_config_t

This structure holds configuration settings for the I2C peripheral. To initialize this structure to reasonable defaults, call the I2C_MasterGetDefaultConfig() function and pass a pointer to your configuration structure instance.

The configuration structure can be made constant so it resides in flash.

Data Fields

bool enableMaster
 Whether to enable master mode. More...
 
uint32_t baudRate_Bps
 Desired baud rate in bits per second. More...
 
bool enableTimeout
 Enable internal timeout function. More...
 

Field Documentation

bool i2c_master_config_t::enableMaster
uint32_t i2c_master_config_t::baudRate_Bps
bool i2c_master_config_t::enableTimeout

Enumeration Type Documentation

Note
These enums are meant to be OR'd together to form a bit mask.
Enumerator
kI2C_MasterPendingFlag 

The I2C module is waiting for software interaction.

kI2C_MasterArbitrationLostFlag 

The arbitration of the bus was lost.

There was collision on the bus

kI2C_MasterStartStopErrorFlag 

There was an error during start or stop phase of the transaction.

Enumerator
kI2C_Write 

Master transmit.

kI2C_Read 

Master receive.

Function Documentation

void I2C_MasterGetDefaultConfig ( i2c_master_config_t masterConfig)

This function provides the following default configuration for the I2C master peripheral:

* masterConfig->enableMaster = true;
* masterConfig->baudRate_Bps = 100000U;
* masterConfig->enableTimeout = false;
*

After calling this function, you can override any settings in order to customize the configuration, prior to initializing the master driver with I2C_MasterInit().

Parameters
[out]masterConfigUser provided configuration structure for default values. Refer to i2c_master_config_t.
void I2C_MasterInit ( I2C_Type *  base,
const i2c_master_config_t masterConfig,
uint32_t  srcClock_Hz 
)

This function enables the peripheral clock and initializes the I2C master peripheral as described by the user provided configuration. A software reset is performed prior to configuration.

Parameters
baseThe I2C peripheral base address.
masterConfigUser provided peripheral configuration. Use I2C_MasterGetDefaultConfig() to get a set of defaults that you can override.
srcClock_HzFrequency in Hertz of the I2C functional clock. Used to calculate the baud rate divisors, filter widths, and timeout periods.
void I2C_MasterDeinit ( I2C_Type *  base)

This function disables the I2C master peripheral and gates the clock. It also performs a software reset to restore the peripheral to reset conditions.

Parameters
baseThe I2C peripheral base address.
uint32_t I2C_GetInstance ( I2C_Type *  base)

If an invalid base address is passed, debug builds will assert. Release builds will just return instance number 0.

Parameters
baseThe I2C peripheral base address.
Returns
I2C instance number starting from 0.
static void I2C_MasterReset ( I2C_Type *  base)
inlinestatic

Restores the I2C master peripheral to reset conditions.

Parameters
baseThe I2C peripheral base address.
static void I2C_MasterEnable ( I2C_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseThe I2C peripheral base address.
enablePass true to enable or false to disable the specified I2C as master.
static uint32_t I2C_GetStatusFlags ( I2C_Type *  base)
inlinestatic

A bit mask with the state of all I2C status flags is returned. For each flag, the corresponding bit in the return value is set if the flag is asserted.

Parameters
baseThe I2C peripheral base address.
Returns
State of the status flags:
  • 1: related status flag is set.
  • 0: related status flag is not set.
See Also
_i2c_master_flags
static void I2C_MasterClearStatusFlags ( I2C_Type *  base,
uint32_t  statusMask 
)
inlinestatic

The following status register flags can be cleared:

Attempts to clear other flags has no effect.

Parameters
baseThe I2C peripheral base address.
statusMaskA bitmask of status flags that are to be cleared. The mask is composed of _i2c_master_flags enumerators OR'd together. You may pass the result of a previous call to I2C_GetStatusFlags().
See Also
_i2c_master_flags.
static void I2C_EnableInterrupts ( I2C_Type *  base,
uint32_t  interruptMask 
)
inlinestatic
Parameters
baseThe I2C peripheral base address.
interruptMaskBit mask of interrupts to enable. See _i2c_master_flags for the set of constants that should be OR'd together to form the bit mask.
static void I2C_DisableInterrupts ( I2C_Type *  base,
uint32_t  interruptMask 
)
inlinestatic
Parameters
baseThe I2C peripheral base address.
interruptMaskBit mask of interrupts to disable. See _i2c_master_flags for the set of constants that should be OR'd together to form the bit mask.
static uint32_t I2C_GetEnabledInterrupts ( I2C_Type *  base)
inlinestatic
Parameters
baseThe I2C peripheral base address.
Returns
A bitmask composed of _i2c_master_flags enumerators OR'd together to indicate the set of enabled interrupts.
void I2C_MasterSetBaudRate ( I2C_Type *  base,
uint32_t  baudRate_Bps,
uint32_t  srcClock_Hz 
)

The I2C master is automatically disabled and re-enabled as necessary to configure the baud rate. Do not call this function during a transfer, or the transfer is aborted.

Parameters
baseThe I2C peripheral base address.
srcClock_HzI2C functional clock frequency in Hertz.
baudRate_BpsRequested bus frequency in bits per second.
static bool I2C_MasterGetBusIdleState ( I2C_Type *  base)
inlinestatic

Requires the master mode to be enabled.

Parameters
baseThe I2C peripheral base address.
Return values
trueBus is busy.
falseBus is idle.
status_t I2C_MasterStart ( I2C_Type *  base,
uint8_t  address,
i2c_direction_t  direction 
)

This function is used to initiate a new master mode transfer by sending the START signal. The slave address is sent following the I2C START signal.

Parameters
baseI2C peripheral base pointer
address7-bit slave device address.
directionMaster transfer directions(transmit/receive).
Return values
kStatus_SuccessSuccessfully send the start signal.
kStatus_I2C_BusyCurrent bus is busy.
status_t I2C_MasterStop ( I2C_Type *  base)
Return values
kStatus_SuccessSuccessfully send the stop signal.
kStatus_I2C_TimeoutSend stop signal failed, timeout.
static status_t I2C_MasterRepeatedStart ( I2C_Type *  base,
uint8_t  address,
i2c_direction_t  direction 
)
inlinestatic
Parameters
baseI2C peripheral base pointer
address7-bit slave device address.
directionMaster transfer directions(transmit/receive).
Return values
kStatus_SuccessSuccessfully send the start signal.
kStatus_I2C_BusyCurrent bus is busy but not occupied by current I2C master.