FenTrac
Full Member level 5
![Full Member level 5](/styles/images/ranks/flevel2.gif)
- Joined
- Jul 6, 2014
- Messages
- 248
- Helped
- 50
- Reputation
- 102
- Reaction score
- 54
- Trophy points
- 1,308
- Location
- West Coast
- Activity points
- 4,226
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.
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.