MSP430™CapTIvateSoftwareLibraryAPIGuide 1_70_00_03

Data Structures | Macros | Enumerations | Functions | Variables
I2CSlave

I2C slave driver module for the eUSCI_B I2C peripheral. More...

## Data Structures
struct | tI2CSlavePort

## Macros
#define | I2CSLAVE__EUSCI_VECTOR (USCI_B0_VECTOR)
#define | I2CSLAVE__EUSCI_IV (UCB0IV)
#define | I2CSLAVE__INT_MASK (0x0F)
#define | I2C__INIT_REQ_SIGNAL (I2CSLAVE__REQ_POUT &= ~I2CSLAVE__REQ_MASK)
#define | I2C__PULL_REQ_SIGNAL (I2CSLAVE__REQ_PDIR |= I2CSLAVE__REQ_MASK)
#define | I2C__RELEASE_REQ_SIGNAL (I2CSLAVE__REQ_PDIR &= ~I2CSLAVE__REQ_MASK)
#define | I2CSLAVE__EUSCI_B_PERIPHERAL (EUSCI_B0_BASE)
#define | I2CSLAVE__ADDRESS (0x0A)
#define | I2CSLAVE__LPMx_bits (LPM3_bits)
#define | I2CSLAVE__INVALID_BYTE (0xFF)
#define | I2CSLAVE__TIMEOUT_ENABLE (true)
#define | I2CSLAVE__REQ_TIMEOUT_CYCLES (66)
#define | I2CSLAVE__TXFR_TIMEOUT_CYCLES (264)

## Enumerations
enum | tI2CSlaveStates { eI2CSlaveIsClosed = 0x00, eI2CSlaveIsIdle = 0x01, eI2CSlaveIsBeingRead = 0x02, eI2CSlaveIsBeingWrittenTo = 0x03 }
| enumerates the possible I2C slave driver states. More...
enum | tI2CSlaveErrors { eI2CSlaveTransmitRequestTimeout, eI2CSlaveTransactionTimeout, eI2CSlaveReceiveBufferFull, eI2CSlaveWasReadBeyondTransmitBuffer }

## Functions
void | I2CSlave_openPort (const tI2CSlavePort *pPort)
void | I2CSlave_closePort (void)
uint8_t | I2CSlave_getPortStatus (void)
void | I2CSlave_setTransmitBuffer (uint8_t *pBuffer, uint16_t ui16Length)
void | I2CSlave_setRequestFlag (void)
__interrupt void | I2CSlave_ISR (void)

## Variables
const tI2CSlavePort * | g_pI2CSlavePort
const EUSCI_B_I2C_initSlaveParam | g_I2CSlaveConfiguration
const uint8_t * | g_pI2CTransmitBuffer
| var g_pI2CTransmitBuffer stores a pointer to the current transmit buffer. More...
uint16_t | g_ui16I2CLength
volatile uint16_t | g_ui16I2CIndex
| var g_ui16I2CIndex stores the current transmit or receive buffer index. More...
volatile uint8_t | g_I2CSlaveStatus = eI2CSlaveIsClosed
volatile bool | g_bI2CSlaveRequestPending
const tFunctionTimer | g_I2CSlaveFunctionTimer

## Detailed Description

I2C slave driver module for the eUSCI_B I2C peripheral.

This is the I2C slave port driver header file. The I2C slave port driver enables interrupt-driven I2C-bus transactions via a simple API. The implementation requires one eUSCI_B instance, and the MSP430 DriverLib version 2.10.00.00 or greater.

Version
  VERSION Released on RELEASE_DATE

This is the I2C slave definitions file. This file sets the configuration parameters for the I2C slave port.

Version
  VERSION Released on RELEASE_DATE

## Macro Definition Documentation

## § I2CSLAVE__EUSCI_VECTOR

#define I2CSLAVE__EUSCI_VECTOR (USCI_B0_VECTOR)

def I2CSLAVE__EUSCI_VECTOR defines the interrupt vector location of the selected eUSCI_B I2C peripheral. def I2CSLAVE__EUSCI_IV defines the interrupt vector of the selected eUSCI_B I2C peripheral.

## § I2CSLAVE__EUSCI_IV

#define I2CSLAVE__EUSCI_IV (UCB0IV)

Referenced by I2CSlave_ISR().

## § I2CSLAVE__INT_MASK

#define I2CSLAVE__INT_MASK (0x0F)

def I2CSLAVE__INT_MASK defines the interrupt enable mask for the eUSCI_B I2C peripheral. The used interrupts include START, STOP, RX, and TX.

Referenced by I2CSlave_openPort().

## § I2C__INIT_REQ_SIGNAL

#define I2C__INIT_REQ_SIGNAL (I2CSLAVE__REQ_POUT &= ~I2CSLAVE__REQ_MASK)

def I2C__INIT_REQ_SIGNAL is a macro for setting the I2C request line to active low.

Referenced by I2CSlave_openPort().

## § I2C__PULL_REQ_SIGNAL

#define I2C__PULL_REQ_SIGNAL (I2CSLAVE__REQ_PDIR |= I2CSLAVE__REQ_MASK)

def I2C__PULL_REQ_SIGNAL is a macro for pulling the I2C request line by changing its state from Hi-Z to output low (current sink)

Referenced by I2CSlave_setRequestFlag().

## § I2C__RELEASE_REQ_SIGNAL

#define I2C__RELEASE_REQ_SIGNAL (I2CSLAVE__REQ_PDIR &= ~I2CSLAVE__REQ_MASK)

def I2C__RELEASE_REQ_SIGNAL us a macro for releasing the I2C request line by returing its state to Hi-Z from output low.

Referenced by I2CSlave_setRequestFlag().

## § I2CSLAVE__EUSCI_B_PERIPHERAL

#define I2CSLAVE__EUSCI_B_PERIPHERAL (EUSCI_B0_BASE)

Referenced by I2CSlave_closePort(), and I2CSlave_openPort().

## § I2CSLAVE__ADDRESS

#define I2CSLAVE__ADDRESS (0x0A)

## § I2CSLAVE__LPMx_bits

#define I2CSLAVE__LPMx_bits (LPM3_bits)

Referenced by I2CSlave_setRequestFlag(), and I2CSlave_setTransmitBuffer().

## § I2CSLAVE__INVALID_BYTE

#define I2CSLAVE__INVALID_BYTE (0xFF)

## § I2CSLAVE__TIMEOUT_ENABLE

#define I2CSLAVE__TIMEOUT_ENABLE (true)

## § I2CSLAVE__REQ_TIMEOUT_CYCLES

#define I2CSLAVE__REQ_TIMEOUT_CYCLES (66)

## § I2CSLAVE__TXFR_TIMEOUT_CYCLES

#define I2CSLAVE__TXFR_TIMEOUT_CYCLES (264)

## Enumeration Type Documentation

## § tI2CSlaveStates

enum tI2CSlaveStates

enumerates the possible I2C slave driver states.

Enumerator
eI2CSlaveIsClosed |
eI2CSlaveIsIdle |
eI2CSlaveIsBeingRead |
eI2CSlaveIsBeingWrittenTo |

## § tI2CSlaveErrors

enum tI2CSlaveErrors

enumerates the possible I2C slave driver errors. These error codes are passed to the error callback function.

Enumerator
eI2CSlaveTransmitRequestTimeout |
eI2CSlaveTransactionTimeout |
eI2CSlaveReceiveBufferFull |
eI2CSlaveWasReadBeyondTransmitBuffer |

## Function Documentation

## § I2CSlave_openPort()

void I2CSlave_openPort | ( | const tI2CSlavePort * | pPort | ) |

This function opens the I2C slave port on the specified HW eUSCI_B peripheral. This function must be called before the port is used.

Parameters

  pPort | is a pointer to the I2C Slave Port configuration structure. The user must populate and provide this structure to the I2C slave port driver. The data structure must remain at the same address throughout the operation of the driver.

Returns
  none

References eI2CSlaveIsIdle, g_bI2CSlaveRequestPending, g_I2CSlaveConfiguration, g_I2CSlaveStatus, I2C__INIT_REQ_SIGNAL, I2CSLAVE__EUSCI_B_PERIPHERAL, I2CSLAVE__INT_MASK, I2CSlave_closePort(), and Timer_startDelayedFunctionTimer().

## § I2CSlave_closePort()

void I2CSlave_closePort | ( | void |  | ) |

This function closes the I2C slave port on the specified HW eUSCI_B peripheral.

Parameters
  none

Returns
  none

References eI2CSlaveIsClosed, g_I2CSlaveStatus, I2CSLAVE__EUSCI_B_PERIPHERAL, and Timer_stopDelayedFunctionTimer().

Referenced by I2CSlave_openPort().

## § I2CSlave_getPortStatus()

uint8_t I2CSlave_getPortStatus | ( | void |  | ) |

This function returns the status of the I2C port when called. The possible I2C statuses are enumerated under tI2CSlaveStates.

Parameters
  none

Returns
  tI2CSlaveStates enumeration indicating the current I2C status.

References g_I2CSlaveStatus.

## § I2CSlave_setTransmitBuffer()

void I2CSlave_setTransmitBuffer | ( | uint8_t * | pBuffer,
|  | uint16_t | ui16Length
| ) |  |

This function sets a new transmit buffer in the I2C peripheral. To send a buffer of data to the I2C bus master, use this function to inform the driver of the buffer location and size. Then call the I2CSlave_setTransmitRequestFlag function to signal the host to begin transmission. If a current read is either pending or currently in progress, this function will block until that operation has completed or timed out before updating the transmit buffer pointer and length.

Parameters

  pBuffer | is a pointer to the new transmit buffer
  ui16Length | is an integer specifying the valid data length in the buffer

Returns
  none

References eI2CSlaveIsBeingRead, g_bI2CSlaveRequestPending, g_I2CSlaveStatus, g_pI2CTransmitBuffer, g_ui16I2CLength, and I2CSLAVE__LPMx_bits.

## § I2CSlave_setRequestFlag()

void I2CSlave_setRequestFlag | ( | void |  | ) |

This function pulls the I2C request line to signal the bus master that data is waiting to be read from this device. This function will block until either the bus master begins to read out the data OR the read post times out, at which point the error callback will be called to handle the error.

Parameters
  none

Returns
  true if bus master began read operation; else false if the request timed out.

References eTimerDelayedFunction_A, g_bI2CSlaveRequestPending, I2C__PULL_REQ_SIGNAL, I2C__RELEASE_REQ_SIGNAL, I2CSLAVE__LPMx_bits, Timer_cancelDelayedFunction(), and Timer_scheduleDelayedFunction().

## § I2CSlave_ISR()

__interrupt void I2CSlave_ISR | ( | void |  | ) |

References eI2CSlaveIsBeingWrittenTo, g_I2CSlaveStatus, and I2CSLAVE__EUSCI_IV.

## Variable Documentation

## § g_pI2CSlavePort

const tI2CSlavePort* g_pI2CSlavePort

var g_pI2CSlavePort stores a pointer to the I2C slave port configuration structure that was passed to the I2CSlave_openPort function. The I2C slave driver does not modify this structure.

## § g_I2CSlaveConfiguration

const EUSCI_B_I2C_initSlaveParam g_I2CSlaveConfiguration

Initial value:
=
{
.slaveAddress = I2CSLAVE__ADDRESS,
.slaveAddressOffset = EUSCI_B_I2C_OWN_ADDRESS_OFFSET0,
.slaveOwnAddressEnable = EUSCI_B_I2C_OWN_ADDRESS_ENABLE
}
I2CSLAVE__ADDRESS
#define I2CSLAVE__ADDRESS
Definition: I2CSlave_Definitions.h:48

var g_I2CSlaveConfiguration stores the MSP430 DriverLib EUSCI_B_I2C configuration parameters for the EUSCI_B_I2C_initSlave() function call.

Referenced by I2CSlave_openPort().

## § g_pI2CTransmitBuffer

const uint8_t* g_pI2CTransmitBuffer

var g_pI2CTransmitBuffer stores a pointer to the current transmit buffer.

Referenced by I2CSlave_setTransmitBuffer().

## § g_ui16I2CLength

uint16_t g_ui16I2CLength

var g_ui16I2CLength stores the valid data length of the data pointed to by g_pI2CTransmitBuffer.

Referenced by I2CSlave_setTransmitBuffer().

## § g_ui16I2CIndex

volatile uint16_t g_ui16I2CIndex

var g_ui16I2CIndex stores the current transmit or receive buffer index.

## § g_I2CSlaveStatus

volatile uint8_t g_I2CSlaveStatus = eI2CSlaveIsClosed

var g_I2CSlaveStatus stores the current status of the I2C slave port. possible options are enumerated in tI2CSlaveStates.

Referenced by I2CSlave_closePort(), I2CSlave_getPortStatus(), I2CSlave_ISR(), I2CSlave_openPort(), and I2CSlave_setTransmitBuffer().

## § g_bI2CSlaveRequestPending

volatile bool g_bI2CSlaveRequestPending

var g_bI2CSlaveRequestPending indicates whether or not a read operation is currently pending on the I2C bus master.

Referenced by I2CSlave_openPort(), I2CSlave_setRequestFlag(), and I2CSlave_setTransmitBuffer().

## § g_I2CSlaveFunctionTimer

const tFunctionTimer g_I2CSlaveFunctionTimer

Initial value:
=
{
.pbFunction_A = &I2CSlave_requestTimeoutHandler,
.pbFunction_B = &I2CSlave_transactionTimeoutHandler,
.ui16FunctionDelay_A = I2CSLAVE__REQ_TIMEOUT_CYCLES,
.ui16FunctionDelay_B = I2CSLAVE__TXFR_TIMEOUT_CYCLES
}
I2CSLAVE__REQ_TIMEOUT_CYCLES
#define I2CSLAVE__REQ_TIMEOUT_CYCLES
Definition: I2CSlave_Definitions.h:80
I2CSLAVE__TXFR_TIMEOUT_CYCLES
#define I2CSLAVE__TXFR_TIMEOUT_CYCLES
Definition: I2CSlave_Definitions.h:81

var g_I2CSlaveFunctionTimer contains the function timer configuration for the two I2C timeout events- a slave request timeout (Fxn A) and an I2C transaction timeout (Fxn B)

© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale