Functions
i2c.c File Reference
#include "inc/hw_types.h"
#include "driverlib/5xx_6xx/debug.h"
#include "driverlib/5xx_6xx/i2c.h"
#include "deprecated/CCS/msp430xgeneric.h"

Functions

void I2C_masterInit (unsigned int baseAddress, unsigned char selectClockSource, unsigned long i2cClk, unsigned long dataRate)
void I2C_slaveInit (unsigned int baseAddress, unsigned char slaveAddress)
void I2C_enable (unsigned int baseAddress)
void I2C_disable (unsigned int baseAddress)
void I2C_setSlaveAddress (unsigned int baseAddress, unsigned char slaveAddress)
void I2C_setMode (unsigned int baseAddress, unsigned char mode)
void I2C_slaveDataPut (unsigned int baseAddress, unsigned char transmitData)
unsigned char I2C_slaveDataGet (unsigned int baseAddress)
unsigned char I2C_isBusBusy (unsigned int baseAddress)
unsigned char I2C_isBusy (unsigned int baseAddress)
unsigned char I2C_masterIsSTOPSent (unsigned int baseAddress)
void I2C_masterSendStart (unsigned int baseAddress)
void I2C_enableInterrupt (unsigned int baseAddress, unsigned char mask)
void I2C_disableInterrupt (unsigned int baseAddress, unsigned char mask)
void I2C_clearInterruptFlag (unsigned int baseAddress, unsigned char mask)
unsigned char I2C_getInterruptStatus (unsigned int baseAddress, unsigned char mask)
void I2C_masterSendSingleByte (unsigned int baseAddress, unsigned char txData)
void I2C_masterMultiByteSendStart (unsigned int baseAddress, unsigned char txData)
void I2C_masterMultiByteSendNext (unsigned int baseAddress, unsigned char txData)
void I2C_masterMultiByteSendFinish (unsigned int baseAddress, unsigned char txData)
void I2C_masterMultiByteSendStop (unsigned int baseAddress)
void I2C_masterMultiByteReceiveStart (unsigned int baseAddress)
unsigned char I2C_masterMultiByteReceiveNext (unsigned int baseAddress)
unsigned char I2C_masterMultiByteReceiveFinish (unsigned int baseAddress)
void I2C_masterMultiByteReceiveStop (unsigned int baseAddress)
void I2C_masterSingleReceiveStart (unsigned int baseAddress)
unsigned char I2C_masterSingleReceive (unsigned int baseAddress)
unsigned long I2C_getReceiveBufferAddressForDMA (unsigned int baseAddress)
unsigned long I2C_getTransmitBufferAddressForDMA (unsigned int baseAddress)

Function Documentation

void I2C_masterInit ( unsigned int  baseAddress,
unsigned char  selectClockSource,
unsigned long  i2cClk,
unsigned long  dataRate 
)

Initializes the I2C Master block.

Parameters:
baseAddressis the base address of the I2C Master module.
selectClockSourceis the clocksource. Valid values are I2C_CLOCKSOURCE_ACLK I2C_CLOCKSOURCE_SMCLK
i2cClkis the rate of the clock supplied to the I2C module.
dataRateset up for selecting data transfer rate. Valid values are I2C_SET_DATA_RATE_400KBPS I2C_SET_DATA_RATE_100KBPS

This function initializes operation of the I2C Master block. Upon successful initialization of the I2C block, this function will have set the bus speed for the master; however I2C module is still disabled till I2C_enable is invoked

If the parameter dataRate is I2C_SET_DATA_RATE_400KBPS, then the master block will be set up to transfer data at 400 kbps; otherwise, it will be set up to transfer data at 100 kbps.

Modified bits are UCMST,UCMODE_3,UCSYNC of UCBxCTL0 register UCSSELx, UCSWRST, of UCBxCTL1 register UCBxBR0 and UCBxBR1 regsiters

Returns:
None.

References ASSERT, HWREG, HWREGB, I2C_CLOCKSOURCE_ACLK, I2C_CLOCKSOURCE_SMCLK, I2C_SET_DATA_RATE_100KBPS, and I2C_SET_DATA_RATE_400KBPS.

void I2C_slaveInit ( unsigned int  baseAddress,
unsigned char  slaveAddress 
)

Initializes the I2C Slave block.

Parameters:
baseAddressis the base address of the I2C Slave module.
slaveAddress7-bit slave address

This function initializes operation of the I2C as a Slave mode. Upon successful initialization of the I2C blocks, this function will have set the slave address but the I2C module is still disabled till I2C_enable is invoked.

The parameter slaveAddress is the value that will be compared against the slave address sent by an I2C master. Modified buts are UCMODE_3, UCSYNC of UCBxCTL0 register UCSWRST of UCBxCTL1 register UCBxI2COA register

Returns:
None.

References HWREG, and HWREGB.

void I2C_enable ( unsigned int  baseAddress)

Enables the I2C block.

Parameters:
baseAddressis the base address of the USCI I2C module.

This will enable operation of the I2C block. Modified bits are UCSWRST of UCBxCTL1 register.

Returns:
None.

References HWREGB.

void I2C_disable ( unsigned int  baseAddress)

Disables the I2C block.

Parameters:
baseAddressis the base address of the USCI I2C module.

This will disable operation of the I2C block. Modified bits are UCSWRST of UCBxCTL1 register.

Returns:
None.

References HWREGB.

void I2C_setSlaveAddress ( unsigned int  baseAddress,
unsigned char  slaveAddress 
)

Sets the address that the I2C Master will place on the bus.

Parameters:
baseAddressis the base address of the I2C Master module.
slaveAddress7-bit slave address

This function will set the address that the I2C Master will place on the bus when initiating a transaction. Modified bits are UCSWRST of UCBxCTL1 register UCBxI2CSA register

Returns:
None.

References HWREG.

void I2C_setMode ( unsigned int  baseAddress,
unsigned char  mode 
)

Sets the mode of the I2C device

Parameters:
baseAddressis the base address of the I2C Master module.
receiveindicates whether module is in transmit/receive mode

When the receive parameter is set to I2C_TRANSMIT_MODE, the address will indicate that the I2C module is in receive mode; otherwise, the I2C module is in send mode. Valid values are I2C_TRANSMIT_MODE I2C_RECEIVE_MODE [Default value] Modified bits are UCTR of UCBxCTL1 register

Returns:
None.

References ASSERT, HWREGB, I2C_RECEIVE_MODE, and I2C_TRANSMIT_MODE.

void I2C_slaveDataPut ( unsigned int  baseAddress,
unsigned char  transmitData 
)

Transmits a byte from the I2C Module.

Parameters:
baseAddressis the base address of the I2C module.
transmitDatadata to be transmitted from the I2C module

This function will place the supplied data into I2C trasmit data register to start transmission Modified bit is UCBxTXBUF register

Returns:
None.

References HWREGB.

unsigned char I2C_slaveDataGet ( unsigned int  baseAddress)

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

Parameters:
baseAddressis the base address of the I2C module.

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

Returns:
Returns the byte received from by the I2C module, cast as an unsigned char. Modified bit is UCBxRXBUF register

References HWREGB.

unsigned char I2C_isBusBusy ( unsigned int  baseAddress)

Indicates whether or not the I2C bus is busy.

Parameters:
baseAddressis the base address of the I2C module.

This function returns an indication of whether or not the I2C bus is busy.This function checks the status of the bus via UCBBUSY bit in UCBxSTAT register.

Returns:
Returns I2C_BUS_BUSY if the I2C Master is busy; otherwise, returns I2C_BUS_NOT_BUSY.

References HWREGB.

unsigned char I2C_isBusy ( unsigned int  baseAddress)

DEPRECATED - Function may be removed in future release. Indicates whether or not the I2C module is busy.

Parameters:
baseAddressis the base address of the I2C module.

This function returns an indication of whether or not the I2C module is busy transmitting or receiving data. This function checks if the Transmit or receive flag is set.

Returns:
Returns I2C_BUS_BUSY if the I2C module is busy; otherwise, returns I2C_BUS_NOT_BUSY.

References HWREGB, I2C_BUS_BUSY, and I2C_BUS_NOT_BUSY.

unsigned char I2C_masterIsSTOPSent ( unsigned int  baseAddress)

Indicates whether STOP got sent.

Parameters:
baseAddressis the base address of the I2C module.

This function returns an indication of whether or not STOP got sent This function checks the status of the bus via UCTXSTP bit in UCBxCTL1 register.

Returns:
Returns I2C_STOP_SEND_COMPLETE if the I2C Master is busy; otherwise, returns I2C_SENDING_STOP.

References HWREGB.

void I2C_masterSendStart ( unsigned int  baseAddress)

This function is used by the Master module to initiate START

Parameters:
baseAddressis the base address of the I2C Master module.

This function is used by the Master module to initiate STOP

Modified bits are UCTXSTT bit of UCBxCTL1.

Returns:
None.

References HWREGB.

void I2C_enableInterrupt ( unsigned int  baseAddress,
unsigned char  mask 
)

Enables individual I2C interrupt sources.

Parameters:
baseAddressis the base address of the I2C module.
interruptFlagsis the bit mask of the interrupt sources to be enabled.

Enables the indicated I2C interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.

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

  • I2C_STOP_INTERRUPT - STOP condition interrupt
  • I2C_START_INTERRUPT - START condition interrupt
  • I2C_RECEIVE_INTERRUPT -Receive interrupt
  • I2C_TRANSMIT_INTERRUPT - Transmit interrupt
  • I2C_NAK_INTERRUPT - Not-acknowledge interrupt
  • I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt

Modified registers are UCBxIFG and OFS_UCBxIE.

Returns:
None.

References ASSERT, HWREG, HWREGB, I2C_ARBITRATIONLOST_INTERRUPT, I2C_NAK_INTERRUPT, I2C_RECEIVE_INTERRUPT, I2C_START_INTERRUPT, I2C_STOP_INTERRUPT, and I2C_TRANSMIT_INTERRUPT.

void I2C_disableInterrupt ( unsigned int  baseAddress,
unsigned char  mask 
)

Disables individual I2C interrupt sources.

Parameters:
baseAddressis the base address of the I2C module.
maskis the bit mask of the interrupt sources to be disabled.

Disables the indicated I2C interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt; disabled sources have no effect on the processor.

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

  • I2C_STOP_INTERRUPT - STOP condition interrupt
  • I2C_START_INTERRUPT - START condition interrupt
  • I2C_RECEIVE_INTERRUPT -Receive interrupt
  • I2C_TRANSMIT_INTERRUPT - Transmit interrupt
  • I2C_NAK_INTERRUPT - Not-acknowledge interrupt
  • I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt

Modified register is UCBxIE.

Returns:
None.

References ASSERT, HWREGB, I2C_ARBITRATIONLOST_INTERRUPT, I2C_NAK_INTERRUPT, I2C_RECEIVE_INTERRUPT, I2C_START_INTERRUPT, I2C_STOP_INTERRUPT, and I2C_TRANSMIT_INTERRUPT.

void I2C_clearInterruptFlag ( unsigned int  baseAddress,
unsigned char  mask 
)

Clears I2C interrupt sources.

Parameters:
baseAddressis the base address of the I2C Slave module.
maskis a bit mask of the interrupt sources to be cleared.

The I2C interrupt source is cleared, so that it no longer asserts. The highest interrupt flag is automatically cleared when an interrupt vector generator is used.

The mask parameter has the same definition as the mask parameter to I2C_enableInterrupt().

Modified register is UCBxIFG.

Returns:
None.

References ASSERT, HWREGB, I2C_ARBITRATIONLOST_INTERRUPT, I2C_NAK_INTERRUPT, I2C_RECEIVE_INTERRUPT, I2C_START_INTERRUPT, I2C_STOP_INTERRUPT, and I2C_TRANSMIT_INTERRUPT.

unsigned char I2C_getInterruptStatus ( unsigned int  baseAddress,
unsigned char  mask 
)

Gets the current I2C interrupt status.

Parameters:
baseAddressis the base address of the I2C module.
maskis the masked interrupt flag status to be returned.

This returns the interrupt status for the I2C module based on which flag is passed. mask parameter can be either any of the following selection.

  • I2C_STOP_INTERRUPT - STOP condition interrupt
  • I2C_START_INTERRUPT - START condition interrupt
  • I2C_RECEIVE_INTERRUPT -Receive interrupt
  • I2C_TRANSMIT_INTERRUPT - Transmit interrupt
  • I2C_NAK_INTERRUPT - Not-acknowledge interrupt
  • I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost interrupt

Modified register is UCBxIFG.

Returns:
the masked status of the interrupt flag

References ASSERT, HWREGB, I2C_ARBITRATIONLOST_INTERRUPT, I2C_NAK_INTERRUPT, I2C_RECEIVE_INTERRUPT, I2C_START_INTERRUPT, I2C_STOP_INTERRUPT, and I2C_TRANSMIT_INTERRUPT.

void I2C_masterSendSingleByte ( unsigned int  baseAddress,
unsigned char  txData 
)

Does single byte transmission from Master to Slave

Parameters:
baseAddressis the base address of the I2C Master module.
txDatais the data byte to be transmitted

This function is used by the Master module to send a single byte. This function

  • Sends START
  • Transmits the byte to the Slave
  • Sends STOP

Modified registers are UCBxIE, UCBxCTL1, UCBxIFG, UCBxTXBUF, UCBxIE

Returns:
None.

References HWREGB.

void I2C_masterMultiByteSendStart ( unsigned int  baseAddress,
unsigned char  txData 
)

Starts multi-byte transmission from Master to Slave

Parameters:
baseAddressis the base address of the I2C Master module.
txDatais the first data byte to be transmitted

This function is used by the Master module to send a single byte. This function

  • Sends START
  • Transmits the first data byte of a multi-byte transmission to the Slave

Modified registers are UCBxIE, UCBxCTL1, UCBxIFG, UCBxTXBUF, UCBxIE

Returns:
None.

References HWREGB.

void I2C_masterMultiByteSendNext ( unsigned int  baseAddress,
unsigned char  txData 
)

Continues multi-byte transmission from Master to Slave

Parameters:
baseAddressis the base address of the I2C Master module.
txDatais the next data byte to be transmitted

This function is used by the Master module continue each byte of a multi-byte trasmission. This function

  • Transmits each data byte of a multi-byte transmission to the Slave

Modified registers are UCBxTXBUF

Returns:
None.

References HWREGB.

void I2C_masterMultiByteSendFinish ( unsigned int  baseAddress,
unsigned char  txData 
)

Finishes multi-byte transmission from Master to Slave

Parameters:
baseAddressis the base address of the I2C Master module.
txDatais the last data byte to be transmitted in a multi-byte tramsission

This function is used by the Master module to send the last byte and STOP. This function

  • Transmits the last data byte of a multi-byte transmission to the Slave
  • Sends STOP

Modified registers are UCBxTXBUF and UCBxCTL1.

Returns:
None.

References HWREGB.

void I2C_masterMultiByteSendStop ( unsigned int  baseAddress)

Send STOP byte at the end of a multi-byte transmission from Master to Slave

Parameters:
baseAddressis the base address of the I2C Master module.

This function is used by the Master module send STOP at the end of a multi-byte trasmission

This function

  • Send a STOP after current transmission is complete

Modified bits are UCTXSTP bit of UCBxCTL1.

Returns:
None.

References HWREGB.

void I2C_masterMultiByteReceiveStart ( unsigned int  baseAddress)

Starts multi-byte reception at the Master end

Parameters:
baseAddressis the base address of the I2C Master module.

This function is used by the Master module initiate reception of a single byte. This function

  • Sends START

Modified bits are UCTXSTT bit of UCBxCTL1.

Returns:
None.

References HWREGB.

unsigned char I2C_masterMultiByteReceiveNext ( unsigned int  baseAddress)

Starts multi-byte reception at the Master end one byte at a time

Parameters:
baseAddressis the base address of the I2C Master module.

This function is used by the Master module to receive each byte of a multi-byte reception This function reads currently received byte

Modified register is UCBxRXBUF.

Returns:
Received byte at Master end.

References HWREGB.

unsigned char I2C_masterMultiByteReceiveFinish ( unsigned int  baseAddress)

Finishes multi-byte reception at the Master end

Parameters:
baseAddressis the base address of the I2C Master module.

This function is used by the Master module to initiate completion of a multi-byte reception This function

  • Receives the current byte and initiates the STOP from Master to Slave

Modified bits are UCTXSTP bit of UCBxCTL1.

Returns:
Received byte at Master end.

References HWREGB.

void I2C_masterMultiByteReceiveStop ( unsigned int  baseAddress)

Sends the STOP at the end of a multi-byte reception at the Master end

Parameters:
baseAddressis the base address of the I2C Master module.

This function is used by the Master module to initiate STOP

Modified bits are UCTXSTP bit of UCBxCTL1.

Returns:
None.

References HWREGB.

void I2C_masterSingleReceiveStart ( unsigned int  baseAddress)

Initiates a single byte Reception at the Master End

Parameters:
baseAddressis the base address of the I2C Master module.

This function sends a START and STOP immediately to indicate Single byte reception

Modified bits are UCTXSTT and UCTXSTP of UCBxCTL1, GIE

Returns:
None.

References HWREGB.

unsigned char I2C_masterSingleReceive ( unsigned int  baseAddress)

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

Parameters:
baseAddressis the base address of the I2C module.

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

Returns:
Returns the byte received from by the I2C module, cast as an unsigned char.

References HWREGB.

unsigned long I2C_getReceiveBufferAddressForDMA ( unsigned int  baseAddress)

Returns the address of the RX Buffer of the I2C for the DMA module.

Parameters:
baseAddressis the base address of the I2C module.

Returns the address of the I2C RX Buffer. This can be used in conjunction with the DMA to store the received data directly to memory.

Returns:
NONE
unsigned long I2C_getTransmitBufferAddressForDMA ( unsigned int  baseAddress)

Returns the address of the TX Buffer of the I2C for the DMA module.

Parameters:
baseAddressis the base address of the I2C module.

Returns the address of the I2C TX Buffer. This can be used in conjunction with the DMA to obtain transmitted data directly from memory.

Returns:
NONE

Copyright 2012, Texas Instruments Incorporated