|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.wpi.first.wpilibj.SensorBase
edu.wpi.first.wpilibj.SPIDevice
public class SPIDevice
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
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 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean BIT_ORDER_MSB_FIRST
setBitOrder(boolean)
,
Constant Field Valuespublic static final boolean BIT_ORDER_LSB_FIRST
setBitOrder(boolean)
,
Constant Field Valuespublic static final boolean CLOCK_POLARITY_ACTIVE_HIGH
setClockPolarity(boolean)
,
Constant Field Valuespublic static final boolean CLOCK_POLARITY_ACTIVE_LOW
setClockPolarity(boolean)
,
Constant Field Valuespublic static final boolean DATA_ON_LEADING_EDGE
#setDataOnFalling(boolean)
,
Constant Field Valuespublic static final boolean DATA_ON_TRAILING_EDGE
#setDataOnFalling(boolean)
,
Constant Field Valuespublic static final boolean CS_ACTIVE_HIGH
public static final boolean CS_ACTIVE_LOW
public static final char FRAME_MODE_CHIP_SELECT
setFrameMode(char)
,
Constant Field Valuespublic static final char FRAME_MODE_PRE_LATCH
setFrameMode(char)
,
Constant Field Valuespublic static final char FRAME_MODE_POST_LATCH
setFrameMode(char)
,
Constant Field Valuespublic static final char FRAME_MODE_PRE_POST_LATCH_PULSE
setFrameMode(char)
,
Constant Field Valuespublic final double MAX_CLOCK_FREQUENCY
public final double MIN_CLOCK_FREQUENCY
Constructor Detail |
---|
public SPIDevice(int slot, int clkChannel, int mosiChannel, int misoChannel, int csChannel)
slot
- The module of the digital IO for the deviceclkChannel
- The channel number for the clk channelmosiChannel
- The channel number for the mosi (output) channelmisoChannel
- The channel number for the miso (input) channelcsChannel
- The channel number for the chip select channelpublic SPIDevice(int slot, int clkChannel, int mosiChannel, int misoChannel, int csChannel, boolean csActiveHigh)
slot
- The module of the digital IO for the deviceclkChannel
- The channel number for the clk channelmosiChannel
- The channel number for the mosi (output) channelmisoChannel
- The channel number for the miso (input) channelcsChannel
- The channel number for the chip select channelcsActiveHigh
- True if the chip select line should be high when
the device is selected. False if it should be low.public SPIDevice(DigitalOutput clk, DigitalOutput mosi, DigitalInput miso, DigitalOutput cs)
clk
- The clock channelmosi
- The mosi (output) channelmiso
- The miso (input) channelcs
- The chip select channelpublic SPIDevice(DigitalOutput clk, DigitalOutput mosi, DigitalInput miso, DigitalOutput cs, boolean csActiveHigh)
clk
- The clock channelmosi
- The mosi (output) channelmiso
- The miso (input) channelcs
- The chip select channelcsActiveHigh
- True if the chip select line should be high when
the device is selected. False if it should be low.public SPIDevice(int slot, int csChannel)
slot
- The module of the digital output for the device's chip select pincsChannel
- The channel for the digital output for the device's chip select pinpublic SPIDevice(int slot, int csChannel, boolean csActiveHigh)
slot
- The module of the digital output for the device's chip select pincsChannel
- The channel for the digital output for the device's chip select pincsActiveHigh
- True if the chip select line should be high when
the device is selected. False if it should be low.public SPIDevice(DigitalOutput cs)
cs
- The chip select channelpublic SPIDevice(DigitalOutput cs, boolean csActiveHigh)
cs
- The chip select channelcsActiveHigh
- True if the chip select line should be high when
the device is selected. False if it should be low.Method Detail |
---|
public void free()
free
in class SensorBase
public long transfer(long writeValue, int numBits)
writeValue
- The value to write to the devicenumBits
- The number of bits to write/readpublic long[] transfer(long[] writeValues, int[] numBits)
writeValues
- The value to write to the devicenumBits
- The number of bits to write/readpublic final void setBitOrder(boolean bitOrder)
bitOrder
- true=Most significant bit first, false=Least significant
bit firstBIT_ORDER_MSB_FIRST
,
BIT_ORDER_LSB_FIRST
public final void setClockPolarity(boolean clockPolarity)
clockPolarity
- true=Clock active low, false=Clock active highCLOCK_POLARITY_ACTIVE_HIGH
,
CLOCK_POLARITY_ACTIVE_LOW
public final void setDataOnTrailing(boolean dataOnTrailing)
dataOnTrailing
- true=Process data on the trailing edge of the clock,
false=Process data on leading edge of the clockDATA_ON_LEADING_EDGE
,
DATA_ON_TRAILING_EDGE
public final void setFrameMode(char frameMode)
frameMode
- 0 = low for duration of frame, 1 = pulse before transfer,
2 = pulse after transfer, 3 = pulse before and after transferFRAME_MODE_CHIP_SELECT
,
FRAME_MODE_PRE_LATCH
,
FRAME_MODE_POST_LATCH
,
FRAME_MODE_PRE_POST_LATCH_PULSE
public final void setClockRate(double hz)
hz
- The frequency of the clock in hzMIN_CLOCK_FREQUENCY
,
MAX_CLOCK_FREQUENCY
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |