一箭一雕, USB转单串口例程
将STC官网提供的【一箭双雕之USB转双串口】学习板例程包里面的开源例程稍做修改,就能实现【一箭一雕,USB转单串口】功能,以满足只需要一路串口的用户需求。
一箭双雕例程包下载地址:https://www.stcai.com/hxgnsyb
将双串口改成单串口主要就修改USB配置参数,配置参数改完就识别成一个串口设备了:
char code DEVICEDESC =
{
0x12, //bLength(18);
0x01, //bDescriptorType(Device);
0x00,0x02, //bcdUSB(2.00);
0x02, //bDeviceClass(2:Communication Device Class);
0x00, //bDeviceSubClass0);
0x00, //bDeviceProtocol(0);
0x40, //bMaxPacketSize0(64);
0xbf,0x34, //idVendor(34bf);
0x02,0xff, //idProduct(ff02);
0x00,0x01, //bcdDevice(1.00);
0x01, //iManufacturer(1);
0x02, //iProduct(2);
0x00, //iSerialNumber(0);
0x01, //bNumConfigurations(1);
};
char code CONFIGDESC =
{
0x09, //bLength(9);
0x02, //bDescriptorType(Configuration);
0x43,0x00, //wTotalLength(67);
0x02, //bNumInterfaces(2);
0x01, //bConfigurationValue(1);
0x00, //iConfiguration(0);
0x80, //bmAttributes(BUSPower);
0x32, //MaxPower(100mA);
0x09, //bLength(9);
0x04, //bDescriptorType(Interface);
0x00, //bInterfaceNumber(0);
0x00, //bAlternateSetting(0);
0x01, //bNumEndpoints(1);
0x02, //bInterfaceClass(Communication Interface Class);
0x02, //bInterfaceSubClass(Abstract Control Model);
0x01, //bInterfaceProtocol(Common AT commands);
0x00, //iInterface(0);
0x05, //bLength(5);
0x24, //bDescriptorType(CS_INTERFACE);
0x00, //bDescriptorSubtype(Header Functional Descriptor);
0x10,0x01, //bcdCDC(1.10);
0x05, //bLength(5);
0x24, //bDescriptorType(CS_INTERFACE);
0x01, //bDescriptorSubtype(Call Management Functional Descriptor);
0x00, //bmCapabilities(Device does not handles call management itself);
0x01, //bDataInterface(1);
0x04, //bLength(4);
0x24, //bDescriptorType(CS_INTERFACE);
0x02, //bDescriptorSubtype(Abstract Control Management Functional Descriptor);
0x02, //bmCapabilities(Set/Get_Line_Coding,Serial_State,Set_Control_Line_State);
0x05, //bLength(5);
0x24, //bDescriptorType(CS_INTERFACE);
0x06, //bDescriptorSubtype(Union Functional descriptor);
0x00, //bMasterInterface(0);
0x01, //bSlaveInterface0(1);
0x07, //bLength(7);
0x05, //bDescriptorType(Endpoint);
0x82, //bEndpointAddress(EndPoint2 as IN);
0x03, //bmAttributes(Interrupt);
0x40,0x00, //wMaxPacketSize(64);
0xff, //bInterval(255ms);
0x09, //bLength(9);
0x04, //bDescriptorType(Interface);
0x01, //bInterfaceNumber(1);
0x00, //bAlternateSetting(0);
0x02, //bNumEndpoints(2);
0x0a, //bInterfaceClass(Data Interface Class);
0x00, //bInterfaceSubClass(AData Interface Class SubClass Codes);
0x00, //bInterfaceProtocol(USB SPEC);
0x00, //iInterface(0);
0x07, //bLength(7);
0x05, //bDescriptorType(Endpoint);
0x84, //bEndpointAddress(EndPoint4 as IN);
0x02, //bmAttributes(Bulk);
0x40,0x00, //wMaxPacketSize(64);
0x00, //bInterval(Ignored);
0x07, //bLength(7);
0x05, //bDescriptorType(Endpoint);
0x04, //bEndpointAddress(EndPoint4 as OUT);
0x02, //bmAttributes(Bulk);
0x40,0x00, //wMaxPacketSize(64);
0x00, //bInterval(Ignored);
};附件使用一箭双雕USB转双串口A0例程修改USB配置,
主函数里将自检部分删除避免使用不同板子测试自检通不过导致不识别。
通过最小改动达到需求。
也可从 辅助开发/烧录工具,STC-ISP V6.92D 或以上版本,下载:
【一箭双雕之USB转双串口】学习板例程包里面的,开源例程
例程A0/例程A1, 都是【一箭双雕之USB转双串口】演示例程
先谢谢了。这就去做测试 试了一下确实是一个串口了。不过自动下载功能也没有了。 能不能转4个串口出来啊 East Wind 41 发表于 2024-12-16 21:35
能不能转4个串口出来啊
不能,端点数不够
页:
[1]