Defines | Functions
spi.h File Reference

Go to the source code of this file.

Defines

#define __MSP430_HAS_USCI_Ax__
#define SPI_CLOCKSOURCE_ACLK   UCSSEL__ACLK
#define SPI_CLOCKSOURCE_SMCLK   UCSSEL__SMCLK
#define SPI_MSB_FIRST   UCMSB
#define SPI_LSB_FIRST   0x00
#define SPI_BUSY   UCBUSY
#define SPI_NOT_BUSY   0x00
#define SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT   0x00
#define SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT   UCCKPH
#define SPI_CLOCKPOLARITY_INACTIVITY_HIGH   UCCKPL
#define SPI_CLOCKPOLARITY_INACTIVITY_LOW   0x00
#define SPI_TRANSMIT_INTERRUPT   UCTXIE
#define SPI_RECEIVE_INTERRUPT   UCRXIE

Functions

unsigned short SPI_masterInit (unsigned int baseAddress, unsigned char selectClockSource, unsigned long clockSourceFrequency, unsigned long desiredSpiClock, unsigned char msbFirst, unsigned char clockPhase, unsigned char clockPolarity)
void SPI_masterChangeClock (unsigned int baseAddress, unsigned long clockSourceFrequency, unsigned long desiredSpiClock)
unsigned short SPI_slaveInit (unsigned int baseAddress, unsigned char msbFirst, unsigned char clockPhase, unsigned char clockPolarity)
void SPI_changeClockPhasePolarity (unsigned int baseAddress, unsigned char clockPhase, unsigned char clockPolarity)
void SPI_transmitData (unsigned int baseAddress, unsigned char transmitData)
unsigned char SPI_receiveData (unsigned int baseAddress)
void SPI_enableInterrupt (unsigned int baseAddress, unsigned char mask)
void SPI_disableInterrupt (unsigned int baseAddress, unsigned char mask)
unsigned char SPI_getInterruptStatus (unsigned int baseAddress, unsigned char mask)
void SPI_enable (unsigned int baseAddress)
void SPI_disable (unsigned int baseAddress)
unsigned long SPI_getReceiveBufferAddressForDMA (unsigned int baseAddress)
unsigned long SPI_getTransmitBufferAddressForDMA (unsigned int baseAddress)
unsigned char SPI_isBusy (unsigned int baseAddress)
void SPI_clearInterruptFlag (unsigned int baseAddress, unsigned char mask)

Define Documentation

#define __MSP430_HAS_USCI_Ax__
#define SPI_CLOCKSOURCE_ACLK   UCSSEL__ACLK

Referenced by SPI_masterInit().

#define SPI_CLOCKSOURCE_SMCLK   UCSSEL__SMCLK

Referenced by SPI_masterInit().

#define SPI_MSB_FIRST   UCMSB

Referenced by SPI_masterInit(), and SPI_slaveInit().

#define SPI_LSB_FIRST   0x00

Referenced by SPI_masterInit(), and SPI_slaveInit().

#define SPI_BUSY   UCBUSY
#define SPI_NOT_BUSY   0x00
#define SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT   0x00

Referenced by SPI_masterInit(), and SPI_slaveInit().

#define SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT   UCCKPH

Referenced by SPI_masterInit(), and SPI_slaveInit().

#define SPI_CLOCKPOLARITY_INACTIVITY_HIGH   UCCKPL
#define SPI_CLOCKPOLARITY_INACTIVITY_LOW   0x00
#define SPI_TRANSMIT_INTERRUPT   UCTXIE
#define SPI_RECEIVE_INTERRUPT   UCRXIE

Function Documentation

unsigned short SPI_masterInit ( unsigned int  baseAddress,
unsigned char  selectClockSource,
unsigned long  clockSourceFrequency,
unsigned long  desiredSpiClock,
unsigned char  msbFirst,
unsigned char  clockPhase,
unsigned char  clockPolarity 
)

Initializes the SPI Master block.

Parameters:
baseAddressis the base address of the I2C Master module.
selectClockSourceselects Clock source. Valid values are SPI_CLOCKSOURCE_ACLK SPI_CLOCKSOURCE_SMCLK
clockSourceFrequencyis the frequency of the slected clock source
desiredSpiClockis the desired clock rate for SPI communication
msbFirstcontrols the direction of the receive and transmit shift register. Valid values are SPI_MSB_FIRST SPI_LSB_FIRST [Default Value]
clockPhaseis clock phase select. Valid values are SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default Value] SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
clockPolarity_InactivityHIGHis clock polarity select. Valid values are SPI_CLOCKPOLARITY_INACTIVITY_HIGH SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default Value] Upon successful initialization of the SPI master block, this function will have set the bus speed for the master, but the SPI Master block still remains disabled and must be enabled with SPI_enable()

Modified bits are UCCKPH, UCCKPL, UC7BIT, UCMSB bits of UCBxCTL0 register and UCSSELx, UCSWRST bits of UCBxCTL1 register

Returns:
STATUS_SUCCESS

References ASSERT, HWREGB, SPI_CLOCKPOLARITY_INACTIVITY_HIGH, SPI_CLOCKPOLARITY_INACTIVITY_LOW, SPI_CLOCKSOURCE_ACLK, SPI_CLOCKSOURCE_SMCLK, SPI_LSB_FIRST, SPI_MSB_FIRST, SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, and STATUS_SUCCESS.

void SPI_masterChangeClock ( unsigned int  baseAddress,
unsigned long  clockSourceFrequency,
unsigned long  desiredSpiClock 
)

Initializes the SPI Master clock.At the end of this function call, SPI module is left enabled.

Parameters:
baseAddressis the base address of the I2C Master module.
clockSourceFrequencyis the frequency of the slected clock source
desiredSpiClockis the desired clock rate for SPI communication
Returns:
None

References HWREGB.

unsigned short SPI_slaveInit ( unsigned int  baseAddress,
unsigned char  msbFirst,
unsigned char  clockPhase,
unsigned char  clockPolarity 
)

Initializes the SPI Slave block.

Parameters:
baseAddressis the base address of the SPI Slave module.
msbFirstcontrols the direction of the receive and transmit shift register. Valid values are SPI_MSB_FIRST SPI_LSB_FIRST [Default Value]
clockPhaseis clock phase select. Valid values are SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default Value] SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
clockPolarity_InactivityHIGHis clock polarity select. Valid values are SPI_CLOCKPOLARITY_INACTIVITY_HIGH SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default Value] Upon successful initialization of the SPI slave block, this function will have initailized the slave block, but the SPI Slave block still remains disabled and must be enabled with SPI_enable()

Modified bits are UCMSB, UC7BIT, UCMST, UCCKPL, UCCKPH, UCMODE_3 bits of UCAxCTL0 and UCSWRST bits of UCAxCTL1

Returns:
STATUS_SUCCESS

References ASSERT, HWREGB, SPI_CLOCKPOLARITY_INACTIVITY_HIGH, SPI_CLOCKPOLARITY_INACTIVITY_LOW, SPI_LSB_FIRST, SPI_MSB_FIRST, SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, and STATUS_SUCCESS.

void SPI_changeClockPhasePolarity ( unsigned int  baseAddress,
unsigned char  clockPhase,
unsigned char  clockPolarity 
)

Changes the SPI colock phase and polarity.At the end of this function call, SPI module is left enabled.

Parameters:
baseAddressis the base address of the I2C Master module.
clockPhaseis clock phase select. Valid values are SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default Value] SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
clockPolarity_InactivityHIGHis clock polarity select. Valid values are SPI_CLOCKPOLARITY_INACTIVITY_HIGH SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default Value]
Returns:
None

References ASSERT, HWREGB, SPI_CLOCKPOLARITY_INACTIVITY_HIGH, and SPI_CLOCKPOLARITY_INACTIVITY_LOW.

void SPI_transmitData ( unsigned int  baseAddress,
unsigned char  transmitData 
)

Transmits a byte from the SPI Module.

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

This function will place the supplied data into SPI trasmit data register to start transmission

Returns:
None.

References HWREGB.

unsigned char SPI_receiveData ( unsigned int  baseAddress)

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

Parameters:
baseAddressis the base address of the SPI module.

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

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

References HWREGB.

void SPI_enableInterrupt ( unsigned int  baseAddress,
unsigned char  mask 
)

Enables individual SPI interrupt sources.

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

Enables the indicated SPI 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:

  • SPI_RECEIVE_INTERRUPT -Receive interrupt
  • SPI_TRANSMIT_INTERRUPT - Transmit interrupt

Modified registers are UCAxIFG and UCAxIE

Returns:
None.

References ASSERT, HWREGB, SPI_RECEIVE_INTERRUPT, and SPI_TRANSMIT_INTERRUPT.

void SPI_disableInterrupt ( unsigned int  baseAddress,
unsigned char  mask 
)

Disables individual SPI interrupt sources.

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

Disables the indicated SPI 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:

  • SPI_RECEIVE_INTERRUPT -Receive interrupt
  • SPI_TRANSMIT_INTERRUPT - Transmit interrupt

Modified register is UCAxIE

Returns:
None.

References ASSERT, HWREGB, SPI_RECEIVE_INTERRUPT, and SPI_TRANSMIT_INTERRUPT.

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

Gets the current SPI interrupt status.

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

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

  • SPI_RECEIVE_INTERRUPT -Receive interrupt
  • SPI_TRANSMIT_INTERRUPT - Transmit interrupt

Modified registers are UCAxIFG.

Returns:
The current interrupt status as the mask of the set flags

References ASSERT, HWREGB, SPI_RECEIVE_INTERRUPT, and SPI_TRANSMIT_INTERRUPT.

void SPI_enable ( unsigned int  baseAddress)

Enables the SPI block.

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

This will enable operation of the SPI block. Modified bits are UCSWRST bit of UCAxCTL1 register.

Returns:
None.

References HWREGB.

void SPI_disable ( unsigned int  baseAddress)

Disables the SPI block.

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

This will disable operation of the SPI block.

Modified bits are UCSWRST bit of UCAxCTL1 register.

Returns:
None.

References HWREGB.

unsigned long SPI_getReceiveBufferAddressForDMA ( unsigned int  baseAddress)

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

Parameters:
baseAddressis the base address of the SPI module.

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

Returns:
None
unsigned long SPI_getTransmitBufferAddressForDMA ( unsigned int  baseAddress)

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

Parameters:
baseAddressis the base address of the SPI module.

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

Returns:
None
unsigned char SPI_isBusy ( unsigned int  baseAddress)

Indicates whether or not the SPI bus is busy.

Parameters:
baseAddressis the base address of the SPI module.

This function returns an indication of whether or not the SPI bus is busy.This function checks the status of the bus via UCBBUSY bit

Returns:
SPI_BUSY if the SPI module trasmitting or receiving is busy; otherwise, returns SPI_NOT_BUSY.

References HWREGB.

void SPI_clearInterruptFlag ( unsigned int  baseAddress,
unsigned char  mask 
)

Clears the selected SPI interrupt status flag.

Parameters:
baseAddressis the base address of the SPI module.
maskis the masked interrupt flag to be cleared.

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

  • SPI_RECEIVE_INTERRUPT -Receive interrupt
  • SPI_TRANSMIT_INTERRUPT - Transmit interrupt

Modified registers are UCAxIFG.

Returns:
None

References ASSERT, HWREGB, SPI_RECEIVE_INTERRUPT, and SPI_TRANSMIT_INTERRUPT.


Copyright 2012, Texas Instruments Incorporated