Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

MCP2210 programming example in C++, using the HIDAPI HID library

FenTrac

Full Member level 3
Joined
Jul 6, 2014
Messages
181
Helped
32
Reputation
64
Reaction score
31
Trophy points
28
Location
West Coast
Activity points
1,328
This is a programming example in C++ for an MCP2210 USB to SPI
converter. The MCP2210 has 9 general purpose I/O pins,
an SPI master bus controller, and 256 bytes of EEprom.

The MCP2210 USB interface attaches as an HID device when
connected to the PC. The MCP2210 does not run an internal
program, but is controlled by a program running on
the PC, sending instructions to it over USB.

The MCP2210 uses 26 commands for configuration and controlling
the I/O functions. The hidapi function "hid_write()" is used
to send commands to the MCP2210. The MCP2210 sends a
response for each command that's read with "hid_read()".

Programming the MCP2210 with hidapi is fairly simple:

Place the data bytes for a command in the array buf[64];
Send the array using "hid-write( handle, buf, #_of_bytes )";
Read the response using "hid_read( handle, rbuf, #_of_bytes )";

The command codes are listed in the MCP2210 User Manual:
Tables 3-1 thru 3-26.

The hidapi library includes an example program "hidtest.cpp",
That file was modified to use the MCP2210 for this example.

The example program controls an MCP3008 A/D converter connected
by SPI to the MCP2210. It controls a 2x16 display using 7 GPIO
pins, and an LED on another GPIO.

Attached is the modifed version of hidtest.cpp. Comments
in the file have info on downloading and installing the hidapi
library, and compiling and running the program.

Below is a schematic of the test circuit used.



USB_to_SPI_interface.jpg
 

Attachments


Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top