Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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

Status
Not open for further replies.

FenTrac

Full Member level 5
Joined
Jul 6, 2014
Messages
248
Helped
50
Reputation
102
Reaction score
54
Trophy points
1,308
Location
West Coast
Activity points
4,137
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

  • hidtest..zip
    4.7 KB · Views: 316

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top