MCP2221IO 3.0.0

dotnet add package MCP2221IO --version 3.0.0                
NuGet\Install-Package MCP2221IO -Version 3.0.0                
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="MCP2221IO" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MCP2221IO --version 3.0.0                
#r "nuget: MCP2221IO, 3.0.0"                
#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 MCP2221IO as a Cake Addin
#addin nuget:?package=MCP2221IO&version=3.0.0

// Install MCP2221IO as a Cake Tool
#tool nuget:?package=MCP2221IO&version=3.0.0                

Build Status

NuGet Badge

MCP2221IO

A .Net Core library to interact with Usb MCP2221/MCP2221A devices. For example the ADM00559 device.

Installing MCP2221IO

Install the MCP2221IO package via nuget package manager console:

Install-Package MCP2221IO

Or from the dot net command line console

dotnet add package MCP2221IO

Supported Functions

The following is the list of functions supported by the API.

  • Status/Set Parameters
    • Cancel I2C Transfer
    • Set I2C Speed
  • Read Flash Data
    • Read Chip Settings
    • Read GP Settings
    • Read USB Manufacturer Descriptor String
    • Read USB Product Descriptor String
    • Read USB Serial Number Descriptor String
    • Read Chip Factory Serial Number
  • Write Flash Data
    • Write Chip Settings
    • Write GP Settings
    • Write USB Manufacturer Descriptor String
    • Write USB Product Descriptor String
    • Write USB Serial Number Descriptor String
    • Write Chip Factory Serial Number
  • Send Access Flash Password
  • I2C Operations (7 Bit And 10 Bit address)
    • Scan Bus
    • Write Data
    • Write Data Repeated-Start
    • Write Data No Stop
    • Read Data
    • Read Data Repeated-Start
  • Set GPIO (Output And Direction)
    • GPO, GP1, GP2, GP3
  • Get GPIO (Output And Direction)
    • GPO, GP1, GP2, GP3
  • Set SRAM Settings
    • Clock Output Divider Value
    • DAC Voltage Reference
    • Set DAC Output Value
    • ADC Voltage Reference
    • Set Up the Interrupt Detection Mechanism and Clear the Detection Flag
    • GP0, GP1, GP2, GP3 Settings (Output And Designation)
  • Get SRAM Settings
    • CDC Serial Number Enumeration Enable
    • Chip Configuration Security Option
    • Clock Output Divider Value
    • DAC Reference Voltage Option
    • DAC Reference Option
    • Power-up DAC Value
    • Interrupt Detection – Negative Edge
    • Interrupt Detection – Positive Edge
    • ADC Reference Voltage
    • ADC Reference Option
    • USB VID
    • USB PID
    • USB Power Attributes
    • Usb Request Number Of mA
    • Password
  • Reset
  • SmBus
    • SmBusBlockRead
    • SmBusBlockWrite
    • SmBusQuickCommand
    • SmBusReadByte
    • SmBusReadByteCommand
    • SmBusReadIntCommand
    • SmBusReadLongCommand
    • SmBusReadShortCommand
    • SmBusWriteByte
    • SmBusWriteByteCommand
    • SmBusWriteIntCommand
    • SmBusWriteLongCommand
    • SmBusWriteShortCommand

Example code

The MCP2221A Api contains a mix of Read/Write properties and Read Before Write properties. The intent is to allow the code consuming the MCP 2221A Api to control the read write IO to the USB device.

Resolve HID Device Instance

var hidDevice = DeviceList.Local.GetHidDeviceOrNull(Vid, Pid, null, Serial);

if (hidDevice != null)
{
    using HidSharpHidDevice hidSharpHidDevice = new HidSharpHidDevice((ILogger<IHidDevice>)_serviceProvider.GetService(typeof(ILogger<IHidDevice>)), hidDevice);
    using MCP2221IO.Device device = new MCP2221IO.Device((ILogger<IDevice>)_serviceProvider.GetService(typeof(ILogger<IDevice>)), hidSharpHidDevice);

    device.Open();

    result = action(device);
}
else
{
    Console.Error.WriteLine($"Unable to find HID device VID: [0x{Vid:X}] PID: [0x{Vid:X}] SerialNumber: [{Serial}]");
}

Read Write Properties

Read write properties can be simply used as any standard property.

Console.WriteLine($"Usb Manufacture Descriptor: [{device.UsbManufacturerDescriptor}]");

device.UsbManufacturerDescriptor = "Updated";

Read Before Write Methods

To reduce the IO overhead to and from the USB device multiple settings can be set and then applied in a single operation.

// Read the chip settings
device.ReadChipSettings();

// Update  multiple settings
device.ChipSettings.AdcRefOption = AdcRef.Value;

Password password = MCP2221IO.Settings.Password.DefaultPassword;

// Write the CHIP Settings
device.WriteChipSettings(password);

Console.WriteLine("CHIP settings updated");

Synchronous Methods

There a number of synchronous methods that are used to change state of the device or read write data for example I2C and SmBus operations.

// Cancel the I2C bus transfer
device.CancelI2cBusTransfer();

// Set the I2C bus speed
device.SetI2cBusSpeed(int speed);

MCP2221 Console Application

A console application is available from nuget that allows command line access to the functions of a connected MCP2221 HID usb device. Type MCP2221Console -?|-h|--help to see the list of commands for the device.

Installing MCP2221IO.Console

Install the MCP2221IO.Console package via nuget package manager console:

Install-Package MCP2221IO.Console

Or from the dot net command line console

dotnet add package MCP2221IO.Console

Example Console Application

The source code contains an example application for the PModAqs sensor which is based on the CCS811 see here for further information.

The ADM00559 should be configured for 3.3v operation via the jumper selectable power supply. The ADM00559 should be connected to the PMosAqs device in the following way:

ADM00559 J3 PMosAqs
Pin 2 (Vdd) Pin 6 (Vcc)
Pin 3 (Gnd) Pin 5 (Gnd)
Pin 4 (Sda) Pin 4 (Sda)
Pin 5 (Scl) Pin 3 (Scl)
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MCP2221IO:

Package Downloads
MCP2221IO.Console

A .Net Core console application for interacting with a connected MCP2221 HID device

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 132 6/11/2024
2.0.0 167 3/6/2024
1.0.5 386 7/25/2022

1.0.0 Initial Version
2.0.0 Upgraded to .net 7
3.0.0 Upgraded to .net 8