Treehopper C# API
SpiDevice Class Reference

Represents a peripheral attached to the SPI bus More...

Public Member Functions

 SpiDevice (Spi spiModule, SpiChipSelectPin chipSelect, ChipSelectMode chipSelectMode=ChipSelectMode.SpiActiveLow, double speedMhz=6, SpiMode mode=SpiMode.Mode00)
 Construct an SPI device attached to a particular module More...
 
Task< byte[]> SendReceiveAsync (byte[] dataToSend, SpiBurstMode burst=SpiBurstMode.NoBurst)
 Start an SPI transaction More...
 

Properties

SpiChipSelectPin ChipSelect [get, protected set]
 Get or set the pin to use for chip-select duties. More...
 
SpiMode Mode [get, protected set]
 Get or set the SPI module's mode More...
 
double Frequency [get, set]
 Gets or sets the Frequency, in MHz, that this device will use for SPI communication. More...
 
ChipSelectMode ChipSelectMode [get, protected set]
 The chip select mode to use with transactions More...
 

Detailed Description

Represents a peripheral attached to the SPI bus

Constructor & Destructor Documentation

◆ SpiDevice()

SpiDevice ( Spi  spiModule,
SpiChipSelectPin  chipSelect,
ChipSelectMode  chipSelectMode = ChipSelectMode.SpiActiveLow,
double  speedMhz = 6,
SpiMode  mode = SpiMode.Mode00 
)

Construct an SPI device attached to a particular module

Parameters
spiModuleThe module this device is attached to
chipSelectThe chip select pin used by this device
chipSelectModeThe ChipSelectMode to use with this device
speedMhzThe speed to operate this device at
modeThe SpiMode of this device

Member Function Documentation

◆ SendReceiveAsync()

Task<byte[]> SendReceiveAsync ( byte []  dataToSend,
SpiBurstMode  burst = SpiBurstMode.NoBurst 
)

Start an SPI transaction

Parameters
dataToSendThe data to send
burstThe burst mode, if any, to use
Returns
Data received by the peripheral

Property Documentation

◆ ChipSelect

SpiChipSelectPin ChipSelect
getprotected set

Get or set the pin to use for chip-select duties.

Almost every SPI peripheral chip has some sort of chip select (which may be called load, strobe, or enable, depending on the type of chip). You can use any Pin for chip-select duties as long as it belongs to the same board as this SPI peripheral (i.e., you can't use a pin from one Treehopper as a chip-select for the SPI port on another Treehopper). Chip-selects are controlled at the firmware, not peripheral, level, which offers quite a bit of flexibility in choosing the behavior. Make sure to set ChipSelectMode properly for your device.

◆ Mode

SpiMode Mode
getprotected set

Get or set the SPI module's mode

The SPI module supports the four SPI modes: 00, 01, 10, 11. See SpiMode for more info.

◆ Frequency

double Frequency
getset

Gets or sets the Frequency, in MHz, that this device will use for SPI communication.

The SPI module can operate from 0.09375 MHz (93.75 kHz) to 24 MHz. Setting Frequency outside of those limits will result in clipping, plus a debug notice. Note that SPI transfers are managed by the CPU, as Treehopper's MCU has no DMA. As a result, there are diminishing performance returns above 8 MHz, as dead space starts appearing between bytes as the SPI module waits for the CPU to push the next byte into the register.

◆ ChipSelectMode

ChipSelectMode ChipSelectMode
getprotected set

The chip select mode to use with transactions


The documentation for this class was generated from the following file: