nanoFramework.System.Device.Spi
1.3.52
Prefix Reserved
dotnet add package nanoFramework.System.Device.Spi --version 1.3.52
NuGet\Install-Package nanoFramework.System.Device.Spi -Version 1.3.52
<PackageReference Include="nanoFramework.System.Device.Spi" Version="1.3.52" />
paket add nanoFramework.System.Device.Spi --version 1.3.52
#r "nuget: nanoFramework.System.Device.Spi, 1.3.52"
// Install nanoFramework.System.Device.Spi as a Cake Addin #addin nuget:?package=nanoFramework.System.Device.Spi&version=1.3.52 // Install nanoFramework.System.Device.Spi as a Cake Tool #tool nuget:?package=nanoFramework.System.Device.Spi&version=1.3.52
Welcome to the .NET nanoFramework System.Device.Spi Library repository
Build status
Component | Build Status | NuGet Package |
---|---|---|
System.Device.Spi |
Usage
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);
If you'll be controlling the state of the Chip Select line, you need to pass -1
to the second parameter of SpiConnectionSettings(...)
. When specifying a GPIO number the driver takes care of this for you by setting the appropriate state for the signal during the SPI transactions.
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.MaxClockFrequency)}: {spiBusInfo.MaxClockFrequency}");
Debug.WriteLine($"{nameof(spiBusInfo.MinClockFrequency)}: {spiBusInfo.MinClockFrequency}");
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 };
spiDevice.Write(writeBuffer);
You can write a ushort
array like this:
ushort[] writeBuffer = new ushort[2] { 4200, 8432 };
spiDevice.Write(writeBuffer);
You can as well write a single byte:
spiDevice.WriteByte(42);
Read operations are similar:
SpanByte readBuffer = new byte[2];
// This will read 2 bytes
spiDevice.Read(readBuffer);
ushort[] readUshort = new ushort[4];
// This will read 4 ushort
spiDevice.Read(readUshort);
// 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.
Credits
The list of contributors to this project can be found at CONTRIBUTORS.
License
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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.Runtime.Events (>= 1.11.18)
- nanoFramework.System.Device.Gpio (>= 1.1.41)
NuGet packages (32)
Showing the top 5 NuGet packages that depend on nanoFramework.System.Device.Spi:
Package | Downloads |
---|---|
nanoFramework.M5Core2
This package includes the nanoFramework.M5Core2 assembly for .NET nanoFramework C# projects. |
|
nanoFramework.M5Core
This package includes the nanoFramework.M5Core assembly for .NET nanoFramework C# projects. |
|
nanoFramework.AtomLite
This package includes the nanoFramework.AtomLite assembly for .NET nanoFramework C# projects. |
|
nanoFramework.AtomMatrix
This package includes the nanoFramework.AtomMatrix assembly for .NET nanoFramework C# projects. |
|
nanoFramework.Iot.Device.ShiftRegister
This package includes the .NET IoT Core binding Iot.Device.ShiftRegister for .NET nanoFramework C# projects. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on nanoFramework.System.Device.Spi:
Repository | Stars |
---|---|
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
|
|
nanoframework/nanoFramework.IoT.Device
📦 This repo includes .NET nanoFramework implementations for various sensors, chips, displays, hats and drivers
|
Version | Downloads | Last updated |
---|---|---|
1.3.52 | 8,361 | 5/27/2024 |
1.3.48 | 1,438 | 5/10/2024 |
1.3.43 | 9,076 | 11/9/2023 |
1.3.41 | 186 | 11/9/2023 |
1.3.37 | 44,536 | 12/27/2022 |
1.3.34 | 490 | 12/27/2022 |
1.3.32 | 425 | 12/22/2022 |
1.3.30 | 337 | 12/22/2022 |
1.3.22 | 37,321 | 10/11/2022 |
1.3.18 | 15,001 | 9/23/2022 |
1.3.15 | 21,147 | 9/14/2022 |
1.3.12 | 462 | 9/13/2022 |
1.3.8 | 7,681 | 9/7/2022 |
1.3.4 | 39,784 | 7/12/2022 |
1.3.2 | 10,425 | 7/6/2022 |
1.2.1 | 85,890 | 4/25/2022 |
1.1.1 | 14,280 | 4/21/2022 |
1.0.5 | 31,849 | 3/29/2022 |
1.0.5-preview.5 | 143 | 3/29/2022 |
1.0.5-preview.3 | 138 | 3/29/2022 |
1.0.4 | 154 | 3/28/2022 |
1.0.4-preview.14 | 132 | 3/28/2022 |
1.0.4-preview.11 | 374 | 3/17/2022 |
1.0.4-preview.9 | 152 | 3/17/2022 |
1.0.4-preview.7 | 225 | 3/14/2022 |
1.0.4-preview.5 | 140 | 3/14/2022 |
1.0.4-preview.3 | 423 | 3/3/2022 |
1.0.4-preview.1 | 232 | 2/24/2022 |
1.0.3-preview.24 | 205 | 2/18/2022 |
1.0.3-preview.21 | 136 | 2/17/2022 |
1.0.3-preview.19 | 304 | 2/4/2022 |
1.0.3-preview.17 | 323 | 1/28/2022 |
1.0.3-preview.15 | 149 | 1/28/2022 |
1.0.3-preview.13 | 151 | 1/28/2022 |
1.0.3-preview.11 | 250 | 1/22/2022 |
1.0.3-preview.9 | 196 | 1/21/2022 |
1.0.3-preview.7 | 160 | 1/21/2022 |
1.0.3-preview.5 | 160 | 1/21/2022 |
1.0.3-preview.3 | 353 | 12/29/2021 |
1.0.2 | 6,422 | 12/3/2021 |
1.0.2-preview.31 | 164 | 12/2/2021 |
1.0.2-preview.29 | 154 | 12/2/2021 |
1.0.2-preview.27 | 153 | 12/2/2021 |
1.0.2-preview.25 | 169 | 12/2/2021 |
1.0.2-preview.22 | 151 | 12/2/2021 |
1.0.2-preview.20 | 159 | 12/1/2021 |
1.0.2-preview.17 | 5,993 | 11/23/2021 |
1.0.2-preview.15 | 340 | 11/13/2021 |
1.0.2-preview.13 | 306 | 10/23/2021 |
1.0.2-preview.11 | 545 | 10/18/2021 |
1.0.2-preview.5 | 712 | 7/16/2021 |
1.0.2-preview.3 | 176 | 7/16/2021 |
1.0.1 | 996 | 7/16/2021 |
1.0.0-preview.80 | 166 | 7/16/2021 |
1.0.0-preview.77 | 201 | 7/15/2021 |
1.0.0-preview.75 | 192 | 7/14/2021 |
1.0.0-preview.70 | 442 | 6/20/2021 |
1.0.0-preview.68 | 291 | 6/19/2021 |
1.0.0-preview.65 | 182 | 6/8/2021 |
1.0.0-preview.63 | 196 | 6/7/2021 |
1.0.0-preview.61 | 215 | 6/7/2021 |
1.0.0-preview.59 | 274 | 6/5/2021 |
1.0.0-preview.57 | 189 | 6/3/2021 |
1.0.0-preview.55 | 177 | 6/2/2021 |
1.0.0-preview.53 | 205 | 6/1/2021 |
1.0.0-preview.51 | 216 | 5/31/2021 |
1.0.0-preview.50 | 236 | 5/31/2021 |
1.0.0-preview.49 | 224 | 5/31/2021 |
1.0.0-preview.48 | 202 | 5/31/2021 |
1.0.0-preview.46 | 203 | 5/30/2021 |
1.0.0-preview.44 | 180 | 5/29/2021 |
1.0.0-preview.42 | 469 | 5/26/2021 |
1.0.0-preview.40 | 505 | 5/25/2021 |
1.0.0-preview.38 | 728 | 5/20/2021 |
1.0.0-preview.36 | 178 | 5/19/2021 |
1.0.0-preview.34 | 201 | 5/19/2021 |
1.0.0-preview.32 | 184 | 5/15/2021 |
1.0.0-preview.30 | 176 | 5/14/2021 |
1.0.0-preview.28 | 196 | 5/13/2021 |
1.0.0-preview.26 | 181 | 5/12/2021 |
1.0.0-preview.24 | 304 | 5/6/2021 |
1.0.0-preview.21 | 177 | 5/4/2021 |
1.0.0-preview.19 | 558 | 4/29/2021 |