MCP cover image
See in Github
2020-05-18

使用GPIO的MCP2221A USB到I²C/UART协议转换器的GO模块

4

Github Watches

4

Github Forks

20

Github Stars

GoDoc

mcp2221a

Go module for the MCP2221A USB to I²C/UART Protocol Converter with GPIO (datasheet)

Features

  • Fully-documented API
  • Compliant Go module (see below: Installation)
  • Supports multiple MCP2221A devices simultaneously
    • Define custom USB device VID/PID
  • GPIO input/output
  • ADC read (10-bit, 3 channels/pins), configurable reference voltage
  • DAC write (5-bit, 2 pins, shared output), configurable reference voltage and default output
  • Dedicated UART/I²C activity LED modes with configurable polarity
  • Rising/falling/both edge interrupt detection
  • Clock output on 1 pin (up to 12 MHz)
  • Save default/power-on configuration to flash memory (GPIO mode/value, DAC output, etc.)
    • Password-protected flash support
    • Configure minimum required operating current (510 mA max)
  • I²C read/write (configurable bit rate, up to 400 kHz)
    • I²C address scanner discovers all slaves on the bus
    • Convenience routines for reading registers from devices with 8-bit and 16-bit subaddressing

Note that UART support is provided natively through the USB interface as a CDC device and is not handled by this module. It should show up in your OS as a regular TTY serial interface (/dev/tty* on Linux/macOS, COM on Windows).

Dependencies

Installation

If you are not using Go modules (or are unsure), just use the go built-in package manager:

go get -u -v github.com/ardnew/mcp2221a

Installation using modules

Either use the built-in package manager as above (and drop the -u):

go get -v github.com/ardnew/mcp2221a

Or simply add the import statement to your Go package's source code:

import (
  // ... other imports ...
  mcp "github.com/ardnew/mcp2221a"
)

The next time you run go build, the appropriate package will be downloaded automatically! Gee whiz!

Examples

See examples for some demo applications:

  • GPIO - classic "Blink" demo, toggles an LED connected to GPIO pin GP0
  • I²C - I²C address scanner, and also reads and prints the "Device ID" register contents from an INA260 power sensor
  • ADC - continuously reads and prints an analog value on GPIO pin GP1
  • DAC - continuously writes and prints an always-incrementing 5-bit value on GPIO pin GP2
  • Flash - prints the USB product descriptors from flash memory, and toggles power-up GPIO output value on pin GP0

Notes

GP operating modes

All of the available operating modes for the general-purpose (GP) pins:

  • GPIO: Operate as a digital input or a digital output pin.
  • SSPND: Reflects the USB state (Suspend/Resume); active-low when Suspend has been issued by the USB host, and driven high on Resume.
    • This lets the application react (e.g enter a low-power mode) when USB communication has been suspended or resumed.
    • The pin value can be inverted (high on Suspend, low on Resume) using the Flash module.
  • USBCFG: Starts out low during power-up/reset and goes high after successfully enumerating on the USB host.
    • The pin will also go low when in Suspend mode and high on Resume.
    • The pin value can be inverted (start high, low after enumeration) using the Flash module.
  • LED_URX,LED_UTX: Indicates UART (Rx/Tx) data being received/transmitted by pulsing the pin high for a few milliseconds.
    • The pin value can be inverted (pulse low on receive/transmit) using the Flash module.
  • LED_I2C: Indicates I²C (Rx and Tx) data being received and transmitted by pulsing the pin high for a few milliseconds.
    • The pin value can be inverted (pulse low on receive and transmit) using the Flash module.
  • CLKR: Digital output, providing a clock signal derived from the device’s internal clock.
    • The clock’s nominal frequency is 12 MHz ± 0.25%.
    • Other clock values and duty cycles can be configured using the Flash module.
  • IOC: Digital input ("Interrupt-on-Change") that is sensitive to rising, falling, or both edges.
    • The desired edge can be configured using the Flash and SRAM modules.
Supported modes

However, only certain pins support each of the operating modes listed above — per the following matrix yanked from the datasheet:

GP0 GP1 GP2 GP3
Default GPIO GPIO GPIO GPIO
Dedicated SSPND CLKR USBCFG LED_I2C
Alt 1 LED_URX ADC1 ADC2 ADC3
Alt 2 -- LED_UTX DAC1 DAC2
Alt 3 -- IOC -- --

No idea why the first row of alternate functions is named Dedicated, that's how they are identified in the datasheet...

Datasheet

Please refer to this before sending me a confusing question:

To get started reading this thing, and easier grokking, note that:

  • The first half of the datasheet (.pdf) defines internal registers and inter-component behaviors which are all but completely transparent to us. This info can be ignored, but be sure to read the front-matter and any component descriptions.
  • The second half of the datasheet (.pdf) defines the USB HID command and response formats. This is the good stuff that pertains to developers of or using this Go module.

Where to get one

Adafruit makes a crazy cheap, snazzy breakout with built-in 3.3V regulator (with VBUS/5V and 3.3V output pins), an I²C Qwiic/Stemma QT connector (as well as the regular SDA/SCL pins), and best of all a USB-C connector as its programming interface:

相关推荐

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Lists Tailwind CSS classes in monospaced font

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • n8n-io
  • 具有本机AI功能的公平代码工作流程自动化平台。将视觉构建与自定义代码,自宿主或云相结合,400+集成。

  • open-webui
  • 用户友好的AI接口(支持Ollama,OpenAi API,...)

    Reviews

    3 (1)
    Avatar
    user_7vODKPw7
    2025-04-18

    The MCP2221A by Ardnew is an exceptional USB-to-UART/I2C protocol converter. It's user-friendly and integrates smoothly with various projects, enhancing functionality with minimal effort. Highly recommended for anyone looking to simplify their serial communication tasks. Check it out [here](https://github.com/ardnew/mcp2221a)!