nanoFramework.System.Device.I2c.Slave 1.0.6

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package nanoFramework.System.Device.I2c.Slave --version 1.0.6
NuGet\Install-Package nanoFramework.System.Device.I2c.Slave -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.System.Device.I2c.Slave" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.System.Device.I2c.Slave --version 1.0.6
#r "nuget: nanoFramework.System.Device.I2c.Slave, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.System.Device.I2c.Slave as a Cake Addin
#addin nuget:?package=nanoFramework.System.Device.I2c.Slave&version=1.0.6

// Install nanoFramework.System.Device.I2c.Slave as a Cake Tool
#tool nuget:?package=nanoFramework.System.Device.I2c.Slave&version=1.0.6

Quality Gate Status Reliability Rating NuGet #yourfirstpr Discord

nanoFramework logo


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 Build Status NuGet

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 Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 235 11/9/2023
1.0.5 103 11/8/2023