Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
I2C Slave peripheral driver

Overview

This section describes the programming interface of the I2C slave mode Peripheral driver.

Data Structures

struct  i2c_slave_state_t
 Runtime state of the I2C Slave driver. More...
 
struct  i2c_slave_user_config_t
 Defines the structure to initialize the I2C Slave module. More...
 

Typedefs

typedef void(* i2c_slave_callback_t )(uint8_t instance, i2c_slave_event_t slaveEvent, void *userData)
 I2C slave callback function.
 

Enumerations

enum  i2c_slave_event_t {
  kI2CSlaveTxReq = 0x02u,
  kI2CSlaveRxReq = 0x04u,
  kI2CSlaveTxNAK = 0x08u,
  kI2CSlaveTxEmpty = 0x10u,
  kI2CSlaveRxFull = 0x20u,
  kI2CSlaveAbort = 0x40u
}
 Internal driver state information. More...
 

Variables

I2C_Type *const g_i2cBase [I2C_INSTANCE_COUNT]
 Table of base addresses for I2C instances. More...
 

I2C Slave

i2c_status_t I2C_DRV_SlaveInit (uint32_t instance, const i2c_slave_user_config_t *userConfigPtr, i2c_slave_state_t *slave)
 Initializes the I2C module. More...
 
i2c_status_t I2C_DRV_SlaveDeinit (uint32_t instance)
 Shuts down the I2C slave driver. More...
 
i2c_slave_state_tI2C_DRV_SlaveGetHandler (uint32_t instance)
 Gets the I2C slave run-time state structure. More...
 
i2c_status_t I2C_DRV_SlaveSendData (uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
 Sends/transmits data by using a non-blocking method. More...
 
i2c_status_t I2C_DRV_SlaveSendDataBlocking (uint32_t instance, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout_ms)
 Sends (transmits) data by using a blocking method. More...
 
i2c_status_t I2C_DRV_SlaveReceiveData (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
 Receives the data by using a non-blocking method. More...
 
i2c_status_t I2C_DRV_SlaveReceiveDataBlocking (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout_ms)
 Receives data by using a blocking method. More...
 
i2c_status_t I2C_DRV_SlaveGetReceiveStatus (uint32_t instance, uint32_t *bytesRemaining)
 Gets the current status of the I2C slave driver. More...
 
i2c_status_t I2C_DRV_SlaveGetTransmitStatus (uint32_t instance, uint32_t *bytesRemaining)
 Gets the current status of the I2C slave driver. More...
 
i2c_status_t I2C_DRV_SlaveAbortReceiveData (uint32_t instance, uint32_t *rxSize)
 Terminates a non-blocking receive of the I2C slave early. More...
 
i2c_status_t I2C_DRV_SlaveAbortSendData (uint32_t instance, uint32_t *txSize)
 Terminates a non-blocking send of the I2C slave early. More...
 
static bool I2C_DRV_SlaveIsBusBusy (uint32_t instance)
 Gets the current status of the I2C slave bus. More...
 
static i2c_status_t I2C_DRV_SlaveSendDataPolling (uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
 Sends out multiple bytes of data using a polling method. More...
 
static i2c_status_t I2C_DRV_SlaveReceiveDataPolling (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
 Receives multiple bytes of data using a polling method. More...
 
void I2C_DRV_SlaveIRQHandler (uint32_t instance)
 The interrupt handler for I2C slave mode. More...
 

Data Structure Documentation

struct i2c_slave_state_t

This structure holds data used by the I2C Slave Peripheral driver to communicate between the transfer function and the interrupt handler. The interrupt handler also uses this information to keep track of its progress.

Data Fields

i2c_status_t status
 The slave I2C status. More...
 
volatile uint32_t txSize
 Size of the TX buffer. More...
 
volatile uint32_t rxSize
 Size of the RX buffer. More...
 
const uint8_t * txBuff
 Pointer to Tx Buffer. More...
 
uint8_t * rxBuff
 Pointer to Rx Buffer. More...
 
bool isTxBusy
 True if the driver is sending data. More...
 
bool isRxBusy
 True if the driver is receiving data. More...
 
bool isTxBlocking
 True if transmit is blocking transaction. More...
 
bool isRxBlocking
 True if receive is blocking transaction. More...
 
event_t irqEvent
 Use to wait for ISR to complete its Tx, Rx business.
 
bool slaveListening
 True if slave is in listening mode. More...
 
i2c_slave_callback_t slaveCallback
 Pointer to user callback function. More...
 
void * callbackParam
 Pointer to user callback param. More...
 

Field Documentation

i2c_status_t i2c_slave_state_t::status
volatile uint32_t i2c_slave_state_t::txSize
volatile uint32_t i2c_slave_state_t::rxSize
const uint8_t* i2c_slave_state_t::txBuff
uint8_t* i2c_slave_state_t::rxBuff
bool i2c_slave_state_t::isTxBusy
bool i2c_slave_state_t::isRxBusy
bool i2c_slave_state_t::isTxBlocking
bool i2c_slave_state_t::isRxBlocking
bool i2c_slave_state_t::slaveListening
i2c_slave_callback_t i2c_slave_state_t::slaveCallback
void* i2c_slave_state_t::callbackParam
struct i2c_slave_user_config_t
Note
once slaveListening mode is selected, all send/receive blocking/non-blocking functions will be invalid.

Data Fields

uint16_t address
 Slave's 7-bit or 10-bit address. More...
 
bool slaveListening
 The slave configuration mode.
 
i2c_slave_callback_t slaveCallback
 The slave callback function.
 
void * callbackParam
 The slave callback data.
 

Field Documentation

uint16_t i2c_slave_user_config_t::address

If 10-bit address, the first 6 bits must be 011110 in binary.

Enumeration Type Documentation

Note
The contents of this structure are internal to the driver and should not be modified by users. Also, contents of the structure are subject to change in future releases.

Defines the type of flags for callback function

Enumerator
kI2CSlaveTxReq 

The slave I2C Transmitting Request event.

kI2CSlaveRxReq 

The slave I2C Receiving Request event.

kI2CSlaveTxNAK 

The slave I2C Transmitting NAK event.

kI2CSlaveTxEmpty 

The slave I2C Transmitting Buffer Empty event.

kI2CSlaveRxFull 

The slave I2C Receiving Buffer Full event.

kI2CSlaveAbort 

The slave I2C Slave abort transaction event.

Function Documentation

i2c_status_t I2C_DRV_SlaveInit ( uint32_t  instance,
const i2c_slave_user_config_t userConfigPtr,
i2c_slave_state_t slave 
)

Saves the application callback info, turns on the clock to the module, enables the device, and enables interrupts. Sets the I2C to slave mode. IOMUX should be handled in the init_hardware() function.

Parameters
instanceInstance number of the I2C module.
userConfigPtrPointer of the user configuration structure
slavePointer of the slave run-time structure.
Returns
Error or success status returned by API.
i2c_status_t I2C_DRV_SlaveDeinit ( uint32_t  instance)

Clears the control register and turns off the clock to the module.

Parameters
instanceInstance number of the I2C module.
Returns
Error or success status returned by API.
i2c_slave_state_t* I2C_DRV_SlaveGetHandler ( uint32_t  instance)

This function gets the I2C slave run-time state structure.

Parameters
instanceInstance number of the I2C module.
Returns
Pointer to I2C slave run-time state structure.
i2c_status_t I2C_DRV_SlaveSendData ( uint32_t  instance,
const uint8_t *  txBuff,
uint32_t  txSize 
)

This function returns immediately when the buffer pointer and length are set to the transfer buffer and transfer size. The user should check the status of I2C slave to find out whether the transmission is completed. The user can also wait the kI2CSlaveStop or the kI2CSlaveTxDone to ensure that the transmission is ended.

Parameters
instanceInstance number of the I2C module.
txBuffThe pointer to sending the data buffer.
txSizeThe number of bytes which the user wants to send.
Returns
success (if I2C slave status is not error) or error code in others.
i2c_status_t I2C_DRV_SlaveSendDataBlocking ( uint32_t  instance,
const uint8_t *  txBuff,
uint32_t  txSize,
uint32_t  timeout_ms 
)

This function sets the buffer pointer and length to the transfer buffer and the transfer size and waits until the transmission is ended (NAK is detected).

Parameters
instanceInstance number of the I2C module.
txBuffThe pointer to sending the data buffer.
txSizeThe number of bytes which the user wants to send.
timeout_msThe maximum number of milliseconds to wait for transmit completed
Returns
success (if I2C slave status is not error) or error code in others.
i2c_status_t I2C_DRV_SlaveReceiveData ( uint32_t  instance,
uint8_t *  rxBuff,
uint32_t  rxSize 
)

This function returns immediately when the buffer pointer and length are set to the receive buffer and the receive size. The user should check the status of the I2C slave to find out whether the transmission is completed. The user can also wait the kI2CSlaveStop or the kI2CSlaveRxDone to ensure that the transmission is ended.

Parameters
instanceInstance number of the I2C module.
rxBuffThe pointer to the received data buffer.
rxSizeThe number of bytes which the user wants to receive.
Returns
success (if I2C slave status is not error) or error code in others.
i2c_status_t I2C_DRV_SlaveReceiveDataBlocking ( uint32_t  instance,
uint8_t *  rxBuff,
uint32_t  rxSize,
uint32_t  timeout_ms 
)

This function sets the buffer pointer and length to the receive buffer and the receive size. Then, the function waits until the transmission is ended (all data is received or a STOP signal is detected).

Parameters
instanceInstance number of the I2C module.
rxBuffThe pointer to the received data buffer.
rxSizeThe number of bytes which the user wants to receive.
timeout_msThe maximum number of milliseconds to wait for receive completed
Returns
success (if I2C slave status is not error) or error code in others.
i2c_status_t I2C_DRV_SlaveGetReceiveStatus ( uint32_t  instance,
uint32_t *  bytesRemaining 
)
Parameters
instanceInstance number of the I2C module.
bytesRemainingThe number of remaining bytes that I2C transmits.
Returns
The current status of I2C instance: in progress (busy), complete (success) or idle (I2C bus is idle).
i2c_status_t I2C_DRV_SlaveGetTransmitStatus ( uint32_t  instance,
uint32_t *  bytesRemaining 
)
Parameters
instanceInstance number of the I2C module.
bytesRemainingThe number of remaining bytes that I2C transmits.
Returns
The current status of I2C instance: in progress (busy), complete (success) or idle (I2C bus is idle).
i2c_status_t I2C_DRV_SlaveAbortReceiveData ( uint32_t  instance,
uint32_t *  rxSize 
)

During an non-blocking receiving

Parameters
instanceInstance number of the I2C module.
rxSizeThe number of remaining bytes in I2C Rx Buffer.
Returns
kStatus_I2C_Success if success kStatus_I2C_NoReceiveInProgress if none receiving is available.
i2c_status_t I2C_DRV_SlaveAbortSendData ( uint32_t  instance,
uint32_t *  txSize 
)

During an non-blocking receiving

Parameters
instanceInstance number of the I2C module.
txSizeThe number of remaining bytes in I2C Tx Buffer.
Returns
kStatus_I2C_Success if success kStatus_I2C_NoReceiveInProgress if none receiving is available.
static bool I2C_DRV_SlaveIsBusBusy ( uint32_t  instance)
inlinestatic
Parameters
instanceInstance number of the I2C module.
Returns
True if the bus is busy False if the bus is idle
static i2c_status_t I2C_DRV_SlaveSendDataPolling ( uint32_t  instance,
const uint8_t *  txBuff,
uint32_t  txSize 
)
inlinestatic
Parameters
instanceInstance number of the I2C module.
txBuffThe buffer pointer which saves the data to be sent.
txSizeSize of data to be sent in bytes.
Returns
Error or success status returned by API.
static i2c_status_t I2C_DRV_SlaveReceiveDataPolling ( uint32_t  instance,
uint8_t *  rxBuff,
uint32_t  rxSize 
)
inlinestatic
Parameters
instanceInstance number of the I2C module.
rxBuffThe buffer pointer which saves the data to be received.
rxSizeSize of data need to be received in bytes.
Returns
Error or success status returned by the API.
void I2C_DRV_SlaveIRQHandler ( uint32_t  instance)
Parameters
instanceInstance number of the I2C module.

Variable Documentation

I2C_Type* const g_i2cBase[I2C_INSTANCE_COUNT]