RPICSIO
The SPISlaveDeviceHandle Class
The SPISlaveDeviceHandle Class
Provides a container to transport information on an open Slave Device around the system.
The RPI SPI port is capable of 2 slave select lines. This means that if you wish to control more than two devices you will have to use regular GPIO outputs to implement the Slave Selects for them. The RPICSIO SPIPortFS class copes with this and manages it all internally and a slave device configured on a GPIO can be used in exactly the same way as once controlled with the built-in slave select line.
Source Code
The source code for this class is available online for
download
and also in
browseable form.
Example Code
Example code which demonstrates the use of this class can be found on the SPI Port Example page.
Syntax
public class SPISlaveDeviceHandle
Provides a container to transport information on an open Slave Device around the system.
Public Constructors
public SPISlaveDeviceHandle()
Default Constructor.
public SPISlaveDeviceHandle(SPISlaveDeviceEnum spiSlaveDeviceIn, int spiDevFileDescriptorIn)
Constructor.
- Parameters
- spiSlaveDeviceIn - The SPI slave device.
- spiDevFileDescriptorIn - The SPI file descriptor.
public SPISlaveDeviceHandle(SPISlaveDeviceEnum spiSlaveDeviceIn, OutputPortMM gpioSlaveSelectIn)
Constructor.
- Parameters
- spiSlaveDeviceIn - The SPI slave device.
- gpioSlaveSelectIn - The GPIO output port acting as the slave select line.
Public Methods
public void Reset()
Resets the object to the default state
Public Properties
public byte BitsPerWord { get;set }
Get/Set the bits_per_word for the slave device. Overrides the SPI port
defaults
- value
- The bits per word for theslave device.
public byte CSChange { get;set }
Get/Set the cs change flag for this slave device. If nz device will be deselected and reselected before
starting the next transfer.
- value
- nz means toggle the Slave Select line for each transfer.
public UInt16 DelayUSecs { get;set }
Get/Set the delay_usecs for this slave device. If nonzero, indicates how long to delay after the last bit
transfer before optionally deselecting the device before the next transfer.
- value
- The delay time in microseconds.
public OutputPortMM GpioSlaveSelect { get;set }
Get/Set the port which acts as the GPIO based slave select. Only
meaningful when the SlaveDevice is SPISlaveDeviceEnum.SPI_SLAVEDEVICE_GPIO
- value
- The GPIO Slave Select port.
public int SpiDevFileDescriptor { get;set }
Get/Set the spiDevFileDescriptor. Only meaningful when the SlaveDevice
is SPISlaveDeviceEnum.SPI_SLAVEDEVICE_CS*
- value
- The SPIDev file descriptor or -1 for not open.
public SPISlaveDeviceEnum SPISlaveDevice { get;set }
Get/Set the spiSlaveDevice.
- value
- The SPI Slave Device Enum.