Tiva Driver Lib
Functions
I2c_api

Functions

void I2CMasterInitExpClk (uint32_t ui32Base, uint32_t ui32I2CClk, bool bFast)
 
void I2CSlaveInit (uint32_t ui32Base, uint8_t ui8SlaveAddr)
 
void I2CSlaveAddressSet (uint32_t ui32Base, uint8_t ui8AddrNum, uint8_t ui8SlaveAddr)
 
void I2CMasterEnable (uint32_t ui32Base)
 
void I2CSlaveEnable (uint32_t ui32Base)
 
void I2CMasterDisable (uint32_t ui32Base)
 
void I2CSlaveDisable (uint32_t ui32Base)
 
void I2CIntRegister (uint32_t ui32Base, void(*pfnHandler)(void))
 
void I2CIntUnregister (uint32_t ui32Base)
 
void I2CMasterIntEnable (uint32_t ui32Base)
 
void I2CMasterIntEnableEx (uint32_t ui32Base, uint32_t ui32IntFlags)
 
void I2CSlaveIntEnable (uint32_t ui32Base)
 
void I2CSlaveIntEnableEx (uint32_t ui32Base, uint32_t ui32IntFlags)
 
void I2CMasterIntDisable (uint32_t ui32Base)
 
void I2CMasterIntDisableEx (uint32_t ui32Base, uint32_t ui32IntFlags)
 
void I2CSlaveIntDisable (uint32_t ui32Base)
 
void I2CSlaveIntDisableEx (uint32_t ui32Base, uint32_t ui32IntFlags)
 
bool I2CMasterIntStatus (uint32_t ui32Base, bool bMasked)
 
uint32_t I2CMasterIntStatusEx (uint32_t ui32Base, bool bMasked)
 
bool I2CSlaveIntStatus (uint32_t ui32Base, bool bMasked)
 
uint32_t I2CSlaveIntStatusEx (uint32_t ui32Base, bool bMasked)
 
void I2CMasterIntClear (uint32_t ui32Base)
 
void I2CMasterIntClearEx (uint32_t ui32Base, uint32_t ui32IntFlags)
 
void I2CSlaveIntClear (uint32_t ui32Base)
 
void I2CSlaveIntClearEx (uint32_t ui32Base, uint32_t ui32IntFlags)
 
void I2CMasterSlaveAddrSet (uint32_t ui32Base, uint8_t ui8SlaveAddr, bool bReceive)
 
uint32_t I2CMasterLineStateGet (uint32_t ui32Base)
 
bool I2CMasterBusy (uint32_t ui32Base)
 
bool I2CMasterBusBusy (uint32_t ui32Base)
 
void I2CMasterControl (uint32_t ui32Base, uint32_t ui32Cmd)
 
uint32_t I2CMasterErr (uint32_t ui32Base)
 
void I2CMasterDataPut (uint32_t ui32Base, uint8_t ui8Data)
 
uint32_t I2CMasterDataGet (uint32_t ui32Base)
 
void I2CMasterTimeoutSet (uint32_t ui32Base, uint32_t ui32Value)
 
void I2CSlaveACKOverride (uint32_t ui32Base, bool bEnable)
 
void I2CSlaveACKValueSet (uint32_t ui32Base, bool bACK)
 
uint32_t I2CSlaveStatus (uint32_t ui32Base)
 
void I2CSlaveDataPut (uint32_t ui32Base, uint8_t ui8Data)
 
uint32_t I2CSlaveDataGet (uint32_t ui32Base)
 

Detailed Description

Function Documentation

void I2CIntRegister ( uint32_t  ui32Base,
void(*)(void)  pfnHandler 
)

Registers an interrupt handler for the I2C module.

Parameters
ui32Baseis the base address of the I2C Master module.
pfnHandleris a pointer to the function to be called when the I2C interrupt occurs.

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 I2CMasterIntEnable() and I2CSlaveIntEnable(). If necessary, it is the interrupt handler's responsibility to clear the interrupt source via I2CMasterIntClear() and I2CSlaveIntClear().

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.
void I2CIntUnregister ( uint32_t  ui32Base)

Unregisters an interrupt handler for the I2C module.

Parameters
ui32Baseis the base address of the I2C Master module.

This function clears the handler to be called when an I2C interrupt occurs. This function also masks off the interrupt in the interrupt r controller so that the interrupt handler no longer is called.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.
bool I2CMasterBusBusy ( uint32_t  ui32Base)

Indicates whether or not the I2C bus is busy.

Parameters
ui32Baseis the base address of the I2C Master module.

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.

Returns
Returns true if the I2C bus is busy; otherwise, returns false.
bool I2CMasterBusy ( uint32_t  ui32Base)

Indicates whether or not the I2C Master is busy.

Parameters
ui32Baseis the base address of the I2C Master module.

This function returns an indication of whether or not the I2C Master is busy transmitting or receiving data.

Returns
Returns true if the I2C Master is busy; otherwise, returns false.
void I2CMasterControl ( uint32_t  ui32Base,
uint32_t  ui32Cmd 
)

Controls the state of the I2C Master module.

Parameters
ui32Baseis the base address of the I2C Master module.
ui32Cmdcommand to be issued to the I2C Master module.

This function is used to control the state of the Master module send and receive operations. The ui8Cmd parameter can be one of the following values:

  • 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
Returns
None.
uint32_t I2CMasterDataGet ( uint32_t  ui32Base)

Receives a byte that has been sent to the I2C Master.

Parameters
ui32Baseis the base address of the I2C Master module.

This function reads a byte of data from the I2C Master Data Register.

Returns
Returns the byte received from by the I2C Master, cast as an uint32_t.
void I2CMasterDataPut ( uint32_t  ui32Base,
uint8_t  ui8Data 
)

Transmits a byte from the I2C Master.

Parameters
ui32Baseis the base address of the I2C Master module.
ui8Datadata to be transmitted from the I2C Master.

This function places the supplied data into I2C Master Data Register.

Returns
None.
void I2CMasterDisable ( uint32_t  ui32Base)

Disables the I2C master block.

Parameters
ui32Baseis the base address of the I2C Master module.

This function disables operation of the I2C master block.

Returns
None.
void I2CMasterEnable ( uint32_t  ui32Base)

Enables the I2C Master block.

Parameters
ui32Baseis the base address of the I2C Master module.

This function enables operation of the I2C Master block.

Returns
None.
uint32_t I2CMasterErr ( uint32_t  ui32Base)

Gets the error status of the I2C Master module.

Parameters
ui32Baseis the base address of the I2C Master module.

This function is used to obtain the error status of the Master module send and receive operations.

Returns
Returns the error status, as one of I2C_MASTER_ERR_NONE, I2C_MASTER_ERR_ADDR_ACK, I2C_MASTER_ERR_DATA_ACK, or I2C_MASTER_ERR_ARB_LOST.
void I2CMasterInitExpClk ( uint32_t  ui32Base,
uint32_t  ui32I2CClk,
bool  bFast 
)

Initializes the I2C Master block.

Parameters
ui32Baseis the base address of the I2C Master module.
ui32I2CClkis the rate of the clock supplied to the I2C module.
bFastset up for fast data transfers.

This function initializes operation of the I2C Master block by configuring the bus speed for the master and enabling the I2C Master block.

If the parameter bFast 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. This value is returned by SysCtlClockGet(), or it can be explicitly hard coded if it is constant and known (to save the code/execution overhead of a call to SysCtlClockGet()).

Returns
None.
void I2CMasterIntClear ( uint32_t  ui32Base)

Clears I2C Master interrupt sources.

Parameters
ui32Baseis the base address of the I2C Master module.

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.

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 avoid 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).
Returns
None.
void I2CMasterIntClearEx ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Clears I2C Master interrupt sources.

Parameters
ui32Baseis the base address of the I2C Master module.
ui32IntFlagsis a bit mask of the interrupt sources to be cleared.

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.

The ui32IntFlags parameter has the same definition as the ui32IntFlags parameter to I2CMasterIntEnableEx().

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 avoid 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).
Returns
None.
void I2CMasterIntDisable ( uint32_t  ui32Base)

Disables the I2C Master interrupt.

Parameters
ui32Baseis the base address of the I2C Master module.

This function disables the I2C Master interrupt source.

Returns
None.
void I2CMasterIntDisableEx ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Disables individual I2C Master interrupt sources.

Parameters
ui32Baseis the base address of the I2C Master module.
ui32IntFlagsis the bit mask of the interrupt sources to be disabled.

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.

The ui32IntFlags parameter has the same definition as the ui32IntFlags parameter to I2CMasterIntEnableEx().

Returns
None.
void I2CMasterIntEnable ( uint32_t  ui32Base)

Enables the I2C Master interrupt.

Parameters
ui32Baseis the base address of the I2C Master module.

This function enables the I2C Master interrupt source.

Returns
None.
void I2CMasterIntEnableEx ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Enables individual I2C Master interrupt sources.

Parameters
ui32Baseis the base address of the I2C Master module.
ui32IntFlagsis the bit mask of the interrupt sources to be enabled.

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.

The ui32IntFlags parameter is the logical OR of any of the following:

  • I2C_MASTER_INT_TIMEOUT - Clock Timeout interrupt
  • I2C_MASTER_INT_DATA - Data interrupt
Note
Not all Tiva devices support all of the listed interrupt sources. Please consult the device data sheet to determine if these features are supported.
Returns
None.
bool I2CMasterIntStatus ( uint32_t  ui32Base,
bool  bMasked 
)

Gets the current I2C Master interrupt status.

Parameters
ui32Baseis the base address of the I2C Master module.
bMaskedis false if the raw interrupt status is requested and true if the masked interrupt status is requested.

This function returns the interrupt status for the I2C Master module. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.

Returns
The current interrupt status, returned as true if active or false if not active.
uint32_t I2CMasterIntStatusEx ( uint32_t  ui32Base,
bool  bMasked 
)

Gets the current I2C Master interrupt status.

Parameters
ui32Baseis the base address of the I2C Master module.
bMaskedis false if the raw interrupt status is requested and true if the masked interrupt status is requested.

This function returns the interrupt status for the I2C Master module. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.

Returns
Returns the current interrupt status, enumerated as a bit field of values described in I2CMasterIntEnableEx().
uint32_t I2CMasterLineStateGet ( uint32_t  ui32Base)

Reads the state of the SDA and SCL pins.

Parameters
ui32Baseis the base address of the I2C Master module.

This function returns the state of the I2C bus by providing the real time values of the SDA and SCL pins.

Note
Not all Tiva devices support this function. Please consult the device data sheet to determine if this feature is supported.
Returns
Returns the state of the bus with SDA in bit position 1 and SCL in bit position 0.
void I2CMasterSlaveAddrSet ( uint32_t  ui32Base,
uint8_t  ui8SlaveAddr,
bool  bReceive 
)

Sets the address that the I2C Master places on the bus.

Parameters
ui32Baseis the base address of the I2C Master module.
ui8SlaveAddr7-bit slave address
bReceiveflag indicating the type of communication with the slave

This function configures the address that the I2C Master places on the bus when initiating a transaction. When the bReceive parameter is set to true, the address indicates that the I2C Master is initiating a read from the slave; otherwise the address indicates that the I2C Master is initiating a write to the slave.

Returns
None.
void I2CMasterTimeoutSet ( uint32_t  ui32Base,
uint32_t  ui32Value 
)

Sets the Master clock timeout value.

Parameters
ui32Baseis the base address of the I2C Master module.
ui32Valueis the number of I2C clocks before the timeout is asserted.

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 100kHz SCL frequency, ui32Value would be 0x7d.

Note
Not all Tiva devices support this function. Please consult the device data sheet to determine if this feature is supported.
Returns
None.
void I2CSlaveACKOverride ( uint32_t  ui32Base,
bool  bEnable 
)

Configures ACK override behavior of the I2C Slave.

Parameters
ui32Baseis the base address of the I2C Slave module.
bEnableenables or disables ACK override.

This function enables or disables ACK override, allowing the user application to drive the value on SDA during the ACK cycle.

Note
Not all Tiva devices support this function. Please consult the device data sheet to determine if this feature is supported.
Returns
None.
void I2CSlaveACKValueSet ( uint32_t  ui32Base,
bool  bACK 
)

Writes the ACK value.

Parameters
ui32Baseis the base address of the I2C Slave module.
bACKchooses whether to ACK (true) or NACK (false) the transfer.

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 I2CSlaveACKOverride().

Returns
None.
void I2CSlaveAddressSet ( uint32_t  ui32Base,
uint8_t  ui8AddrNum,
uint8_t  ui8SlaveAddr 
)

Sets the I2C slave address.

Parameters
ui32Baseis the base address of the I2C Slave module.
ui8AddrNumdetermines which slave address is set.
ui8SlaveAddris the 7-bit slave address

This function writes the specified slave address. The ui32AddrNum field dictates which slave address is configured. For example, a value of 0 configures the primary address and a value of 1 configures the secondary.

Note
Not all Tiva devices support a secondary address. Please consult the device data sheet to determine if this feature is supported.
Returns
None.
uint32_t I2CSlaveDataGet ( uint32_t  ui32Base)

Receives a byte that has been sent to the I2C Slave.

Parameters
ui32Baseis the base address of the I2C Slave module.

This function reads a byte of data from the I2C Slave Data Register.

Returns
Returns the byte received from by the I2C Slave, cast as an uint32_t.
void I2CSlaveDataPut ( uint32_t  ui32Base,
uint8_t  ui8Data 
)

Transmits a byte from the I2C Slave.

Parameters
ui32Baseis the base address of the I2C Slave module.
ui8Datais the data to be transmitted from the I2C Slave

This function places the supplied data into I2C Slave Data Register.

Returns
None.
void I2CSlaveDisable ( uint32_t  ui32Base)

Disables the I2C slave block.

Parameters
ui32Baseis the base address of the I2C Slave module.

This function disables operation of the I2C slave block.

Returns
None.
void I2CSlaveEnable ( uint32_t  ui32Base)

Enables the I2C Slave block.

Parameters
ui32Baseis the base address of the I2C Slave module.

This fucntion enables operation of the I2C Slave block.

Returns
None.
void I2CSlaveInit ( uint32_t  ui32Base,
uint8_t  ui8SlaveAddr 
)

Initializes the I2C Slave block.

Parameters
ui32Baseis the base address of the I2C Slave module.
ui8SlaveAddr7-bit slave address

This function initializes operation of the I2C Slave block by configuring the slave address and enabling the I2C Slave block.

The parameter ui8SlaveAddr is the value that is compared against the slave address sent by an I2C master.

Returns
None.
void I2CSlaveIntClear ( uint32_t  ui32Base)

Clears I2C Slave interrupt sources.

Parameters
ui32Baseis the base address of the I2C Slave module.

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.

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 avoid 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).
Returns
None.
void I2CSlaveIntClearEx ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Clears I2C Slave interrupt sources.

Parameters
ui32Baseis the base address of the I2C Slave module.
ui32IntFlagsis a bit mask of the interrupt sources to be cleared.

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.

The ui32IntFlags parameter has the same definition as the ui32IntFlags parameter to I2CSlaveIntEnableEx().

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 avoid 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).
Returns
None.
void I2CSlaveIntDisable ( uint32_t  ui32Base)

Disables the I2C Slave interrupt.

Parameters
ui32Baseis the base address of the I2C Slave module.

This function disables the I2C Slave interrupt source.

Returns
None.
void I2CSlaveIntDisableEx ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Disables individual I2C Slave interrupt sources.

Parameters
ui32Baseis the base address of the I2C Slave module.
ui32IntFlagsis the bit mask of the interrupt sources to be disabled.

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.

The ui32IntFlags parameter has the same definition as the ui32IntFlags parameter to I2CSlaveIntEnableEx().

Returns
None.
void I2CSlaveIntEnable ( uint32_t  ui32Base)

Enables the I2C Slave interrupt.

Parameters
ui32Baseis the base address of the I2C Slave module.

This function enables the I2C Slave interrupt source.

Returns
None.
void I2CSlaveIntEnableEx ( uint32_t  ui32Base,
uint32_t  ui32IntFlags 
)

Enables individual I2C Slave interrupt sources.

Parameters
ui32Baseis the base address of the I2C Slave module.
ui32IntFlagsis the bit mask of the interrupt sources to be enabled.

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.

The ui32IntFlags parameter is the logical OR of any of the following:

  • I2C_SLAVE_INT_STOP - Stop condition detected interrupt
  • I2C_SLAVE_INT_START - Start condition detected interrupt
  • I2C_SLAVE_INT_DATA - Data interrupt
Note
Not all Tiva devices support the all of the listed interrupts. Please consult the device data sheet to determine if these features are supported.
Returns
None.
bool I2CSlaveIntStatus ( uint32_t  ui32Base,
bool  bMasked 
)

Gets the current I2C Slave interrupt status.

Parameters
ui32Baseis the base address of the I2C Slave module.
bMaskedis false if the raw interrupt status is requested and true if the masked interrupt status is requested.

This function returns the interrupt status for the I2C Slave module. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.

Returns
The current interrupt status, returned as true if active or false if not active.
uint32_t I2CSlaveIntStatusEx ( uint32_t  ui32Base,
bool  bMasked 
)

Gets the current I2C Slave interrupt status.

Parameters
ui32Baseis the base address of the I2C Slave module.
bMaskedis false if the raw interrupt status is requested and true if the masked interrupt status is requested.

This function returns the interrupt status for the I2C Slave module. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.

Returns
Returns the current interrupt status, enumerated as a bit field of values described in I2CSlaveIntEnableEx().
uint32_t I2CSlaveStatus ( uint32_t  ui32Base)

Gets the I2C Slave module status

Parameters
ui32Baseis the base address of the I2C Slave module.

This function returns the action requested from a master, if any. Possible values are:

  • 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
Note
Not all Tiva devices support the second I2C slave's own address or the quick command function. Please consult the device data sheet to determine if these features are supported.
Returns
Returns I2C_SLAVE_ACT_NONE to indicate that no action has been requested of the I2C Slave module, I2C_SLAVE_ACT_RREQ to indicate that an I2C master has sent data to the I2C Slave module, I2C_SLAVE_ACT_TREQ to indicate that an I2C master has requested that the I2C Slave module 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, and I2C_SLAVE_ACT_QCMD_DATA to indicate that the data bit was set when the quick command was received.