I2C Module¶
The inter-integrated circuit (I2C) API provides a set of functions to configure the device’s I2C module. The driver supports operation in both master and slave mode and provides functions to initialize the module, to send and receive data, to obtain status information, and to manage interrupts.
-
group
i2c_api Defines
-
I2C_MASTER_ERR_NONE0X00000000U¶ No error.
-
I2C_MASTER_ERR_ADDR_ACK0x00000004U¶ Acknowledge Address error.
-
I2C_MASTER_ERR_DATA_ACK0x00000008U¶ Acknowledge Data error.
-
I2C_MASTER_ERR_ARB_LOST0x00000010U¶ Arbitration Lost error.
-
I2C_MASTER_ERR_CLK_TOUT0x00000080U¶ Clock Timeout error.
-
I2C_MASTER_INT_RX_FIFO_FULL0x00000800U¶ RX FIFO Full Interrupt.
-
I2C_MASTER_INT_TX_FIFO_EMPTY0x00000400U¶ TX FIFO Empty Intrpt.
-
I2C_MASTER_INT_RX_FIFO_REQ0x00000200U¶ RX FIFO Request Intrpt.
-
I2C_MASTER_INT_TX_FIFO_REQ0x00000100U¶ TX FIFO Request Intrpt.
-
I2C_MASTER_INT_ARB_LOST0x00000080U¶ Arb Lost Interrupt.
-
I2C_MASTER_INT_STOP0x00000040U¶ Stop Condition Intrpt.
-
I2C_MASTER_INT_START0x00000020U¶ Start Condition Intrpt.
-
I2C_MASTER_INT_NACK0x00000010U¶ Addr/Data NACK Intrpt.
-
I2C_MASTER_INT_TX_DMA_DONE0x00000008U¶ TX DMA Complete Intrpt.
-
I2C_MASTER_INT_RX_DMA_DONE0x00000004U¶ RX DMA Complete Intrpt.
-
I2C_MASTER_INT_TIMEOUT0x00000002U¶ Clock Timeout Intrpt.
-
I2C_MASTER_INT_DATA0x00000001U¶ Data Interrupt.
-
I2C_SLAVE_ACT_NONE0x00000000U¶ Master has sent no command.
-
I2C_SLAVE_ACT_RREQ0x00000001U¶ Master has sent data.
-
I2C_SLAVE_ACT_TREQ0x00000002U¶ Master has requested data.
-
I2C_SLAVE_ACT_RREQ_FBR0x00000005U¶ Master has sent first byte.
-
I2C_SLAVE_ACT_OWN2SEL0x00000008U¶ slave
Master requested secondary
-
I2C_SLAVE_ACT_QCMD0x00000010U¶ Master has sent Quick Command.
-
I2C_SLAVE_ACT_QCMD_DATA0x00000020U¶ Master Quick Command value.
-
I2C_SLAVE_DMA_TX0x00000040U¶ DMA TX active.
-
I2C_SLAVE_DMA_RX0x00000080U¶ DMA RX active.
-
I2C_MASTER_MAX_RETRIES1000U¶ Number of retries.
-
I2C_SA_A6_0_MASK0x80U¶ Mask for Slave Address A6-0.
-
I2C_TXFIFO_MASK0xffff0000U¶ TX FIFO Mask.
-
I2C_RXFIFO_MASK0x0000ffffU¶ RX FIFO Mask.
-
I2C_SCL_FREQ_FAST_MODE400000U¶ SCL freq Fast mode.
-
I2C_SCL_FREQ_STD_MODE100000U¶ SCL freq Std mode.
-
I2C_SCL_FREQ_HS_MODE3400000U¶ SCL freq High speed mode.
-
I2C_SLAVE_INT_RX_FIFO_FULL0x00000100U¶ RX FIFO Full Intrpt.
-
I2C_SLAVE_INT_TX_FIFO_EMPTY0x00000080U¶ TX FIFO Empty Intrpt.
-
I2C_SLAVE_INT_RX_FIFO_REQ0x00000040U¶ RX FIFO Req Intrpt.
-
I2C_SLAVE_INT_TX_FIFO_REQ0x00000020U¶ TX FIFO Req Intrpt.
-
I2C_SLAVE_INT_TX_DMA_DONE0x00000010U¶ TX DMA Complete Intrpt.
-
I2C_SLAVE_INT_RX_DMA_DONE0x00000008U¶ RX DMA Complete Intrpt.
-
I2C_SLAVE_INT_STOP0x00000004U¶ Stop Condition Intrpt.
-
I2C_SLAVE_INT_START0x00000002U¶ Start Condition Intrpt.
-
I2C_SLAVE_INT_DATA0x00000001U¶ Data Interrupt.
-
I2C_SLAVE_TX_FIFO_ENABLE0x00000002U¶ TX FIFO enable.
-
I2C_SLAVE_RX_FIFO_ENABLE0x00000004U¶ RX FIFO enable.
-
I2C_SLAVE_ACK_OVERRIDE_ENABLEtrue¶ Slave ACK override enable.
-
I2C_SLAVE_ACK_OVERRIDE_DISABLEfalse¶ Slave ACK override disable.
-
I2C_SLAVE_ACKtrue¶ Slave ACK.
-
I2C_SLAVE_NACKfalse¶ Slave NACK.
-
I2C_FIFO_RX_BELOW_TRIG_LEVEL0x00040000U¶ level
RX FIFO below Trigger
-
I2C_FIFO_RX_FULL0x00020000U¶ RX FIFO Full.
-
I2C_FIFO_RX_EMPTY0x00010000U¶ RX FIFO Empty.
-
I2C_FIFO_TX_BELOW_TRIG_LEVEL0x00000004U¶ level
TX FIFO below Trigger
-
I2C_FIFO_TX_FULL0x00000002U¶ TX FIFO Full.
-
I2C_FIFO_TX_EMPTY0x00000001U¶ TX FIFO Empty.
-
I2C_FIFOSTATUS_TX_M0x00000007U¶ TX FIFO mask.
-
I2C_FIFOSTATUS_RX_M0x00070000U¶ RX FIFO mask.
-
I2C_CLK_FREQCM_CLK_FREQ¶ CM CPU freq.
-
I2C_MASTER_RAW_INTfalse¶ raw interrupt
-
I2C_MASTER_MASKED_INTtrue¶ masked interrupt
Typedefs
-
typedef bool
I2C_MasterIntType¶
Enums
-
enum
I2C_MasterRW¶ Values:
-
enumerator
I2C_MASTER_WRITE= 0x00U¶ Master Read from slave.
-
enumerator
I2C_MASTER_READ= 0x01U¶ Master write to slave.
-
enumerator
-
enum
I2C_SlaveAddrmode¶ Values:
-
enumerator
I2C_SLAVE_ADDR_PRIMARY= 0x00U¶ primary address
-
enumerator
I2C_SLAVE_ADDR_SECONDARY= 0x01U¶ secondary address
-
enumerator
-
enum
I2C_MasterControl¶ Values:
-
enumerator
I2C_MASTER_CMD_SINGLE_SEND= 0x00000007U¶ SINGLE SEND.
-
enumerator
I2C_MASTER_CMD_SINGLE_RECEIVE= 0x00000007U¶ SINGLE RECV.
-
enumerator
I2C_MASTER_CMD_BURST_SEND_START= 0x00000003U¶ BURST SEND START.
-
enumerator
I2C_MASTER_CMD_BURST_SEND_CONT= 0x00000001U¶ BURST SEND CONT.
-
enumerator
I2C_MASTER_CMD_BURST_SEND_FINISH= 0x00000005U¶ BURST SEND FINISH.
-
enumerator
I2C_MASTER_CMD_BURST_SEND_STOP= 0x00000004U¶ BURST SEND STOP.
-
enumerator
I2C_MASTER_CMD_BURST_SEND_ERROR_STOP= 0x00000004U¶ BURST SEND ERROR_STOP.
-
enumerator
I2C_MASTER_CMD_BURST_RECEIVE_START= 0x0000000bU¶ BURST RECEIVE START.
-
enumerator
I2C_MASTER_CMD_BURST_RECEIVE_CONT= 0x00000009U¶ BURST RECEIVE CONT.
-
enumerator
I2C_MASTER_CMD_BURST_RECEIVE_FINISH= 0x00000005U¶ BURST RECEIVE FINISH.
-
enumerator
I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP= 0x00000004U¶ BURST RECEIVE ERROR STOP.
-
enumerator
I2C_MASTER_CMD_QUICK_COMMAND= 0x00000027U¶ QUICK COMMAND.
-
enumerator
I2C_MASTER_CMD_HS_MASTER_CODE_SEND= 0x00000013U¶ HS MASTER CODE SEND.
-
enumerator
I2C_MASTER_CMD_FIFO_SINGLE_SEND= 0x00000046U¶ FIFO SINGLE SEND.
-
enumerator
I2C_MASTER_CMD_FIFO_SINGLE_RECEIVE= 0x00000046U¶ FIFO SINGLE RECEIVE.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_SEND_START= 0x00000042U¶ FIFO BURST SEND START.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_SEND_CONT= 0x00000040U¶ FIFO BURST SEND CONT.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_SEND_FINISH= 0x00000044U¶ FIFO BURST SEND FINISH.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_SEND_ERROR_STOP= 0x00000004U¶ BURST SEND ERROR STOP.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START= 0x0000004aU¶ BURST RECEIVE START.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_CONT= 0x00000048U¶ BURST RECEIVE CONT.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH= 0x00000044U¶ FIFO BURST RECEIVE FINISH.
-
enumerator
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_ERROR_STOP= 0x00000004U¶ FIFO BURST RECEIVE ERROR STOP.
-
enumerator
-
enum
I2C_GlitchFilter¶ Values:
-
enumerator
I2C_MASTER_GLITCH_FILTER_DISABLED= 0x00000000U¶ Bypass.
-
enumerator
I2C_MASTER_GLITCH_FILTER_1= 0x00010000U¶ 1 clock
-
enumerator
I2C_MASTER_GLITCH_FILTER_2= 0x00020000U¶ 2 clocks
-
enumerator
I2C_MASTER_GLITCH_FILTER_3= 0x00030000U¶ 3 clocks
-
enumerator
I2C_MASTER_GLITCH_FILTER_4= 0x00040000U¶ 4 clocks
-
enumerator
I2C_MASTER_GLITCH_FILTER_8= 0x00050000U¶ 8 clocks
-
enumerator
I2C_MASTER_GLITCH_FILTER_16= 0x00060000U¶ 16 clocks
-
enumerator
I2C_MASTER_GLITCH_FILTER_31= 0x00070000U¶ 31 clocks
-
enumerator
-
enum
I2C_TxFIFOCfg¶ Values:
-
enumerator
I2C_FIFO_CFG_TX_MASTER= 0x00000000U¶ TX Master.
-
enumerator
I2C_FIFO_CFG_TX_SLAVE= 0x00008000U¶ TX slave.
-
enumerator
I2C_FIFO_CFG_TX_MASTER_DMA= 0x00002000U¶ TX Master DMA.
-
enumerator
I2C_FIFO_CFG_TX_SLAVE_DMA= 0x0000a000U¶ TX slave DMA.
-
enumerator
-
enum
I2C_TxTrigger¶ Values:
-
enumerator
I2C_FIFO_CFG_TX_NO_TRIG= 0x00000000U¶ Trigger when TX FIFO empty.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_1= 0x00000001U¶ Trigger when TX FIFO has 1 byte.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_2= 0x00000002U¶ Trigger when TX FIFO has 2 byte.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_3= 0x00000003U¶ Trigger when TX FIFO has 3 byte.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_4= 0x00000004U¶ Trigger when TX FIFO has 4 byte.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_5= 0x00000005U¶ Trigger when TX FIFO has 5 byte.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_6= 0x00000006U¶ Trigger when TX FIFO has 6 byte.
-
enumerator
I2C_FIFO_CFG_TX_TRIG_7= 0x00000007U¶ Trigger when TX FIFO has 7 byte.
-
enumerator
-
enum
I2C_RxFIFOCfg¶ Values:
-
enumerator
I2C_FIFO_CFG_RX_MASTER= 0x00000000U¶ RX Master.
-
enumerator
I2C_FIFO_CFG_RX_SLAVE= 0x80000000U¶ RX slave.
-
enumerator
I2C_FIFO_CFG_RX_MASTER_DMA= 0x20000000U¶ RX Master DMA.
-
enumerator
I2C_FIFO_CFG_RX_SLAVE_DMA= 0xa0000000U¶ RX slave DMA.
-
enumerator
-
enum
I2C_RxTrigger¶ Values:
-
enumerator
I2C_FIFO_CFG_RX_NO_TRIG= 0x00000000U¶ Trigger when RX FIFO empty.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_1= 0x00010000U¶ Trigger when RX FIFO has 1 byte.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_2= 0x00020000U¶ Trigger when RX FIFO has 2 byte.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_3= 0x00030000U¶ Trigger when RX FIFO has 3 byte.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_4= 0x00040000U¶ Trigger when RX FIFO has 4 byte.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_5= 0x00050000U¶ Trigger when RX FIFO has 5 byte.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_6= 0x00060000U¶ Trigger when RX FIFO has 6 byte.
-
enumerator
I2C_FIFO_CFG_RX_TRIG_7= 0x00070000U¶ Trigger when RX FIFO has 7 byte.
-
enumerator
Functions
-
void
I2C_enableMaster(uint32_t base)¶ Enables the I2C Master block.
This function enables operation of the I2C Master block.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_enableSlave(uint32_t base)¶ Enables the I2C Slave block.
This function enables operation of the I2C Slave block.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_initSlave(uint32_t base, uint8_t slaveAddr)¶ Initializes the I2C Slave block.
This function initializes operation of the I2C Slave block by configuring the slave address and enabling the I2C Slave block.
- Parameters
base: is the base address of the I2C module.slaveAddr: 7-bit slave address
The parameter slaveAddr is the value that is compared against the slave address sent by an I2C master.
- Return
None.
-
void
I2C_disableMaster(uint32_t base)¶ Disables the I2C master block.
This function disables operation of the I2C master block.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_disableSlave(uint32_t base)¶ Disables the I2C slave block.
This function disables operation of the I2C slave block.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_enableMasterInt(uint32_t base)¶ Enables the I2C Master interrupt.
This function enables the I2C Master interrupt source.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_enableMasterIntSource(uint32_t base, uint32_t intFlags)¶ Enables individual I2C Master interrupt sources.
This function enables the indicated I2C Master interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt disabled sources have no effect on the processor.
- Parameters
base: is the base address of the I2C module.intFlags: is the bit mask of the interrupt sources to be enabled.
The intFlags parameter is the logical OR of any of the following:
I2C_MASTER_INT_RX_FIFO_FULL - RX FIFO Full interrupt
I2C_MASTER_INT_TX_FIFO_EMPTY - TX FIFO Empty interrupt
I2C_MASTER_INT_RX_FIFO_REQ - RX FIFO Request interrupt
I2C_MASTER_INT_TX_FIFO_REQ - TX FIFO Request interrupt
I2C_MASTER_INT_ARB_LOST - Arbitration Lost interrupt
I2C_MASTER_INT_STOP - Stop Condition interrupt
I2C_MASTER_INT_START - Start Condition interrupt
I2C_MASTER_INT_NACK - Address/Data NACK interrupt
I2C_MASTER_INT_TX_DMA_DONE - TX DMA Complete interrupt
I2C_MASTER_INT_RX_DMA_DONE - RX DMA Complete interrupt
I2C_MASTER_INT_TIMEOUT - Clock Timeout interrupt
I2C_MASTER_INT_DATA - Data interrupt
- Note
Please consult the device data sheet to determine if these features are supported.
- Return
None.
-
void
I2C_enableSlaveInt(uint32_t base)¶ Enables the I2C Slave interrupt.
This function enables the I2C Slave interrupt source.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_enableSlaveIntSource(uint32_t base, uint32_t intFlags)¶ Enables individual I2C Slave interrupt sources.
This function enables the indicated I2C Slave interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt disabled sources have no effect on the processor.
- Parameters
base: is the base address of the I2C module.intFlags: is the bit mask of the interrupt sources to be enabled.
The intFlags parameter is the logical OR of any of the following:
I2C_SLAVE_INT_RX_FIFO_FULL - RX FIFO Full interrupt
I2C_SLAVE_INT_TX_FIFO_EMPTY - TX FIFO Empty interrupt
I2C_SLAVE_INT_RX_FIFO_REQ - RX FIFO Request interrupt
I2C_SLAVE_INT_TX_FIFO_REQ - TX FIFO Request interrupt
I2C_SLAVE_INT_TX_DMA_DONE - TX DMA Complete interrupt
I2C_SLAVE_INT_RX_DMA_DONE - RX DMA Complete interrupt
I2C_SLAVE_INT_STOP - Stop condition detected interrupt
I2C_SLAVE_INT_START - Start condition detected interrupt
I2C_SLAVE_INT_DATA - Data interrupt
- Return
None.
-
void
I2C_disableMasterInt(uint32_t base)¶ Disables the I2C Master interrupt.
This function disables the I2C Master interrupt source.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_disableMasterIntSource(uint32_t base, uint32_t intFlags)¶ Disables individual I2C Master interrupt sources.
This function disables the indicated I2C Master interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt disabled sources have no effect on the processor.
- Parameters
base: is the base address of the I2C module.intFlags: is the bit mask of the interrupt sources to be disabled.
The intFlags parameter has the same definition as the intFlags parameter to I2C_enableMasterIntSource().
- Return
None.
-
void
I2C_disableSlaveInt(uint32_t base)¶ Disables the I2C Slave interrupt.
This function disables the I2C Slave interrupt source.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_disableSlaveIntSource(uint32_t base, uint32_t intFlags)¶ Disables individual I2C Slave interrupt sources.
This function disables the indicated I2C Slave interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt disabled sources have no effect on the processor.
- Parameters
base: is the base address of the I2C module.intFlags: is the bit mask of the interrupt sources to be disabled.
The intFlags parameter has the same definition as the intFlags parameter to I2C_enableSlaveIntSource().
- Return
None.
-
bool
I2C_isMasterIntActive(uint32_t base, I2C_MasterIntType masked)¶ Checks if the current I2C Master has any interrupts active.
This function returns the interrupt status as active or not for the I2C. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned as being active or not
- Parameters
base: is the base address of the I2C module.masked: of type I2C_MasterIntType is I2C_MASTER_RAW_INT if the raw interrupt status is requested and I2C_MASTER_MASKED_INT if the masked interrupt status is requested.
- Return
The current interrupt status, returned as true if active or false if not active.
-
uint32_t
I2C_getMasterIntStatus(uint32_t base, I2C_MasterIntType masked)¶ Gets the current I2C Master interrupt status.
This function returns the interrupt status for the I2C module. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.
- Parameters
base: is the base address of the I2C module.masked: of type I2C_MasterIntType is I2C_MASTER_RAW_INT if the raw interrupt status is requested and I2C_MASTER_MASKED_INT if the masked interrupt status is requested..
- Return
Returns the current interrupt status, enumerated as a bit field of values described in I2C_enableMasterIntSource().
-
bool
I2C_isSlaveIntActive(uint32_t base, I2C_MasterIntType masked)¶ Gets the current I2C Slave interrupt status.
This function returns the interrupt status for the I2C Slave. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.
- Parameters
base: is the base address of the I2C module.masked: of type I2C_MasterIntType is I2C_MASTER_RAW_INT if the raw interrupt status is requested and I2C_MASTER_MASKED_INT if the masked interrupt status is requested.
- Return
The current interrupt status, returned as true if active or false if not active.
-
uint32_t
I2C_getSlaveIntStatus(uint32_t base, I2C_MasterIntType masked)¶ Gets the current I2C Slave interrupt status.
This function returns the interrupt status for the I2C Slave. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.
- Parameters
base: is the base address of the I2C module.masked: of type I2C_MasterIntType is I2C_MASTER_RAW_INT if the raw interrupt status is requested and I2C_MASTER_MASKED_INT if the masked interrupt status is requested.
- Return
Returns the current interrupt status, enumerated as a bit field of values described in I2C_enableSlaveIntSource().
-
void
I2C_clearMasterInt(uint32_t base)¶ Clears I2C Master interrupt sources.
The I2C Master interrupt source is cleared, so that it no longer asserts. This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.
- Parameters
base: is the base address of the I2C module.
- Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler(as opposed to the very last action) to astatic inline void returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
- Return
None.
-
void
I2C_clearMasterIntSource(uint32_t base, uint32_t intFlags)¶ Clears I2C Master interrupt sources.
The specified I2C Master interrupt sources are cleared, so that they no longer assert. This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.
- Parameters
base: is the base address of the I2C module.intFlags: is a bit mask of the interrupt sources to be cleared.
The intFlags parameter has the same definition as the intFlags parameter to I2C_enableMasterIntSource().
- Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler(as opposed to the very last action) to astatic inline void returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
- Return
None.
-
void
I2C_clearSlaveInt(uint32_t base)¶ Clears I2C Slave interrupt sources.
The I2C Slave interrupt source is cleared, so that it no longer asserts. This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.
- Parameters
base: is the base address of the I2C module.
- Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler(as opposed to the very last action) to astatic inline void returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
- Return
None.
-
void
I2C_clearSlaveIntSource(uint32_t base, uint32_t intFlags)¶ Clears I2C Slave interrupt sources.
The specified I2C Slave interrupt sources are cleared, so that they no longer assert. This function must be called in the interrupt handler to keep the interrupt from being triggered again immediately upon exit.
- Parameters
base: is the base address of the I2C module.intFlags: is a bit mask of the interrupt sources to be cleared.
The intFlags parameter has the same definition as the intFlags parameter to I2C_enableSlaveIntSource().
- Note
Because there is a write buffer in the Cortex-M processor, it may take several clock cycles before the interrupt source is actually cleared. Therefore, it is recommended that the interrupt source be cleared early in the interrupt handler(as opposed to the very last action) to astatic inline void returning from the interrupt handler before the interrupt source is actually cleared. Failure to do so may result in the interrupt handler being immediately reentered (because the interrupt controller still sees the interrupt source asserted).
- Return
None.
-
void
I2C_setSlaveAddress(uint32_t base, uint8_t slaveAddr, I2C_MasterRW bReceive)¶ Sets the address that the I2C Master places on the bus.
This function configures the address that the I2C Master places on the bus when initiating a transaction. When the
bReceive parameter is set to I2C_MASTER_READ, the address indicates that the I2C Master is initiating a read from the slave else set to I2C_MASTER_WRITE the address indicates that the I2C Master is initiating a write to the slave.This is done using I2C_MasterRW type.- Parameters
base: is the base address of the I2C module.slaveAddr: 7-bit slave addressbReceive: flag indicating the type of communication with the slave
- Return
None.
-
uint32_t
I2C_getMasterLineState(uint32_t base)¶ Reads the state of the SDA and SCL pins.
This function returns the state of the I2C bus by providing the real time values of the SDA and SCL pins.
- Parameters
base: is the base address of the I2C module.
- Return
Returns the state of the bus with SDA in bit position 1 and SCL in bit position 0.
-
bool
I2C_isMasterBusy(uint32_t base)¶ Indicates whether or not the I2C Master is busy.
This function returns an indication of whether or not the I2C Master is busy transmitting or receiving data.
- Parameters
base: is the base address of the I2C module.
- Return
Returns true if the I2C Master is busy; otherwise, returns false.
-
bool
I2C_isBusBusy(uint32_t base)¶ Indicates whether or not the I2C bus is busy.
This function returns an indication of whether or not the I2C bus is busy. This function can be used in a multi-master environment to determine if another master is currently using the bus.
- Parameters
base: is the base address of the I2C module.
- Return
Returns true if the I2C bus is busy; otherwise, returns false.
-
void
I2C_setMasterConfig(uint32_t base, I2C_MasterControl cmd)¶ Controls the state of the I2C Master.
This function is used to control the state of the Master send and receive operations. The
ui8Cmd parameter can be one of the following values:- Parameters
base: is the base address of the I2C module.cmd: command to be issued to the I2C Master. This is provided as a I2C_MasterControl Type .
I2C_MASTER_CMD_SINGLE_SEND
I2C_MASTER_CMD_SINGLE_RECEIVE
I2C_MASTER_CMD_BURST_SEND_START
I2C_MASTER_CMD_BURST_SEND_CONT
I2C_MASTER_CMD_BURST_SEND_FINISH
I2C_MASTER_CMD_BURST_SEND_ERROR_STOP
I2C_MASTER_CMD_BURST_RECEIVE_START
I2C_MASTER_CMD_BURST_RECEIVE_CONT
I2C_MASTER_CMD_BURST_RECEIVE_FINISH
I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP
I2C_MASTER_CMD_QUICK_COMMAND
I2C_MASTER_CMD_HS_MASTER_CODE_SEND
I2C_MASTER_CMD_FIFO_SINGLE_SEND
I2C_MASTER_CMD_FIFO_SINGLE_RECEIVE
I2C_MASTER_CMD_FIFO_BURST_SEND_START
I2C_MASTER_CMD_FIFO_BURST_SEND_CONT
I2C_MASTER_CMD_FIFO_BURST_SEND_FINISH
I2C_MASTER_CMD_FIFO_BURST_SEND_ERROR_STOP
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_CONT
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH
I2C_MASTER_CMD_FIFO_BURST_RECEIVE_ERROR_STOP
- Note
Please consult the device data sheet to determine if this feature is supported.
- Return
None.
-
void
I2C_putMasterData(uint32_t base, uint8_t data)¶ Transmits a byte from the I2C Master.
This function places the supplied data into I2C Master Data Register.
- Parameters
base: is the base address of the I2C module.data: data to be transmitted from the I2C Master.
- Return
None.
-
uint32_t
I2C_getMasterData(uint32_t base)¶ Receives a byte that has been sent to the I2C Master.
This function reads a byte of data from the I2C Master Data Register.
- Parameters
base: is the base address of the I2C module.
- Return
Returns the byte received from by the I2C Master, cast as an uint32_t.
-
void
I2C_setMasterClkTimeout(uint32_t base, uint32_t value)¶ Sets the Master clock timeout value.
This function enables and configures the clock low timeout feature in the I2C peripheral. This feature is implemented as a 12-bit counter, with the upper 8-bits being programmable. For example, to program a timeout of 20ms with a 100-kHz SCL frequency,
value is 0x7d.- Parameters
base: is the base address of the I2C module.value: is the number of I2C clocks before the timeout is asserted.
- Return
None.
-
void
I2C_configureSlaveAckOverride(uint32_t base, bool enable)¶ Configures ACK override behaviour of the I2C Slave.
This function enables or disables ACK override, allowing the user application to drive the value on SDA during the ACK cycle.
- Parameters
base: is the base address of the I2C module.enable: enables or disables ACK override using the macros I2C_SLAVE_ACK_OVERRIDE_ENABLE / I2C_SLAVE_ACK_OVERRIDE_DISABLE
- Return
None.
-
void
I2C_setSlaveAckValue(uint32_t base, bool ack)¶ Writes the ACK value.
This function puts the desired ACK value on SDA during the ACK cycle. The value written is only valid when ACK override is enabled using I2C_configureSlaveACK().
- Parameters
base: is the base address of the I2C module.ack: chooses whether to ACK (true) or NACK (false) the transfer. using the macros I2C_SLAVE_ACK or I2C_SLAVE_NACK resp.
- Return
None.
-
uint32_t
I2C_getSlaveStatus(uint32_t base)¶ Gets the I2C Slave status
This function returns the action requested from a master, if any. Possible values are:
- Parameters
base: is the base address of the I2C module.
I2C_SLAVE_ACT_NONE
I2C_SLAVE_ACT_RREQ
I2C_SLAVE_ACT_TREQ
I2C_SLAVE_ACT_RREQ_FBR
I2C_SLAVE_ACT_OWN2SEL
I2C_SLAVE_ACT_QCMD
I2C_SLAVE_ACT_QCMD_DATA
I2C_SLAVE_DMA_TX
I2C_SLAVE_DMA_RX
- Return
Returns I2C_SLAVE_ACT_NONE to indicate that no action has been requested of the I2C Slave, I2C_SLAVE_ACT_RREQ to indicate that an I2C master has sent data to the I2C Slave, I2C_SLAVE_ACT_TREQ to indicate that an I2C master has requested that the I2C Slave send data, I2C_SLAVE_ACT_RREQ_FBR to indicate that an I2C master has sent data to the I2C slave and the first byte following the slave’s own address has been received, I2C_SLAVE_ACT_OWN2SEL to indicate that the second I2C slave address was matched, I2C_SLAVE_ACT_QCMD to indicate that a quick command was received, I2C_SLAVE_ACT_QCMD_DATA to indicate that the data bit was set when the quick command was received , I2C_SLAVE_DMA_TX to indicate that the DMA TX is active and I2C_SLAVE_DMA_RX to indicate that the DMA RX is active.
-
void
I2C_putSlaveData(uint32_t base, uint8_t data)¶ Transmits a byte from the I2C Slave.
This function places the supplied data into I2C Slave Data Register.
- Parameters
base: is the base address of the I2C module.data: is the data to be transmitted from the I2C Slave
- Return
None.
-
uint32_t
I2C_getSlaveData(uint32_t base)¶ Receives a byte that has been sent to the I2C Slave.
This function reads a byte of data from the I2C Slave Data Register.
- Parameters
base: is the base address of the I2C module.
- Return
Returns the byte received from by the I2C Slave, cast as an uint32_t.
-
void
I2C_configureTxFIFO(uint32_t base, I2C_TxFIFOCfg config, I2C_TxTrigger trigger)¶ Configures the I2C transmit (TX) FIFO.
This configures the I2C peripheral’s transmit FIFO. The transmit FIFO can be used by the master or slave, but not both. The following macros are used to configure the TX FIFO behaviour for master or slave, with or without DMA:
- Parameters
base: is the base address of the I2C module.config: is the configuration of the FIFO.trigger: is to select the trigger level of TX the FIFO.
I2C_FIFO_CFG_TX_MASTER, I2C_FIFO_CFG_TX_SLAVE, I2C_FIFO_CFG_TX_MASTER_DMA, I2C_FIFO_CFG_TX_SLAVE_DMA
To select the trigger level, one of the following macros should be used:
I2C_FIFO_CFG_TX_TRIG_1, I2C_FIFO_CFG_TX_TRIG_2, I2C_FIFO_CFG_TX_TRIG_3, I2C_FIFO_CFG_TX_TRIG_4, I2C_FIFO_CFG_TX_TRIG_5, I2C_FIFO_CFG_TX_TRIG_6, I2C_FIFO_CFG_TX_TRIG_7
- Return
None.
-
void
I2C_flushTxFIFO(uint32_t base)¶ Flushes the transmit (TX) FIFO.
This function flushes the I2C transmit FIFO.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_configureRxFIFO(uint32_t base, I2C_RxFIFOCfg config, I2C_RxTrigger trigger)¶ Configures the I2C receive (RX) FIFO.
This configures the I2C peripheral’s receive FIFO. The receive FIFO can be used by the master or slave, but not both. The following macros are used to configure the RX FIFO behaviour for master or slave,with or without DMA:
- Parameters
base: is the base address of the I2C module.config: is the configuration of the FIFO using specified macros.trigger: is to select the trigger level of RX the FIFO.
I2C_FIFO_CFG_RX_MASTER, I2C_FIFO_CFG_RX_SLAVE, I2C_FIFO_CFG_RX_MASTER_DMA, I2C_FIFO_CFG_RX_SLAVE_DMA
To select the trigger level, one of the following macros should be used:
I2C_FIFO_CFG_RX_TRIG_1, I2C_FIFO_CFG_RX_TRIG_2, I2C_FIFO_CFG_RX_TRIG_3, I2C_FIFO_CFG_RX_TRIG_4, I2C_FIFO_CFG_RX_TRIG_5, I2C_FIFO_CFG_RX_TRIG_6, I2C_FIFO_CFG_RX_TRIG_7
- Return
None.
-
void
I2C_flushRxFIFO(uint32_t base)¶ Flushes the receive (RX) FIFO.
This function flushes the I2C receive FIFO.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
uint32_t
I2C_getTxFIFOStatus(uint32_t base)¶ Gets the TX FIFO status.
This function retrieves the status for the transmit (TX) FIFO. The trigger level for the transmit FIFO is set using I2C_setTxFIFOConfig().
- Parameters
base: is the base address of the I2C module.
- Return
Returns the FIFO status, enumerated as a bit field containing I2C_FIFO_TX_BELOW_TRIG_LEVEL, I2C_FIFO_TX_FULL, and I2C_FIFO_TX_EMPTY.
-
uint32_t
I2C_getRxFIFOStatus(uint32_t base)¶ Gets the RX FIFO status.
This function retrieves the status for the receive (RX) FIFO. The trigger level for the receive FIFO is set using I2C_setRxFIFOConfig().
- Parameters
base: is the base address of the I2C module.
- Return
Returns the FIFO status, enumerated as a bit field containing I2C_FIFO_RX_BELOW_TRIG_LEVEL, I2C_FIFO_RX_FULL, and I2C_FIFO_RX_EMPTY.
-
void
I2C_putFIFOData(uint32_t base, uint8_t data)¶ Writes a data byte to the I2C transmit FIFO.
This function adds a byte of data to the I2C transmit FIFO. If there is no space available in the FIFO, this function waits for space to become available before returning.
- Parameters
base: is the base address of the I2C module.data: is the data to be placed into the transmit FIFO.
- Return
None.
-
uint32_t
I2C_putFIFODataNonBlocking(uint32_t base, uint8_t data)¶ Writes a data byte to the I2C transmit FIFO.
This function adds a byte of data to the I2C transmit FIFO. If there is no space available in the FIFO, this function returns a zero.
- Parameters
base: is the base address of the I2C module.data: is the data to be placed into the transmit FIFO.
- Return
The number of elements added to the I2C transmit FIFO.
-
uint32_t
I2C_getFIFOData(uint32_t base)¶ Reads a byte from the I2C receive FIFO.
This function reads a byte of data from I2C receive FIFO and places it in the location specified by the
pdata parameter. If there is no data available, this function waits until data is received before returning.- Parameters
base: is the base address of the I2C module.
- Return
The data byte.
-
uint32_t
I2C_getFIFODataNonBlocking(uint32_t base, uint8_t *dataptr)¶ Reads a byte from the I2C receive FIFO.
This function reads a byte of data from I2C receive FIFO and places it in the location specified by the
pdata parameter. If there is no data available, this functions returns 0.- Parameters
base: is the base address of the I2C module.dataptr: is a pointer where the read data is stored.
- Return
The number of elements read from the I2C receive FIFO.
-
void
I2C_setMasterBurstLength(uint32_t base, uint8_t length)¶ Set the burst length for a I2C master FIFO operation.
This function configures the burst length for a I2C Master FIFO operation. The burst field is limited to 8 bits or 256 bytes. The burst length applies to a single I2CMCS BURST operation meaning that it specifies the burst length for only the current operation (can be TX or RX). Each burst operation must configure the burst length prior to writing the BURST bit in the I2CMCS using I2C_controlMaster().
- Parameters
base: is the base address of the I2C module.length: is the length of the burst transfer.
- Return
None.
-
uint32_t
I2C_getMasterBurstCount(uint32_t base)¶ Returns the current value of the burst transfer counter.
This function returns the current value of the burst transfer counter that is used by the FIFO mechanism. Software can use this value to determine how many bytes remain in a transfer, or where in the transfer the burst operation was if an error has occurred.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_enableFIFO(uint32_t base, uint32_t config)¶ Enables FIFO usage for the I2C Slave.
This function configures the I2C Slave to use the FIFO(s). This function should be used in combination with I2C_setTxFIFOConfig() and/or I2C_setRxFIFOConfig(), which configure the FIFO trigger level and tell the FIFO hardware whether to interact with the I2C Master or Slave. The application appropriate combination of
I2C_SLAVE_TX_FIFO_ENABLE and I2C_SLAVE_RX_FIFO_ENABLE should be passed in to the config field.- Parameters
base: is the base address of the I2C module.config: is the desired FIFO configuration of the I2C Slave.
The Slave I2CSCSR register is write-only, so any call to I2C_enableSlave(), I2C_disableSlave or I2C_enableSlaveFIFO() overwrites the slave configuration.Therefore, application software should call I2C_enableSlave() followed by I2C_enableSlaveFIFO() with the desired FIFO configuration.
- Return
None.
-
void
I2C_disableFIFO(uint32_t base)¶ Disable FIFO usage for the I2C Slave.
This function disables the FIFOs for the I2C Slave. After calling this this function, the FIFOs are disabled, but the Slave remains active.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_enableLoopback(uint32_t base)¶ Enables internal loopback mode for an I2C port.
This function configures an I2C port in internal loopback mode to help with diagnostics and debug. In this mode, the SDA and SCL signals from master and slave modules are internally connected. This allows data to be transferred between the master and slave modules of the same I2C port, without having to go through I/O’s.I2C_putMasterData(),
I2C_putSlaveData(), I2C_getMasterData(),I2C_getSlaveData()can be used along with this function.- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_disableLoopback(uint32_t base)¶ Disables internal loopback mode for an I2C port.
This function disables the internal loopback mode in an I2C port In this mode, the SDA and SCL signals from the master and slave modules are not internally connected. Loopback mode is disabled by default after reset.
- Parameters
base: is the base address of the I2C module.
- Return
None.
-
void
I2C_registerInt(uint32_t interruptNum, void (*pfnHandler)(void))¶ Registers an interrupt handler for the I2C module.
This function sets the handler to be called when an I2C interrupt occurs. This function enables the global interrupt in the interrupt controller specific I2C interrupts must be enabled via
I2C_enableMasterInt() and I2C_enableSlaveInt(). If necessary, it is the interrupt handler’s responsibility to clear the interrupt source via I2C_clearMasterInt() and I2C_clearSlaveInt().- Parameters
interruptNum: specifies the interrupt in question.pfnHandler: is a pointer to the function to be called when the I2C interrupt occurs.
- See
IntRegister() for important information about registering interrupt handlers.
- Return
None.
-
void
I2C_unregisterInt(uint32_t interruptNum)¶ Unregisters an interrupt handler for the I2C module.
This function clears the handler to be called when an I2C interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.
- Parameters
interruptNum: specifies the interrupt in question.
- See
IntRegister() for important information about registering interrupt handlers.
- Return
None.
-
void
I2C_configureMasterGlitchFilter(uint32_t base, I2C_GlitchFilter config)¶ Configures the I2C Master glitch filter.
This function configures the I2C Master glitch filter. The value passed in to
config determines the sampling range of the glitch filter, which is configurable between 1 and 31 system clock cycles. The default configuration of the glitch filter is 0 system clock cycles, which means that it’s disabled.- Parameters
base: is the base address of the I2C module.config: is the glitch filter configuration provided by I2C_GlitchFilter type
The config field should be any of the following values:
I2C_MASTER_GLITCH_FILTER_DISABLED
I2C_MASTER_GLITCH_FILTER_1
I2C_MASTER_GLITCH_FILTER_2
I2C_MASTER_GLITCH_FILTER_3
I2C_MASTER_GLITCH_FILTER_4
I2C_MASTER_GLITCH_FILTER_8
I2C_MASTER_GLITCH_FILTER_16
I2C_MASTER_GLITCH_FILTER_31
- Return
None.
-
void
I2C_initMaster(uint32_t base, uint32_t i2cClk, bool fast)¶ Initializes the I2C Master block.
This function initializes operation of the I2C Master block by configuring the bus speed for the master and enabling the I2C Master block.
- Parameters
base: is the base address of the I2C module.i2cClk: is the rate of the clock supplied to the I2C module. It should be provided as I2C_CLK_FREQ using the updated clk ratefast: set up for fast data transfers.
If the parameter fast is true, then the master block is set up to transfer data at 400 Kbps; otherwise, it is set up to transfer data at 100 Kbps. If Fast Mode Plus (1 Mbps) is desired, software should manually write the I2CMTPR after calling this function. For High Speed (3.4 Mbps) mode, a specific command is used to switch to the faster clocks after the initial communication with the slave is done at either 100 Kbps or 400 Kbps.
The peripheral clock is the same as the processor clock.
- Return
None.
-
void
I2C_setOwnSlaveAddress(uint32_t base, I2C_SlaveAddrmode addrNum, uint8_t slaveAddr)¶ Sets the I2C slave address.
This function writes the specified slave address. The
addrNum field dictates which slave address is configured. For example, a value of I2C_SLAVE_ADDR_PRIMARY configures the primary address and a value of I2C_SLAVE_ADDR_SECONDARY configures the secondary.- Parameters
base: is the base address of the I2C module.addrNum: determines which slave address is set. This should be provided as I2C_SlaveAddrmode type for Primary or SecondaryslaveAddr: is the 7-bit slave address
- Return
None.
-
uint32_t
I2C_getMasterErr(uint32_t base)¶ Gets the error status of the I2C Master.
This function is used to obtain the error status of the Master send and receive operations.
- Parameters
base: is the base address of the I2C module.
- Return
Returns the error status, as one of I2C_MASTER_ERR_NONE, I2C_MASTER_ERR_ADDR_ACK, I2C_MASTER_ERR_DATA_ACK, I2C_MASTER_ERR_ARB_LOST or I2C_MASTER_ERR_CLK_TOUT .
-
Before initializing the I2C module, the user first must enable the module as a master or a slave using I2C_enableMaster() or I2C_enableSlave(). When using the API in master mode, the user must then call I2C_initMaster() which will configure the rate and duty cycle of the master clock. For slave mode, I2C_initSlave() will need to be called to set the module’s address.
For both modes, this is also the time to do any FIFO or interrupt configuration. FIFOs are configured using I2C_enableFIFO(), I2C_disableFIFO(),I2C_configureTxFIFO() and I2C_configureRxFIFO(). The functions I2C_enableMasterIntSource(), I2C_disableMasterIntSource(), I2C_enableSlaveIntSource(), I2C_disableSlaveIntSource() , I2C_getMasterIntStatus(), I2C_getSlaveIntStatus() , I2C_clearMasterIntSource, I2C_clearSlaveIntSource() are for management of interrupts. Note that the I2C module uses separate interrupt lines for its basic and FIFO interrupts although the functions to configure them are the same.
To do a transfer, for both master and slave modes, other I2C APIs should be called to configure the behavior of the module. A master will need to set I2C_setSlaveAddress() to set the address of the slave to which it will communicate. I2C_putMasterData() will place data in the transmit buffer for the master. A start condition can be sent by a master using I2C_setMasterConfig().
When receiving data, the status of data received can be checked using I2C_getSlaveIntStatus() or I2C_isSlaveIntActive(). I2C_getSlaveData() will read the data from the receive buffer and return it at the slave.
The code for this module is contained in driverlib_cm/i2c.c, with driverlib_cm/i2c.h containing the API declarations for use by applications.