Dallas Semiconductor DS80C400 C Libraries Home Page

Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

tini400_spi.h File Reference


Detailed Description

SPI library for the TINIm400 module.

"Bit Bang" software SPI library for use with the TINIm400. This is a full featured SPI library for sending and receiving data. It supports 4 SPI_CLK polarity and phase modes, slave select with optional inversion and optional synching, 8 and 16 bit transfer modes, bit reordering and SPI_CLK delays.

Port pins used by this SPI library can be specified in spimacros.inc.

For detailed information on the DS80C400 please see the High-Speed Microcontroller User's Guide: DS80C400 Supplement.

Warning:
The functions in this library are NOT multi-process safe--that is, if you call the same method from two different processes at the same time, the parameters to the function may be destroyed, yielding unpredictable results. However, SPI pins are a system resource and should not be shared among different processes.

Go to the source code of this file.

Defines

#define TINI400_SPI_VERSION   2
#define SPI_CKPOL_MASK   0x01
 CKPOL MASK.
#define SPI_CKPHA_MASK   0x02
 CKPHA MASK.
#define SPI_WORD_MASK   0x04
 Word mode MASK.
#define SPI_SKEW_MASK   0x08
 No Skew MASK.
#define SPI_USESS_MASK   0x10
 Use SS MASK.
#define SPI_SYNCHSS_MASK   0x20
 Synch SS MASK.
#define SPI_INVERTSS_MASK   0x40
 Invert SS MASK.

Functions

void spi_init (void)
 Initalize the SPI library.
int spi_reverseBits (int length, int wordSize, unsigned char *dataptr)
 Reverse bits in buffer.
void spi_xmit (unsigned char *dataptr, int length, unsigned char delay, unsigned char options)
 Transmit SPI data.
unsigned int spi_version (void)
 Returns the version number of this SPI library.


Define Documentation

#define SPI_CKPHA_MASK   0x02
 

CKPHA MASK.

See also:
SPI_CKPOL_MASK

spi_xmit

#define SPI_CKPOL_MASK   0x01
 

CKPOL MASK.

The four SPI clock (SPI_CLK) modes supported by this library are defined by CKPHA and CKPOL. The CKPOL bit defines the idle state of the SPI clock, CKPOL = 0 forces SPI_CLK to idle low while CKPOL = 1 forces SPI_CLK to idle high. CKPHA changes the edge used to signal transfer of data. When CKPHA = 0 the first edge of SPI_CLK specifies when the slave and master should sample their input. With CKPHA = 1 the second edge of SPI_CLK specifies when to sample. When CKPHA = 1, the master and slave should present their data on their output during the first SPI_CLK edge, this allows the data sufficent hold time. When CKPHA = 0, data should become valid when the Slave Select (SS) line goes active. Note that most devices require the SS line to be used when CKPHA = 0 to allow proper timing while SS may be optional when CKPHA = 1.

See also:
SPI_CKPHA_MASK

spi_xmit

#define SPI_INVERTSS_MASK   0x40
 

Invert SS MASK.

Most SPI devices expect the active state for SS to be low, but others require high as the active state.

See also:
spi_xmit

#define SPI_SKEW_MASK   0x08
 

No Skew MASK.

To facilitate atomic transfers, interrupts may be disabled while transmiting.

See also:
spi_xmit

#define SPI_SYNCHSS_MASK   0x20
 

Synch SS MASK.

Some SPI devices expect the SS signal to go inactive after each word transfer in order to synchronize.

See also:
spi_xmit

#define SPI_USESS_MASK   0x10
 

Use SS MASK.

The SS signal is optional as it may not be required for all SPI setups.

See also:
spi_xmit

#define SPI_WORD_MASK   0x04
 

Word mode MASK.

Data is sent to the SPI library as a character array in data memory. When in 8 bit word mode these bytes will be transferred one at a time. In 16 bit word mode 2 bytes will be transferred but this operation will only consume 1 transfer of the number requested. Note that in this library, "word" may be 8 or 16 bits in length depending on the selected mode. Using this mask activates 16 bit word mode

See also:
spi_xmit

#define TINI400_SPI_VERSION   2
 

Version number associated with this header file. Should be the same as the version number returned by the spi_version function.

See also:
spi_version


Function Documentation

int spi_reverseBits int  length,
int  wordSize,
unsigned char *  dataptr
 

Reverse bits in buffer.

This function can be called to reverse the bits in the passed buffer. It reorders the based on the word mode 8 bit words or 16 bit words. This can be used to convert data for Least Significant Bit (LSB) transfers.

Parameters:
length Number of words to bit reverse. Note that for 16 bit words this must be a even value, SPI library does not check this.
wordSize Size of the word to reverse. Only 8 and 16 are valid.
dataptr Pointer to the data to be reversed, after calling this function the data in this buffers will be bit reversed.
Returns:
int 1 for success, -1 if error occured

unsigned int spi_version void   ) 
 

Returns the version number of this SPI library.

Returns:
int Version number of this SPI library.

void spi_xmit unsigned char *  dataptr,
int  length,
unsigned char  delay,
unsigned char  options
 

Transmit SPI data.

Transmits the data passed in over the SPI port, reads and returns any data read back.

Parameters:
dataptr Pointer to the data to be transmited, received data is written over transmit data during transfer,
length Amount of data to transfer
delay Amount of time to delay clock edges, in usec. In order to interface to slower SPI slaves a SPI_CLK stretch can be used to increases the SPI_CLK period by 1 µsec per stretch.
options SPI configuration options defined as:
  • bit 0 - CPOL - Set to 1 - SPICLK idles high
  • bit 1 - CPHA - Set to 1 - Transfers on second edge
  • bit 2 - wordMode - Set to 1 - 16 bit transfers
  • bit 3 - noskew - Set to 1 - turn off interrupts during transfer
  • bit 4 - useSS - Set to 1 - Use the SS line during transfers
  • bit 5 - synchSS - Set to 1 - Takes SS to inactive after every word
  • bit 6 - invertSS - Set to 1 - SS line is active high


Copyright 2005 Dallas Semiconductor, Inc.. Documentation generated by Doxygen.