首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MCP2200 linux设置

MCP2200 linux设置
EN

Stack Overflow用户
提问于 2012-10-05 20:57:04
回答 2查看 2.3K关注 0票数 2

我想在linux中控制MCP2200。

我找到了Text Link把一切都安排好了。

例如:

我在控制台中键入

代码语言:javascript
复制
GP3-1

它会将引脚3设置为1。但我不知道在控制台中键入什么

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-16 18:33:19

为了控制mcp2200,你需要一个程序来为你做这些事情。

USBtoUART对我不起作用,也许你需要自己编写一些代码--但你可以用它来理解如何连接到mcp2200 hid。

为了控制IOs,只需设置一个16字节的数组,填充此处描述的数据:http://ww1.microchip.com/downloads/en/DeviceDoc/93066A.pdf

如果你想控制更多的东西而不是gpios,你必须做更多的事情--从linux控制mcp2200的gpios是可能的。

我对windows配置工具的通信做了一点usb跟踪,提取了一些信息,然后,你就可以使用自己的pID/vID、制造商和产品字符串了。

注意:您可能需要MikeF所说的HIDAPI。

首先,有一些定义:

代码语言:javascript
复制
// NOTE: max. string length for manufacturer / product string is 63 bytes!!

// from usb trace of mcp2200 config tool
#define MCP2200_SECRET_CONFIGURE    0x01
#define MCP2200_CFG_PID_VID     0x00 
#define MCP2200_CFG_MANU        0x01
#define MCP2200_CFG_PROD        0x02

..。和一些变量:

代码语言:javascript
复制
unsigned char **mcp2200_manu_string;
unsigned char **mcp2200_prod_string;

制造商字符串的输出消息如下所示

代码语言:javascript
复制
/* configure manufacturer string (16 x 16 bytes):
 *  output buffer:
 * #0: [01 01 00 16 03 58 00 4B 00 72 00 FF FF FF FF FF]
 *       |  |  |  |  |  |  |  |  |  |  |  +-----------+--> Always FF
 *       |  |  |  |  |  |  +-----+-----+-----------------> Always 00
 *       |  |  |  |  |  +-----+-----+--------------------> First 3 Chars of Manufacturer Name / Product Name
 *       |  |  |  |  +-----------------------------------> In #0: 0x03, After #0: 0x00
 *       |  |  |  +--------------------------------------> (Length (Manufacturer Name) * 2) + 2 (after #0: chars of manufacturer name)
 *       |  |  +-----------------------------------------> Counter 0x00 .. 0x0F
 *       |  +--------------------------------------------> MCP2200 Config Bit (MCP2200_CFG_MANU / PROD / VID_PID)
 *       +-----------------------------------------------> MCP2200_SECRET_CONFIGURE from usb trace
 */

如果您将所有这些放在一个函数中,它可能如下所示:

代码语言:javascript
复制
void prepare_cfg_strings (char* manu, char* prod) {
    char manuStr[64];
    char prodStr[64];
    unsigned int i, k = 0;
    unsigned char tmp = 0;

    memset (manuStr, 0x00, sizeof(manuStr));
    memset (prodStr, 0x00, sizeof(prodStr));

    // allocate mcp2200_{manu,prod}_string buffer, 2-dim array with 16 x 16 chars
    if (( mcp2200_manu_string = ( unsigned char** )malloc( 16*sizeof( unsigned char* ))) == NULL ) {
        // error
    }
    if (( mcp2200_prod_string = ( unsigned char** )malloc( 16*sizeof( unsigned char* ))) == NULL ) {
        // error
    }

    for ( i = 0; i < 16; i++ )
    {
      if (( mcp2200_manu_string[i] = ( unsigned char* )malloc( 16 )) == NULL ) {
        /* error */ 
      }
      if (( mcp2200_prod_string[i] = ( unsigned char* )malloc( 16 )) == NULL ) {
        /* error */ 
      }
      /* init the rows here */
      memset (mcp2200_manu_string[i], 0x00, sizeof(&mcp2200_manu_string[i]));
      memset (mcp2200_prod_string[i], 0x00, sizeof(&mcp2200_prod_string[i]));
    }

    // manuStr holds (strlen(manuStr) * 2) + 2 in byte[0] and manufacturer string from byte[1] on
    strcpy (&manuStr[1], manu);
    manuStr[0] = ((strlen (&manuStr[1]) * 2) + 2);
    // prodStr holds (strlen(prodStr) * 2) + 2 in byte[0] and product string from byte[1] on
    strcpy (&prodStr[1], prod);
    prodStr[0] = ((strlen (&prodStr[1]) * 2) + 2);

    // build manufacturer / product strings
    for (i=0, k=0; i<16; i++, k+=4) {
        if (i==0) {
            tmp = 0x03;
        } else {
            tmp = 0x00;
        }
        // manufacturer string
        mcp2200_manu_string[i][0] = MCP2200_SECRET_CONFIGURE; 
        mcp2200_manu_string[i][1] = MCP2200_CFG_MANU;
        mcp2200_manu_string[i][2] = i; 
        mcp2200_manu_string[i][3] = manuStr[k];
        mcp2200_manu_string[i][4] = tmp;
        mcp2200_manu_string[i][5] = manuStr[k+1];
        mcp2200_manu_string[i][6] = 0x00;
        mcp2200_manu_string[i][7] = manuStr[k+2];
        mcp2200_manu_string[i][8] = 0x00;
        mcp2200_manu_string[i][9] = manuStr[k+3];
        mcp2200_manu_string[i][10] = 0x00;
        mcp2200_manu_string[i][11] = 0xff;
        mcp2200_manu_string[i][12] = 0xff;
        mcp2200_manu_string[i][13] = 0xff;
        mcp2200_manu_string[i][14] = 0xff;
        mcp2200_manu_string[i][15] = 0xff;

        // product string
        mcp2200_prod_string[i][0] = MCP2200_SECRET_CONFIGURE; 
        mcp2200_prod_string[i][1] = MCP2200_CFG_PROD;
        mcp2200_prod_string[i][2] = i; 
        mcp2200_prod_string[i][3] = prodStr[k];
        mcp2200_prod_string[i][4] = tmp;
        mcp2200_prod_string[i][5] = prodStr[k+1];
        mcp2200_prod_string[i][6] = 0x00;
        mcp2200_prod_string[i][7] = prodStr[k+2];
        mcp2200_prod_string[i][8] = 0x00;
        mcp2200_prod_string[i][9] = prodStr[k+3];
        mcp2200_prod_string[i][10] = 0x00;
        mcp2200_prod_string[i][11] = 0xff;
        mcp2200_prod_string[i][12] = 0xff;
        mcp2200_prod_string[i][13] = 0xff;
        mcp2200_prod_string[i][14] = 0xff;
        mcp2200_prod_string[i][15] = 0xff;
    }
}

在主循环中调用此函数:

代码语言:javascript
复制
prepare_cfg_strings ("MyManufacturerName, "MyProductName");

打开mcp2200的hid句柄,并将以下内容放到总线上:

代码语言:javascript
复制
// write manufacturer string configuration to usb device
for (i=0; i<16; i++) {
    hid_write (handle, mcp2200_manu_string[i], 16);
}
// write product string configuration to usb device
for (i=0; i<16; i++) {
    hid_write (handle, mcp2200_prod_string[i], 16);
}

如果您想用自己的VendorID / ProductID刷新mcp2200,请配置您的消息:

代码语言:javascript
复制
// Microchip VID: 0x04d8
//   MCP2200 PID: 0x00df
mcp2200_pid_vid_cfg[] = 01 00 D8 04 DF 00 00 00 00 00 00 00 00 00 00 00
                         |  | +---+ +---+--------------------------------> Product ID (bytes swapped)
                         |  |     +--------------------------------------> Vendor ID (bytes swapped)
                         |  +--------------------------------------------> MCP2200 Config Bit (MCP2200_CFG_VID_PID)
                         +-----------------------------------------------> MCP2200_SECRET_CONFIGURE from usb trace

把它放到公交车上:

代码语言:javascript
复制
hid_write (handle, mcp2200_pid_vid_cfg, 16);

玩得开心!

n.

票数 5
EN

Stack Overflow用户

发布于 2013-03-07 00:07:05

您将无法通过USB tty从控制台/终端控制GPIO端口。串口/串口转换是MCP2200的一大特色,要实现对GPIO的控制,需要通过USB驱动程序发送命令。要实现这一点,您将需要以下内容。

HIDAPI:

https://github.com/signal11/hidapi

USBtoUART:

https://github.com/Miceuz/USBtoUART

USBtoUART需要HIDAPI包中的id.o...所以先从HIDAPI开始...

祝好运!

MikeF

ps:我对代码做了一些修改,接受用于控制GPIO端口的二进制格式,等等……它已经在x86和ARM ( Raspberry Pi )上编译得很好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12746744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档