Kinetis SDK v.1.3 API Reference Manual
Rev. 0
Freescale Semiconductor, Inc.
|
This section describes the programming interface of the FlexIO I2C master mode peripheral driver. The FlexIO I2C master peripheral driver provides functions for a master device to send and receive data.
The driver uses an instantiation of the flexio_i2c_state_t structure to maintain the current state of a particular FlexIO-simulated I2C master driver. This structures holds data that is used by the FlexIO-simulated I2C master peripheral driver to communicate between the transmit and receive transfer functions and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. Because the driver itself does not statically allocate memory, the caller provides memory for the driver state structure during initialization by providing a structure.
The FlexIO-simulated I2C driver uses instances of the user configuration structure flexio_i2c_userconfig_t for the FlexIO-simulated I2C driver. The user settings include: I2C mode(master or slave), baud rate, and the associated FlexIO timers, shifters, and pins for SDA and SCL.
The flexio_i2c_userconfig instantiation can be easily modified to configure the FlexIO I2C master peripheral driver either to a different baud rate or using different FlexIO hardware resource. This is an example code to set up a user FlexIO I2C master configuration instantiation:
This example shows how to call the FLEXIO_I2C_DRV_MasterInit() given the user configuration structure and the FlexIO instance 0.
The driver implements transmit and receive functions to transfer buffers of data in blocking and non-blocking modes.
The non-blocking transmit and receive functions include the FLEXIO_I2C_DRV_MasterSendData() and FLEXIO_I2C_DRV_MasterReceiveData() functions.
The blocking (async) transmit and receive functions include the FLEXIO_I2C_DRV_MasterSendDataBlocking() and FLEXIO_I2C_DRV_MasterReceiveDataBlocking() functions.
In all cases mentioned here, the functions are interrupt-driven.
This code example show how to use the functions, assuming that the FlexIO-simulated I2C Master module has been initialized as described previously in the Initialization Section.
This is an example code for blocking transfer functions transmit and receive:
This is an example code for non-blocking (async) transfer functions transmit and receive: