BBBCSIO

The SPISlaveDeviceHandle Class

 

The SPISlaveDeviceHandle Class

Provides a container to transport information on an open Slave Device around the system.

The BBB SPI ports are internally capable of 4 slave select lines. However, of those 4 only two for each port are visible to the pinmux and, of those two, for SPI0 only CS0 is actually available on the P8/9 headers. SPI1 has both CS0 and CS1 available on the P9 header but on pins that collide with the HDMI muxed pins.

The upshot is that, unless you wish to disable HDMI, you have to use SPI port 0 and you will only have one built in slave select (CS0) line available to you. This means you have to use regular GPIO outputs to implement the Slave Select for more than one device. The SPI ports cope with this and manage it all internally and a slave device configured on a GPIO can be used in exactly the same way as 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.