MCP2210 Library is an open source C++ library that enables communications between the host computer and slave MCP2210 devices under Linux. This library utilizes functions from Signal 11‘s HID API (hidraw) open source project to communicate over the USB HID interface. You can find the most up-to-date source code on github. This library is released under Apache License, Version 2.0.

Overview

The primary goal of this project was to create an open source Linux library for the versatile MCP2210 USB-to-SPI chip. Technically speaking, this library should also work with Windows and Mac OS X as the underlying HID API can be cross-compiled on any of these platforms. Since Microchip offers an .Net based API for Windows, my focus has been concentrated on the Linux environment.

Library Documentation

The library reference can either be downloaded from github (under doc directory) or can be viewed directly following the link below:

The Doxygen generated documentation also includes comments from the hidapi library. Most of the documentations for function definitions of the MCP2210 library can be found under mcp2210.h.

License

The library is released under Apache License, Version 2.0.

Copyright 2012 Kerry D. Wong

Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Source Code and Build Instructions

You can get the latest source code using:

git clone git://github.com/kerrydwong/MCP2210-Library.git

Or you can download the source files from here.

The project was built using NetBeans 7.2 under Ubuntu 12.04 (64 bits). The project has a dependency on udev. If you are using NetBeans to build, everything should have already been setup for you. If you are using other IDEs or are compiling from the command line, please remember to include -ludev as the linker option.

You may also need to add a UDEV rule to /etc/udev/rules.d for the underlying hidapi. The rule file (99-hid.rules) is supplied with the source code on github. Depending on the Linux system you use, super user privilege may also be required for your compiled code to interact with the HID device.

Getting Started

All application code should start with the initialization of the library and release the device handle at the end:

#include "mcp2210.h"

void main()
{
    hid_device *handle;

    handle = InitMCP2210();
    if (handle == 0) 
    {
        //Error initializing
        exit(-1);
    }

    //===================
    //user code goes here
    //===================

    ReleaseMCP2210(handle);
}

The library also supports multiple connected MCP2210 devices via the overloaded InitMCP2210 functions. Please refer to the project documentation for more details.

Most of the function calls that gets values from MCP2210 takes the device handle as the parameter and returns a definition value object which contains the settings. For instance:

  SPITransferSettingsDef def = GetSPITransferSettings(handle);

The ErrorCode field within the definition indicates whether the operation was successful. And most of the function calls that writes values to the MCP2210 takes the device handle and the corresponding definition as parameters and return a status code:

    SPITransferSettingsDef def;
    
    //code to fill def

    int r = SetSPITransferSettings(handle, def);

The following links list some of the examples using the library:

Be Sociable, Share!