MCP2210 Library Reference

I have created a dedicated page for the MCP2210 library documentations. An link to the reference can also be found on the side navigation pane. The Doxygen generated project documentation can be viewed directly here.

Drop me a line if you have any questions or run into any issues.

Be Sociable, Share!

11 Comments

  1. Colin says:

    Hi, I’ve got the MCP2210 and have been playing with it under windows but I need to use it under Ubuntu and came across you library.
    I down loaded the library using git clone git://github.com/kerrydwong/MCP2210-Library.git
    I then did g++ mcp2210.cpp and got the following errors
    I’m now well out of my depth any chance you could help me install the library and walk me though one of the examples pls
    Thanks Colin

    Error msg
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start’:
    (.text+0x18): undefined reference to `main’
    /tmp/ccFHnixl.o: In function `SendUSBCmd(hid_device_*, unsigned char*, unsigned char*)’:
    mcp2210.cpp:(.text+0x23): undefined reference to `hid_write’
    mcp2210.cpp:(.text+0x54): undefined reference to `hid_read’
    mcp2210.cpp:(.text+0x7e): undefined reference to `hid_read’
    /tmp/ccFHnixl.o: In function `EnumerateMCP2210()’:
    mcp2210.cpp:(.text+0x19b0): undefined reference to `hid_enumerate’
    /tmp/ccFHnixl.o: In function `InitMCP2210(unsigned short, unsigned short, wchar_t*)’:
    mcp2210.cpp:(.text+0x19e1): undefined reference to `hid_open’
    /tmp/ccFHnixl.o: In function `InitMCP2210(wchar_t*)’:
    mcp2210.cpp:(.text+0x1a04): undefined reference to `hid_open’
    /tmp/ccFHnixl.o: In function `InitMCP2210()’:
    mcp2210.cpp:(.text+0x1a28): undefined reference to `hid_open’
    /tmp/ccFHnixl.o: In function `ReleaseMCP2210(hid_device_*)’:
    mcp2210.cpp:(.text+0x1a3b): undefined reference to `hid_close’
    mcp2210.cpp:(.text+0x1a40): undefined reference to `hid_exit’
    collect2: ld returned 1 exit status

    • kwong says:

      Hi Colin,

      You should be able to use “make” within the project directory to compile the project (or if you installed NetBeans, you could just open up the project and compile that way).

  2. Colin says:

    Hi,
    Thanks for the pointers, I’ve ran all the make files in ./MCP2210-Library/nbproject but they all return Nothing to be done for “Make-file”
    I’ve installed Netbeans but it can’t find and projects in nbproject!!
    Could you give a step by step guide on how to install (starting with git clone to download your library), compiling the library, and ending with running one of your demos

    My background is in embedded systems where an IDE would be vi to write the c code and and a command line compiler to compile it. ;)

    I currently have a MK808 (Android TV) that I’m going to flash with Ubuntu 12.10 Quantal, conect the MCP2210 to the usb port and a Nordic nRF24LE to the MCP2210 SPI port.
    This will then allow me to use the full power of a linux system to gather real time data from a number of remote sensors.

    I’m currently stuck at step 1 trying to talk to the MCP2210 from a shell script in linux :(

    Thanks for any help
    Colin

    • kwong says:

      No problem. When you open a NetBeans project, you need to use File->Open Project and navigate to the project folder and click open.

      Alternatively, you can just create an empty C++ project and copy the source files into that project directory (in this case they would be hidapi.h/hidapi.c mcp2210.h/mcp2210.cpp). And in the IDE right click on your project and choose add existing item to add those copied files.

      Here is a screenshot of what a test project looks like (the main function is inside mcp2210test.cpp):

      Project Layout

  3. Colin says:

    Thanks, I’ve now got your MCP2210 project working, my main issue was not having the C++ module added to netbeans so could only see Java projects!

    One last question for now, is there a way to create a stand alone executable from within netbeans?

    I can run the project from inside netbeans and get the desired results and I can see all the object files in
    ./MCP2210-Library/build/Release/GNU-Linux-x86

    I can create an executable by running g++ -o ./mcp2210-exe ./*.o -ludev and then running sudo ./mcp2210-exe from the terminal
    but it would be nice to set the executable name and location from within netbeans.
    Again thanks for your help.

    • kwong says:

      Great! Glad to hear you got it to work.

      By default when you compile and build your project, an executable is generated in the following folders:

      {project name}/dist/Release/GNU-Linux-x86/
      {project name}/dist/Debug/GNU-Linux-x86/

      so you don’t have to manually create the binary and should already have the executables.

  4. Colin says:

    That works thanks, there seems to be quite a few out there that didn’t know that.

  5. Ema says:

    Hi Kerry,

    I have a working .NET code that runs under Windows but our environment is all ubuntu based,
    and struggling to make a porting to linux I saw some light when I found your library!

    I’ve installed NetBeans on Ubuntu, downloaded source code from git://github.com/kerrydwong/MCP2210-Library.git,
    it compiles and executes fine!

    I’m getting mad trying to understand how to control the logic state of different GPIO pins.
    I have an MC2210 based board which use three pins for transistor-driven power-on of the circuits of the attached SPI device
    and then I should send SPI commands to the connected OLED display.
    I have a test led on gpio4

    What I have in the .NET code, that i can’t understand how to fit in your library is this code:
    private enum gpio_map
    {
    none = 0,
    gpio8 = 0x0100,
    gpio7 = 0x0080,
    gpio6 = 0x0040,
    gpio5 = 0x0020,
    gpio4 = 0x0010,
    gpio3 = 0x0008,
    gpio2 = 0x0004,
    gpio1 = 0x0002,
    gpio0 = 0x0001,
    }

    that is supplied to the initialization library.

    Right now with your library

    /////
    def.GP[0].GPIOOutput = 1;
    r= SetGPIOPinVal(handle,def);
    /////

    the test led on gpio4 turns ON and with

    /////
    def.GP[4].GPIOOutput = 1;
    r= SetGPIOPinVal(handle,def);
    /////

    nothing happens.

    It looks like I’m missing the correct gpio pin “addressing”
    and they are all working on GP[0].

    Do you have any idea?

    Many thanks for your great job!

    Emanuele

    • kwong says:

      Hi Ema,

      Not sure why GP[4] wouldn’t work for you. I just tried with the test code I included on github (copied down below for reference):

      /**
      * Test GPIO
      * Generate a rectangular wave on GP0
      */
      void TestGPIO(hid_device* handle) {
      ChipSettingsDef chipDef;

      /**
      * Set GPIO to be output
      */
      chipDef = GetChipSettings(handle);

      for (int i = 0; i < 9; i++) { chipDef.GP[i].PinDesignation = GP_PIN_DESIGNATION_GPIO; chipDef.GP[i].GPIODirection = GPIO_DIRECTION_OUTPUT; chipDef.GP[i].GPIOOutput = 0; } int r0 = SetChipSettings(handle, chipDef); /** * Configure GPIO0 direction to output */ GPPinDef def = GetGPIOPinDirection(handle); def.GP[0].GPIODirection = GPIO_DIRECTION_OUTPUT; def.GP[0].PinDesignation = GP_PIN_DESIGNATION_GPIO; int r = SetGPIOPinDirection(handle, def); ///< Generate a rectangular wave by toggling GP0. while (1) { def.GP[0].GPIOOutput = 1 - def.GP[0].GPIOOutput; r = SetGPIOPinVal(handle, def); } } and if I change GP[0] to GP[4] the waveform could be observed on GP[4].

  6. Hey there! Thanks for making this library available! It has been quite helpful. I want to let you know that I’ve just released my first beta of an MCP2210 Linux driver based (very loosely) upon Mathew King’s original demo driver. This driver bypasses the usbhid, hid-generic, libusb, etc. altogether and just provides (currently) a crude ioctl interface under /dev for device control and then makes your SPI peripherals available via spidev (or whatever SPI protocol driver you choose).

    Please note that it is *very *beta, but have a look if you are interested.

    https://github.com/daniel-santos/mcp2210-linux

  7. Kerry,

    I am using your HIDNEW.DLL and Visual Studio 2013 (VB) to control a MCP2210 USB-SPI interface. I have been successful in performing write functions from Visual Studio – USB – MCP2210 – Xilinx Spartan 3A – MicroChip 25LC1025 Serial EEPROM. With an oscilloscope I can verify that I am able to write data to the EEPROM, and retrieve the correct data from the EEPROM to a buffer in my Xilinx device. All these functions are USB-SPI HIDWRITEEX functions. The last step is to use HIDREADEX to retrieve the data from a buffer in the Xilinx. I can never get valid data with this step. I’m sure I am doing something wrong. Do you have an example of using the HIDREADEX function in Visual Basic I can look at?

    Thanks for all your help.

Leave a Reply