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_slave_address_t
 Data structure with 7-bit Slave address and Slave address disable. More...
 
struct  i2c_slave_config_t
 Structure with settings to initialize the I2C slave module. More...
 

Enumerations

enum  _i2c_slave_flags {
  kI2C_SlavePendingFlag = I2C_STAT_SLVPENDING_MASK,
  kI2C_SlaveNotStretching,
  kI2C_SlaveSelected = I2C_STAT_SLVSEL_MASK,
  kI2C_SaveDeselected
}
 I2C slave peripheral flags. More...
 
enum  i2c_slave_address_register_t {
  kI2C_SlaveAddressRegister0 = 0U,
  kI2C_SlaveAddressRegister1 = 1U,
  kI2C_SlaveAddressRegister2 = 2U,
  kI2C_SlaveAddressRegister3 = 3U
}
 I2C slave address register. More...
 
enum  i2c_slave_address_qual_mode_t {
  kI2C_QualModeMask = 0U,
  kI2C_QualModeExtend
}
 I2C slave address match options. More...
 
enum  i2c_slave_bus_speed_t
 I2C slave bus speed options. More...
 

Slave initialization and deinitialization

void I2C_SlaveGetDefaultConfig (i2c_slave_config_t *slaveConfig)
 Provides a default configuration for the I2C slave peripheral. More...
 
status_t I2C_SlaveInit (I2C_Type *base, const i2c_slave_config_t *slaveConfig, uint32_t srcClock_Hz)
 Initializes the I2C slave peripheral. More...
 
void I2C_SlaveSetAddress (I2C_Type *base, i2c_slave_address_register_t addressRegister, uint8_t address, bool addressDisable)
 Configures Slave Address n register. More...
 
void I2C_SlaveDeinit (I2C_Type *base)
 Deinitializes the I2C slave peripheral. More...
 
static void I2C_SlaveEnable (I2C_Type *base, bool enable)
 Enables or disables the I2C module as slave. More...
 

Slave status

static void I2C_SlaveClearStatusFlags (I2C_Type *base, uint32_t statusMask)
 Clears the I2C status flag state. More...
 

Data Structure Documentation

struct i2c_slave_address_t

Data Fields

uint8_t address
 7-bit Slave address SLVADR. More...
 
bool addressDisable
 Slave address disable SADISABLE. More...
 

Field Documentation

uint8_t i2c_slave_address_t::address
bool i2c_slave_address_t::addressDisable
struct i2c_slave_config_t

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

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

Data Fields

i2c_slave_address_t address0
 Slave's 7-bit address and disable. More...
 
i2c_slave_address_t address1
 Alternate slave 7-bit address and disable. More...
 
i2c_slave_address_t address2
 Alternate slave 7-bit address and disable. More...
 
i2c_slave_address_t address3
 Alternate slave 7-bit address and disable. More...
 
i2c_slave_address_qual_mode_t qualMode
 Qualify mode for slave address 0. More...
 
uint8_t qualAddress
 Slave address qualifier for address 0. More...
 
i2c_slave_bus_speed_t busSpeed
 Slave bus speed mode. More...
 
bool enableSlave
 Enable slave mode. More...
 

Field Documentation

i2c_slave_address_t i2c_slave_config_t::address0
i2c_slave_address_t i2c_slave_config_t::address1
i2c_slave_address_t i2c_slave_config_t::address2
i2c_slave_address_t i2c_slave_config_t::address3
i2c_slave_address_qual_mode_t i2c_slave_config_t::qualMode
uint8_t i2c_slave_config_t::qualAddress
i2c_slave_bus_speed_t i2c_slave_config_t::busSpeed

If the slave function stretches SCL to allow for software response, it must provide sufficient data setup time to the master before releasing the stretched clock. This is accomplished by inserting one clock time of CLKDIV at that point. The busSpeed value is used to configure CLKDIV such that one clock time is greater than the tSU;DAT value noted in the I2C bus specification for the I2C mode that is being used. If the busSpeed mode is unknown at compile time, use the longest data setup time kI2C_SlaveStandardMode (250 ns)

bool i2c_slave_config_t::enableSlave

Enumeration Type Documentation

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

The I2C module is waiting for software interaction.

kI2C_SlaveNotStretching 

Indicates whether the slave is currently stretching clock (0 = yes, 1 = no).

kI2C_SlaveSelected 

Indicates whether the slave is selected by an address match.

kI2C_SaveDeselected 

Indicates that slave was previously deselected (deselect event took place, w1c).

Enumerator
kI2C_SlaveAddressRegister0 

Slave Address 0 register.

kI2C_SlaveAddressRegister1 

Slave Address 1 register.

kI2C_SlaveAddressRegister2 

Slave Address 2 register.

kI2C_SlaveAddressRegister3 

Slave Address 3 register.

Enumerator
kI2C_QualModeMask 

The SLVQUAL0 field (qualAddress) is used as a logical mask for matching address0.

kI2C_QualModeExtend 

The SLVQUAL0 (qualAddress) field is used to extend address 0 matching in a range of addresses.

Function Documentation

void I2C_SlaveGetDefaultConfig ( i2c_slave_config_t slaveConfig)

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

* slaveConfig->enableSlave = true;
* slaveConfig->address0.disable = false;
* slaveConfig->address0.address = 0u;
* slaveConfig->address1.disable = true;
* slaveConfig->address2.disable = true;
* slaveConfig->address3.disable = true;
* slaveConfig->busSpeed = kI2C_SlaveStandardMode;
*

After calling this function, override any settings to customize the configuration, prior to initializing the master driver with I2C_SlaveInit(). Be sure to override at least the address0.address member of the configuration structure with the desired slave address.

Parameters
[out]slaveConfigUser provided configuration structure that is set to default values. Refer to i2c_slave_config_t.
status_t I2C_SlaveInit ( I2C_Type *  base,
const i2c_slave_config_t slaveConfig,
uint32_t  srcClock_Hz 
)

This function enables the peripheral clock and initializes the I2C slave peripheral as described by the user provided configuration.

Parameters
baseThe I2C peripheral base address.
slaveConfigUser provided peripheral configuration. Use I2C_SlaveGetDefaultConfig() to get a set of defaults that you can override.
srcClock_HzFrequency in Hertz of the I2C functional clock. Used to calculate CLKDIV value to provide enough data setup time for master when slave stretches the clock.
void I2C_SlaveSetAddress ( I2C_Type *  base,
i2c_slave_address_register_t  addressRegister,
uint8_t  address,
bool  addressDisable 
)

This function writes new value to Slave Address register.

Parameters
baseThe I2C peripheral base address.
addressRegisterThe module supports multiple address registers. The parameter determines which one shall be changed.
addressThe slave address to be stored to the address register for matching.
addressDisableDisable matching of the specified address register.
void I2C_SlaveDeinit ( I2C_Type *  base)

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

Parameters
baseThe I2C peripheral base address.
static void I2C_SlaveEnable ( I2C_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseThe I2C peripheral base address.
enableTrue to enable or flase to disable.
static void I2C_SlaveClearStatusFlags ( I2C_Type *  base,
uint32_t  statusMask 
)
inlinestatic

The following status register flags can be cleared:

  • slave deselected flag

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_slave_flags enumerators OR'd together. You may pass the result of a previous call to I2C_SlaveGetStatusFlags().
See Also
_i2c_slave_flags.