Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.wpi.first.wpilibj
Class SPIDevice

    java.lang.Object
      edu.wpi.first.wpilibj.SensorBase
          edu.wpi.first.wpilibj.SPIDevice

    public class SPIDevice

extends SensorBase

Represents a device on an SPI bus Note that the cRIO only supports one SPI bus Attempting to open a second SPI device with a different shared pin (clk, mosi, miso) will result in an exception

Author:
  mwils

Nested Class Summary
`static class` | `SPIDevice.BadSPIConfigException`

Field Summary
`static boolean` | `BIT_ORDER_LSB_FIRST` When transferring data the it is sent and received with the least significant bit first
`static boolean` | `BIT_ORDER_MSB_FIRST` When transferring data the it is sent and received with the most significant bit first
`static boolean` | `CLOCK_POLARITY_ACTIVE_HIGH` When transferring data the clock will be active high This corresponds to CPOL=0
`static boolean` | `CLOCK_POLARITY_ACTIVE_LOW` When transferring data the clock will be active low This corresponds to CPOL=1
`static boolean` | `CS_ACTIVE_HIGH` The CS will be brought high when the device is selected
`static boolean` | `CS_ACTIVE_LOW` The CS will be brought low when the device is selected
`static boolean` | `DATA_ON_LEADING_EDGE` Data is valid on the leading edge of the clock pulse This corresponds to CPHA=0
`static boolean` | `DATA_ON_TRAILING_EDGE` Data is valid on the trailing edge of the clock pulse This corresponds to CPHA=1
`static char` | `FRAME_MODE_CHIP_SELECT` The chip select line is active for the duration of the frame.
`static char` | `FRAME_MODE_POST_LATCH` The chip select line pulses after the transfer of each frame.
`static char` | `FRAME_MODE_PRE_LATCH` The chip select line pulses before the transfer of each frame.
`static char` | `FRAME_MODE_PRE_POST_LATCH_PULSE` The chip select line pulses before and after each frame.
`double` | `MAX_CLOCK_FREQUENCY` The maximum rate the clock can transmit at
`double` | `MIN_CLOCK_FREQUENCY` The minimum rate the clock can transmit at

Fields inherited from class edu.wpi.first.wpilibj.SensorBase
`kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond`

Constructor Summary
`SPIDevice(DigitalOutput cs)` Create a new device on the SPI bus.
`SPIDevice(DigitalOutput cs, boolean csActiveHigh)` Create a new device on the SPI bus.
`SPIDevice(DigitalOutput clk, DigitalOutput mosi, DigitalInput miso, DigitalOutput cs)` Create a new device on the SPI bus.
`SPIDevice(DigitalOutput clk, DigitalOutput mosi, DigitalInput miso, DigitalOutput cs, boolean csActiveHigh)` Create a new device on the SPI bus.
`SPIDevice(int slot, int csChannel)` Create a new device on the SPI bus.
`SPIDevice(int slot, int csChannel, boolean csActiveHigh)` Create a new device on the SPI bus.
`SPIDevice(int slot, int clkChannel, int mosiChannel, int misoChannel, int csChannel)` Create a new device on the SPI bus.
`SPIDevice(int slot, int clkChannel, int mosiChannel, int misoChannel, int csChannel, boolean csActiveHigh)` Create a new device on the SPI bus.

Method Summary
`void` | `free()` Free the resources used by this object
`void` | `setBitOrder(boolean bitOrder)` Sets the bit order of the transfer sent and received values.
`void` | `setClockPolarity(boolean clockPolarity)` Sets the polarity of the clock when transferring data to the device
`void` | `setClockRate(double hz)` Set the frequence of the clock when sending data
`void` | `setDataOnTrailing(boolean dataOnTrailing)` If Data is valid at the beginning of the clock pulse or the end of the clock pulse
`void` | `setFrameMode(char frameMode)` Sets the Frame Mode which specifies the behavior of the chip select line in relation to the duration of the frame.
`long[]` | `transfer(long[] writeValues, int[] numBits)` Perform a SPI transfer where an array of bits are written and read.
`long` | `transfer(long writeValue, int numBits)` Perform a SPI transfer with the length of this device's current configuration.

Methods inherited from class edu.wpi.first.wpilibj.SensorBase
`checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### BIT_ORDER_MSB_FIRST

    public static final boolean BIT_ORDER_MSB_FIRST

  When transferring data the it is sent and received with the most significant bit first

  See Also:
    `setBitOrder(boolean)`, Constant Field Values

### BIT_ORDER_LSB_FIRST

    public static final boolean BIT_ORDER_LSB_FIRST

  When transferring data the it is sent and received with the least significant bit first

  See Also:
    `setBitOrder(boolean)`, Constant Field Values

### CLOCK_POLARITY_ACTIVE_HIGH

    public static final boolean CLOCK_POLARITY_ACTIVE_HIGH

  When transferring data the clock will be active high
  This corresponds to CPOL=0

  See Also:
    `setClockPolarity(boolean)`, Constant Field Values

### CLOCK_POLARITY_ACTIVE_LOW

    public static final boolean CLOCK_POLARITY_ACTIVE_LOW

  When transferring data the clock will be active low
  This corresponds to CPOL=1

  See Also:
    `setClockPolarity(boolean)`, Constant Field Values

### DATA_ON_LEADING_EDGE

    public static final boolean DATA_ON_LEADING_EDGE

  Data is valid on the leading edge of the clock pulse
  This corresponds to CPHA=0

  See Also:
    `#setDataOnFalling(boolean)`, Constant Field Values

### DATA_ON_TRAILING_EDGE

    public static final boolean DATA_ON_TRAILING_EDGE

  Data is valid on the trailing edge of the clock pulse
  This corresponds to CPHA=1

  See Also:
    `#setDataOnFalling(boolean)`, Constant Field Values

### CS_ACTIVE_HIGH

    public static final boolean CS_ACTIVE_HIGH

  The CS will be brought high when the device is selected

  See Also:
    Constant Field Values

### CS_ACTIVE_LOW

    public static final boolean CS_ACTIVE_LOW

  The CS will be brought low when the device is selected

  See Also:
    Constant Field Values

### FRAME_MODE_CHIP_SELECT

    public static final char FRAME_MODE_CHIP_SELECT

  The chip select line is active for the duration of the frame.

  See Also:
    `setFrameMode(char)`, Constant Field Values

### FRAME_MODE_PRE_LATCH

    public static final char FRAME_MODE_PRE_LATCH

  The chip select line pulses before the transfer of each frame.

  See Also:
    `setFrameMode(char)`, Constant Field Values

### FRAME_MODE_POST_LATCH

    public static final char FRAME_MODE_POST_LATCH

  The chip select line pulses after the transfer of each frame.

  See Also:
    `setFrameMode(char)`, Constant Field Values

### FRAME_MODE_PRE_POST_LATCH_PULSE

    public static final char FRAME_MODE_PRE_POST_LATCH_PULSE

  The chip select line pulses before and after each frame.

  See Also:
    `setFrameMode(char)`, Constant Field Values

### MAX_CLOCK_FREQUENCY

    public final double MAX_CLOCK_FREQUENCY

  The maximum rate the clock can transmit at

### MIN_CLOCK_FREQUENCY

    public final double MIN_CLOCK_FREQUENCY

  The minimum rate the clock can transmit at

Constructor Detail

### SPIDevice

    public SPIDevice(int slot,
                     int clkChannel,
                     int mosiChannel,
                     int misoChannel,
                     int csChannel)

  Create a new device on the SPI bus. The chip select line is active low

  Parameters:
    `slot` - The module of the digital IO for the device
    `clkChannel` - The channel number for the clk channel
    `mosiChannel` - The channel number for the mosi (output) channel
    `misoChannel` - The channel number for the miso (input) channel
    `csChannel` - The channel number for the chip select channel

### SPIDevice

    public SPIDevice(int slot,
                     int clkChannel,
                     int mosiChannel,
                     int misoChannel,
                     int csChannel,
                     boolean csActiveHigh)

  Create a new device on the SPI bus.

  Parameters:
    `slot` - The module of the digital IO for the device
    `clkChannel` - The channel number for the clk channel
    `mosiChannel` - The channel number for the mosi (output) channel
    `misoChannel` - The channel number for the miso (input) channel
    `csChannel` - The channel number for the chip select channel
    `csActiveHigh` - True if the chip select line should be high when the device is selected. False if it should be low.

### SPIDevice

    public SPIDevice(DigitalOutput clk,
                     DigitalOutput mosi,
                     DigitalInput miso,
                     DigitalOutput cs)

  Create a new device on the SPI bus. The chip select line is active low

  Parameters:
    `clk` - The clock channel
    `mosi` - The mosi (output) channel
    `miso` - The miso (input) channel
    `cs` - The chip select channel

### SPIDevice

    public SPIDevice(DigitalOutput clk,
                     DigitalOutput mosi,
                     DigitalInput miso,
                     DigitalOutput cs,
                     boolean csActiveHigh)

  Create a new device on the SPI bus.

  Parameters:
    `clk` - The clock channel
    `mosi` - The mosi (output) channel
    `miso` - The miso (input) channel
    `cs` - The chip select channel
    `csActiveHigh` - True if the chip select line should be high when the device is selected. False if it should be low.

### SPIDevice

    public SPIDevice(int slot,
                     int csChannel)

  Create a new device on the SPI bus. Must only be used after a device has been created establishing the clk, mosi and miso channels. The chip select line is active low

  Parameters:
    `slot` - The module of the digital output for the device's chip select pin
    `csChannel` - The channel for the digital output for the device's chip select pin

### SPIDevice

    public SPIDevice(int slot,
                     int csChannel,
                     boolean csActiveHigh)

  Create a new device on the SPI bus. Must only be used after a device has been created establishing the clk, mosi and miso channels.

  Parameters:
    `slot` - The module of the digital output for the device's chip select pin
    `csChannel` - The channel for the digital output for the device's chip select pin
    `csActiveHigh` - True if the chip select line should be high when the device is selected. False if it should be low.

### SPIDevice

    public SPIDevice(DigitalOutput cs)

  Create a new device on the SPI bus. Must only be used after a device has been created establishing the clk, mosi and miso channels. The chip select line is active low

  Parameters:
    `cs` - The chip select channel

### SPIDevice

    public SPIDevice(DigitalOutput cs,
                     boolean csActiveHigh)

  Create a new device on the SPI bus. Must only be used after a device has been created establishing the clk, mosi and miso channels.

  Parameters:
    `cs` - The chip select channel
    `csActiveHigh` - True if the chip select line should be high when the device is selected. False if it should be low.

Method Detail

### free

    public void free()

  Free the resources used by this object

  Overrides:
    `free` in class `SensorBase`

### transfer

    public long transfer(long writeValue,
                         int numBits)

  Perform a SPI transfer with the length of this device's current configuration. This will select the device, transfer the data and then deselect the device

  Parameters:
    `writeValue` - The value to write to the device
    `numBits` - The number of bits to write/read

### transfer

    public long[] transfer(long[] writeValues,
                           int[] numBits)

  Perform a SPI transfer where an array of bits are written and read. The number of bits to write and read is specified in numBits
  The whole transfer will occur with the cs line held active throughout

  Parameters:
    `writeValues` - The value to write to the device
    `numBits` - The number of bits to write/read

### setBitOrder

    public final void setBitOrder(boolean bitOrder)

  Sets the bit order of the transfer sent and received values. The value transfered/received will always be the lowest bits of the value. This method just sets the order in which those bits are transfered.

  Parameters:
    `bitOrder` - true=Most significant bit first, false=Least significant bit first
  See Also:
    `BIT_ORDER_MSB_FIRST`, `BIT_ORDER_LSB_FIRST`

### setClockPolarity

    public final void setClockPolarity(boolean clockPolarity)

  Sets the polarity of the clock when transferring data to the device

  Parameters:
    `clockPolarity` - true=Clock active low, false=Clock active high
  See Also:
    `CLOCK_POLARITY_ACTIVE_HIGH`, `CLOCK_POLARITY_ACTIVE_LOW`

### setDataOnTrailing

    public final void setDataOnTrailing(boolean dataOnTrailing)

  If Data is valid at the beginning of the clock pulse or the end of the clock pulse

  Parameters:
    `dataOnTrailing` - true=Process data on the trailing edge of the clock, false=Process data on leading edge of the clock
  See Also:
    `DATA_ON_LEADING_EDGE`, `DATA_ON_TRAILING_EDGE`

### setFrameMode

    public final void setFrameMode(char frameMode)

  Sets the Frame Mode which specifies the behavior of the chip select line in relation to the duration of the frame.

  Parameters:
    `frameMode` - 0 = low for duration of frame, 1 = pulse before transfer, 2 = pulse after transfer, 3 = pulse before and after transfer
  See Also:
    `FRAME_MODE_CHIP_SELECT`, `FRAME_MODE_PRE_LATCH`, `FRAME_MODE_POST_LATCH`, `FRAME_MODE_PRE_POST_LATCH_PULSE`

### setClockRate

    public final void setClockRate(double hz)

  Set the frequence of the clock when sending data

  Parameters:
    `hz` - The frequency of the clock in hz
  See Also:
    `MIN_CLOCK_FREQUENCY`, `MAX_CLOCK_FREQUENCY`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"