nanoFramework.System.Device.I2c.Slave
1.0.19
Prefix Reserved
See the version list below for details.
dotnet add package nanoFramework.System.Device.I2c.Slave --version 1.0.19
NuGet\Install-Package nanoFramework.System.Device.I2c.Slave -Version 1.0.19
<PackageReference Include="nanoFramework.System.Device.I2c.Slave" Version="1.0.19" />
paket add nanoFramework.System.Device.I2c.Slave --version 1.0.19
#r "nuget: nanoFramework.System.Device.I2c.Slave, 1.0.19"
// Install nanoFramework.System.Device.I2c.Slave as a Cake Addin #addin nuget:?package=nanoFramework.System.Device.I2c.Slave&version=1.0.19 // Install nanoFramework.System.Device.I2c.Slave as a Cake Tool #tool nuget:?package=nanoFramework.System.Device.I2c.Slave&version=1.0.19
Welcome to the .NET nanoFramework System.Device.I2c.Slave Library repository
This repository contains the .NET nanoFramework System.Device.I2c.Slave class library.
Build status
Component | Build Status | NuGet Package |
---|---|---|
System.Device.I2c.Slave |
System.Device.I2c.Slave usage
Creating an I2C slave device
To instantiate a new I2C slave device call the constructor passing the device address in the parameter and the I2C hardware bus where this device will be exposed from. Like this:
// create an I2C slave device on bus 1 with address 0x10
var device = new I2cSlaveDevice(1, 0x10);
Typical read/write operation
A common operation on an I2C device is to read the content of a specified address. The following code snippet reads a byte with the "register address" and returns the content as an array of two bytes. For simplicity no timeouts will be specified. Be aware that there are overloaded methods on the API that accept a timeout parameter in milliseconds.
byte registerAddress;
if(device.ReadByte(out registerAddress))
{
switch(registerAddress)
{
// (...)
// return dummy content for register 0x22
case 0x22:
device.Write(new byte[] { 0xBE, 0xEF});
break;
// (...)
}
}
From the I2C master end, assuming that's a .NET nanoFramework device, using the System.Device.I2c library, the code to perform the above operation on a slave device on I2C bus 1 would be like this:
// create I2C device
var myI2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x10, I2cBusSpeed.FastMode));
// setup read buffer
var buffer = new byte[2];
// set address to read from
myI2cDevice.Write(new byte[] { 0x22 });
myI2cDevice.Read(buffer);
// expected buffer content is: 0xBE, 0xEF
Console.Writeline($"Register content: {buffer[0]:X2} {buffer[1]:X2}")
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.16.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on nanoFramework.System.Device.I2c.Slave:
Repository | Stars |
---|---|
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
|