nanoFramework.System.Device.Spi 1.0.2-preview.20

This is a prerelease version of nanoFramework.System.Device.Spi.
There is a newer version of this package available.
See the version list below for details.
Install-Package nanoFramework.System.Device.Spi -Version 1.0.2-preview.20
dotnet add package nanoFramework.System.Device.Spi --version 1.0.2-preview.20
<PackageReference Include="nanoFramework.System.Device.Spi" Version="1.0.2-preview.20" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.System.Device.Spi --version 1.0.2-preview.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: nanoFramework.System.Device.Spi, 1.0.2-preview.20"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.System.Device.Spi as a Cake Addin
#addin nuget:?package=nanoFramework.System.Device.Spi&version=1.0.2-preview.20&prerelease

// Install nanoFramework.System.Device.Spi as a Cake Tool
#tool nuget:?package=nanoFramework.System.Device.Spi&version=1.0.2-preview.20&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo

Welcome to the .NET nanoFramework System.Device.Spi Library repository

Build status

Component Build Status NuGet Package
System.Device.Spi Build Status NuGet
System.Device.Spi (preview) Build Status NuGet


To create a SpiDevice, you need to follow this pattern:

SpiDevice spiDevice;
SpiConnectionSettings connectionSettings;
// Note: the ChipSelect pin should be adjusted to your device, here 12
// You can adjust as well the bus, here 1 for SPI1
connectionSettings = new SpiConnectionSettings(1, 12);
spiDevice = SpiDevice.Create(connectionSettings);

SpiConnectionSettings and SpiBusInfo

The SpiConnectionSettings contains the key elements needed to setup properly the hardware SPI device. Once created, those elements can't be adjusted.

connectionSettings.ChipSelectLineActiveState = PinValue.High; // Default is active Low
connectionSettings.ClockFrequency = 1_000_000;
connectionSettings.DataFlow = DataFlow.LsbFirst; // Default is MSB

To get the default bus values, especially the bus min and max frequencies, the maximum number of ChipSelect, you can use SpiBusInfo.

SpiBusInfo spiBusInfo = SpiDevice.GetBusInfo(1);
Debug.WriteLine($"{nameof(spiBusInfo.ChipSelectLineCount)}: {spiBusInfo.ChipSelectLineCount}");
Debug.WriteLine($"{nameof(spiBusInfo.MaxClockFrequency)}: {spiBusInfo.MaxClockFrequency}");
Debug.WriteLine($"{nameof(spiBusInfo.MinClockFrequency)}: {spiBusInfo.MinClockFrequency}");
Debug.WriteLine($"{nameof(spiBusInfo.SupportedDataBitLengths)}: ");
foreach(var data in spiBusInfo.SupportedDataBitLengths)
    Debug.WriteLine($"  {data}");

Reading and Writing

You can read, write and do a full transfer. You have the opportunity to use either a SpanByte, either a ushort array.

Important: in both cases, the data bit length will be automatically adjusted. So you can use both SpanByte and ushort array at the same time.

You can write a SpanByte like this:

SpanByte writeBuffer = new byte[2] { 42, 84 };

You can write a ushort array like this:

ushort[] writeBuffer = new ushort[2] { 4200, 8432 };

You can as well write a single byte:


Read operations are similar:

SpanByte readBuffer = new byte[2];
// This will read 2 bytes
ushort[] readUshort = new ushort[4];
// This will read 4 ushort
// read 1 byte
byte readMe = spiDevice.ReadByte();

For full transfer, you need to have 2 arrays of the same size and perform a full duplex transfer:

SpanByte writeBuffer = new byte[4] { 0xAA, 0xBB, 0xCC, 0x42 };
SpanByte readBuffer = new byte[4];
spiDevice.TransferFullDuplex(writeBuffer, readBuffer);
// Same for ushirt arrays:
ushort[] writeBuffer = new ushort[4] { 0xAABC, 0x00BB, 0xCC00, 0x4242 };
ushort[] readBuffer = new ushort[4];
spiDevice.TransferFullDuplex(writeBuffer, readBuffer);

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.


The list of contributors to this project can be found at CONTRIBUTORS.


The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

NuGet packages (20)

Showing the top 5 NuGet packages that depend on nanoFramework.System.Device.Spi:

Package Downloads

This package includes the .NET IoT Core binding Iot.Device.Apa102 for .NET nanoFramework C# projects.


This package includes the .NET IoT Core binding Iot.Device.Ws28xx for .NET nanoFramework C# projects.


This package includes the nanoFramework.M5Stack assembly for .NET nanoFramework C# projects.


This package includes the .NET IoT Core binding Iot.Device.AD5328 for .NET nanoFramework C# projects.


This package includes the .NET IoT Core binding Iot.Device.Max31865 for .NET nanoFramework C# projects.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on nanoFramework.System.Device.Spi:

Repository Stars
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
Version Downloads Last updated
1.0.3-preview.3 150 12/29/2021
1.0.2 928 12/3/2021
1.0.2-preview.31 45 12/2/2021
1.0.2-preview.29 38 12/2/2021
1.0.2-preview.27 35 12/2/2021
1.0.2-preview.25 34 12/2/2021
1.0.2-preview.22 31 12/2/2021
1.0.2-preview.20 40 12/1/2021
1.0.2-preview.17 5,921 11/23/2021
1.0.2-preview.15 188 11/13/2021
1.0.2-preview.13 182 10/23/2021
1.0.2-preview.11 421 10/18/2021
1.0.2-preview.5 598 7/16/2021
1.0.2-preview.3 59 7/16/2021
1.0.1 396 7/16/2021
1.0.0-preview.80 49 7/16/2021
1.0.0-preview.77 74 7/15/2021
1.0.0-preview.75 72 7/14/2021
1.0.0-preview.70 326 6/20/2021
1.0.0-preview.68 170 6/19/2021
1.0.0-preview.65 61 6/8/2021
1.0.0-preview.63 71 6/7/2021
1.0.0-preview.61 92 6/7/2021
1.0.0-preview.59 169 6/5/2021
1.0.0-preview.57 87 6/3/2021
1.0.0-preview.55 63 6/2/2021
1.0.0-preview.53 92 6/1/2021
1.0.0-preview.51 108 5/31/2021
1.0.0-preview.50 122 5/31/2021
1.0.0-preview.49 109 5/31/2021
1.0.0-preview.48 95 5/31/2021
1.0.0-preview.46 93 5/30/2021
1.0.0-preview.44 60 5/29/2021
1.0.0-preview.42 347 5/26/2021
1.0.0-preview.40 384 5/25/2021
1.0.0-preview.38 560 5/20/2021
1.0.0-preview.36 64 5/19/2021
1.0.0-preview.34 98 5/19/2021
1.0.0-preview.32 70 5/15/2021
1.0.0-preview.30 64 5/14/2021
1.0.0-preview.28 85 5/13/2021
1.0.0-preview.26 60 5/12/2021
1.0.0-preview.24 196 5/6/2021
1.0.0-preview.21 67 5/4/2021
1.0.0-preview.19 451 4/29/2021