MCP2200的Linux设置

我想在linux中控制MCP2200。

我发现文字链接,并设置一切。

例如:
我input控制台

GP3-1 

它会将引脚3设置为1.但是我不知道在控制台中input什么

为了控制mcp2200,你将需要一个为你做的东西的程序。

USBtoUART不适合我,也许你必须自己做一些编码 – 但你可以用它来了解如何连接到mcp2200隐藏。

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

如果你想控制一些更多的东西,但gpios,你将不得不做更多的事情 – 有可能不仅仅是控制Linux的mcp2200的gpios。

我做了一些微软的Windows配置工具的沟通,提取了一些信息和 – tadaah,你去与你自己的pID / vID,制造商和产品字符串。

注意:您可能需要MikeF正在谈论的HIDAPI。

首先是一些定义:

 // 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 

…和一些变量:

 unsigned char **mcp2200_manu_string; unsigned char **mcp2200_prod_string; 

制造商字符串的输出消息看起来像

 /* 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 */ 

如果你把所有这些放在一个函数中,它可能看起来像这样:

 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; } } 

在你的主循环中调用这个函数:

 prepare_cfg_strings ("MyManufacturerName, "MyProductName"); 

打开你的mcp2200一个隐藏的句柄,把这东西放在总线上:

 // 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,请配置您的消息:

 // 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 

并把它放在公共汽车上:

 hid_write (handle, mcp2200_pid_vid_cfg, 16); 

玩的开心!

ñ。

您将无法通过USB tty控制控制台/终端的GPIO端口。USB转串口/ UART转换器是MCP2200的一个功能,要控制GPIO,您需要通过USB和HID发送命令驱动程序。 要做到这一点,您将需要以下内容。

HIDAPI:

https://github.com/signal11/hidapi

USBtoUART:

https://github.com/Miceuz/USBtoUART

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

祝你好运!

MikeF

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