做一个Micro USB Host

去年最火爆的就是芯片了,我在21年4月购买的 MAX3421芯片还只要16.6元

MAX3421e 21年3月只要 16.6元

而今天再点进去查看报价已经达到了 130 (咨询下来预期50左右):

MAX3421e 22年2月已经按照 130元报价了

于是萌发了制作一个能够多次复用模块的想法,简单的说设计足够小的 PCB 然后将芯片焊接在上面,将必要的引脚引出,使其成为一个“模块”。

电路图设计如下:

Arduino Micro USB Host 电路图

为了保证体积足够小,使用了贴片式晶振,这个晶振有4个引脚,分别是2个 GND ,1个XO 一个XI;尺寸是 3.2×2.5mm 厚度是 0.7mm,因此这种封装也被称作SMD3225-4P。

SMD3225-4P 的晶振

PCB 设计如下:

Arduino Micro USB Host PCB

为了尽量缩减体积,上面只保留必要的5个电容,同时选用 0603封装的,不得不承认,0603封装能够极大方便布线。

名称用途 用途名称
INT用于MAX3421通知单片机有中断发生SPI的MOSIMOSI
GNDSPI的MOSIMISO
MD-USB Host D-SPI的片选SS
MD+USB Host D+SPI的 CLOCKSCLK
VBCOMP检查USB 设备的 VBUS 是否存在芯片的 RESET Pin, 正常情况下必须为高RESET
GND芯片供电3.3V
引脚说明
PCB 实物

焊接完成后,我们就可以在 FireBeetle 上进行测试了:

首先,FireBeetle  VCC 给USB 母头供电,同时共地,其余引脚连接如下:

名称FireBeetle FireBeetle名称
INTD3IO23MOSI
GNDGNDIO19MISO
MD-USB 母头 D-D7SS
MD+USB 母头 D+IO18SCLK
VBCOMPUSB 母头 5v3.3VRESET
GNDGND3.3V3.3V
对FireBeetle 的连接方式

之后就可以直接使用 USB Host Shield 2.0 的库了,比如运行 \USBHIDBootMouse.ino 这个示例:

#include <hidboot.h>
#include <usbhub.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

class MouseRptParser : public MouseReportParser
{
protected:
	void OnMouseMove	(MOUSEINFO *mi);
	void OnLeftButtonUp	(MOUSEINFO *mi);
	void OnLeftButtonDown	(MOUSEINFO *mi);
	void OnRightButtonUp	(MOUSEINFO *mi);
	void OnRightButtonDown	(MOUSEINFO *mi);
	void OnMiddleButtonUp	(MOUSEINFO *mi);
	void OnMiddleButtonDown	(MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
    Serial.print("dx=");
    Serial.print(mi->dX, DEC);
    Serial.print(" dy=");
    Serial.println(mi->dY, DEC);
};
void MouseRptParser::OnLeftButtonUp	(MOUSEINFO *mi)
{
    Serial.println("L Butt Up");
};
void MouseRptParser::OnLeftButtonDown	(MOUSEINFO *mi)
{
    Serial.println("L Butt Dn");
};
void MouseRptParser::OnRightButtonUp	(MOUSEINFO *mi)
{
    Serial.println("R Butt Up");
};
void MouseRptParser::OnRightButtonDown	(MOUSEINFO *mi)
{
    Serial.println("R Butt Dn");
};
void MouseRptParser::OnMiddleButtonUp	(MOUSEINFO *mi)
{
    Serial.println("M Butt Up");
};
void MouseRptParser::OnMiddleButtonDown	(MOUSEINFO *mi)
{
    Serial.println("M Butt Dn");
};

USB     Usb;
USBHub     Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE>    HidMouse(&Usb);

MouseRptParser                               Prs;

void setup()
{
    Serial.begin( 115200 );
#if !defined(__MIPSEL__)
    while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
    Serial.println("Start");

    if (Usb.Init() == -1)
        Serial.println("OSC did not start.");

    delay( 200 );

    HidMouse.SetReportParser(0, &Prs);
}

void loop()
{
  Usb.Task();
}
面包板上进行测试

本文提到的电路图和PCB 下载(立创 EDA)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注