com.dalsemi.comm
Class SPI

java.lang.Object
  |
  +--com.dalsemi.comm.SPI

public class SPI
extends java.lang.Object

This class is a thin wrapper over a bit-bang SPI native library.
The bit-bang SPI port is implemented using pins ... (PCE0\-PCE3\) of the DS80C390. This is a master only implementation. P5.4 (PCE0\) = SSCK (Serial clock) P5.5 (PCE1\) = MOSI (Master Out/Slave In) P5.6 (PCE2\) = MISO (Master In/Slave Out) P5.7 (PCE3\) = SS (Slave select)

Note on noskew option: Do not attempt to use the noskew option of this SPI library with a *Large* Data Array. Using noskew turns off interrupts on TINI and will cause UNPREDICTABLE system behavior and watch dog reboots sending of a *Large* data array is attempted.


Field Summary
static int DEFAULT_CLOCK_DELAY
           
static int MAX_CLOCK_DELAY
           
 
Constructor Summary
SPI()
          Construct an SPI object with default configuration state which includes: DEFAULT_CLOCK_DELAY Allow skew i.e.
SPI(int delay, boolean noskew, boolean use_ss, boolean CPOL, boolean CPHA, boolean bitOrder, boolean slaveSelectInvert, boolean enableWordMode)
          Construct an SPI object with all configuration state specified.
 
Method Summary
 void enableMinimumClockSkew(boolean noskew)
          Disable interrupts during byte transfers to ensure a stable clock frequency.
 void enableSlaveSelect(boolean use_ss)
          Enable the use of the SS (slave select) line during communication.
 void setBitOrder(boolean bitOrder)
          Set the bit order that the SPI library will use during communication.
 void setClockDelay(int delay)
          Specify the number of microseconds to delay between clock edges.
 void setPhase(boolean CPHA)
          Select the Phase of the SCLK line.
 void setPolarity(boolean CPOL)
          Select the Polarity of the SCLK line.
 void setSlaveSelectInvert(boolean slaveSelectInvert)
          Sets the Invert option for Slave Select
 void setTransferSize(boolean enableWordMode)
          Sets the transfer size
 int xmit(byte[] ba, int off, int len)
          Write len bytes of data to MOSI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CLOCK_DELAY

public static final int DEFAULT_CLOCK_DELAY

MAX_CLOCK_DELAY

public static final int MAX_CLOCK_DELAY
Constructor Detail

SPI

public SPI()
Construct an SPI object with default configuration state which includes: DEFAULT_CLOCK_DELAY Allow skew i.e. interrupts during transfers Use the SS line Use SCLK idle low Use SCLK phase normal - sample on first clock edge Use most significant bit first transmission Use SS active LOW Use 8 bit transfer mode

SPI

public SPI(int delay,
           boolean noskew,
           boolean use_ss,
           boolean CPOL,
           boolean CPHA,
           boolean bitOrder,
           boolean slaveSelectInvert,
           boolean enableWordMode)
Construct an SPI object with all configuration state specified.
Parameters:
delay - # of microseconds of delay between clock edges
noskew - set to true to disable interrupts for strict clock rates
use_ss - set to true to enable use of the SS line Note on noskew option: Do not attempt to use the noskew option of this SPI library with a *Large* Data Array. Using noskew turns off interrupts on TINI and will cause UNPREDICTABLE system behavior and watch dog reboots if sending of a *Large* data array is attempted.
CPOL - set to true forces SCLK to idle high
CPHA - set to true sample on second SCLK edge i.e. CPOL = 0 -> sample on falling edge; CPOL = 1 -> sample on rising edge
bitOrder - set to true to use Least Significant Bit first transmission
slaveSelectInvert - set to true changes the SS line to be active high
enableWordMode - set to true does 16 bit transfers
Method Detail

xmit

public int xmit(byte[] ba,
                int off,
                int len)
Write len bytes of data to MOSI. Return data simultaneously read from MISO. Source data is contained in ba starting at off. Read data is returned in the same positions within the array.
Parameters:
ba - source byte array, contains data to be written to the SPI slave
off - starting offset into ba
len - number of bytes to write, if in word mode, this remains the number of bytes, NOT the number of 16 bit words. Also when using word mode, len of transfer must be an even number.

setClockDelay

public void setClockDelay(int delay)
                   throws java.lang.IllegalArgumentException
Specify the number of microseconds to delay between clock edges.
Parameters:
delay - The number of microseconds between clock edges
Throws:
java.lang.IllegalArgumentException - if delay is negative or greater than MAX_CLOCK_DELAY.

enableMinimumClockSkew

public void enableMinimumClockSkew(boolean noskew)
Disable interrupts during byte transfers to ensure a stable clock frequency. Many SPI devices don't require a precise clock frequency range. In this case, the application should allow clock skew due to system interrupts during SPI communication. By default, interrupts are enabled during communication. Note on noskew option: Do not attempt to use the noskew option of this SPI library with a *Large* Data Array. Using noskew turns off interrupts on TINI and will cause UNPREDICTABLE system behavior and watch dog reboots sending of a *Large* data array is attempted.
Parameters:
noskew - set to true to disable interrupts

enableSlaveSelect

public void enableSlaveSelect(boolean use_ss)
Enable the use of the SS (slave select) line during communication. If enabled , the SS line is asserted before each read or write operation and deasserted immediately following the operation. Otherwise this pin is ignored.
Parameters:
use_ss - set to true to force use of SS pin

setPolarity

public void setPolarity(boolean CPOL)
Select the Polarity of the SCLK line.
Parameters:
CPOL - set to true forces SCLK to idle high

setPhase

public void setPhase(boolean CPHA)
Select the Phase of the SCLK line.
Parameters:
CPHA - set to true sample on second SCLK edge i.e. CPOL = 0 -> sample on falling edge; CPOL = 1 -> sample on rising edge

setBitOrder

public void setBitOrder(boolean bitOrder)
Set the bit order that the SPI library will use during communication.
Parameters:
bitOrder - set to true to use Least Significant Bit first transmission

setSlaveSelectInvert

public void setSlaveSelectInvert(boolean slaveSelectInvert)
Sets the Invert option for Slave Select
Parameters:
slaveSelectInvert - set to true, the SS line will be active high, otherwise the SS line will be active low.

setTransferSize

public void setTransferSize(boolean enableWordMode)
Sets the transfer size
Parameters:
enableWordMode - set to true, transfers 16 bits at a time, otherwise 8 bits at a time


Also see:
o TINI 1.16 API
o TINI Home Page
o 1-Wire API

o JDK 1.1

Last update Wed Jun 8 17:19:36 CDT 2005