找回密码
 立即注册
查看: 698|回复: 1

一箭一雕, USB转单串口例程

[复制链接]
  • TA的每日心情
    奋斗
    前天 08:59
  • 签到天数: 143 天

    [LV.7]常住居民III

    27

    主题

    1343

    回帖

    4187

    积分

    论坛元老

    积分
    4187
    发表于 2023-10-9 17:48:25 | 显示全部楼层 |阅读模式
    将STC官网提供的【一箭双雕USB转串口】学习板例程包里面的开源例程稍做修改,
    就能实现【一箭一雕USB转串口】功能,以满足只需要一路串口的用户需求。
    一箭双雕例程包下载地址:https://www.stcai.com/hxgnsyb
    截图202310091741546772.jpg

    将双串口改成单串口主要就修改USB配置参数,配置参数改完就识别成一个串口设备了:
    1. char code DEVICEDESC[18] =
    2. {
    3.     0x12,                   //bLength(18);
    4.     0x01,                   //bDescriptorType(Device);
    5.     0x00,0x02,              //bcdUSB(2.00);
    6.     0x02,                   //bDeviceClass(2:Communication Device Class);
    7.     0x00,                   //bDeviceSubClass0);
    8.     0x00,                   //bDeviceProtocol(0);
    9.     0x40,                   //bMaxPacketSize0(64);
    10.     0xbf,0x34,              //idVendor(34bf);
    11.     0x02,0xff,              //idProduct(ff02);
    12.     0x00,0x01,              //bcdDevice(1.00);
    13.     0x01,                   //iManufacturer(1);
    14.     0x02,                   //iProduct(2);
    15.     0x00,                   //iSerialNumber(0);
    16.     0x01,                   //bNumConfigurations(1);
    17. };
    18. char code CONFIGDESC[67] =
    19. {
    20.     0x09,                   //bLength(9);
    21.     0x02,                   //bDescriptorType(Configuration);
    22.     0x43,0x00,              //wTotalLength(67);
    23.     0x02,                   //bNumInterfaces(2);
    24.     0x01,                   //bConfigurationValue(1);
    25.     0x00,                   //iConfiguration(0);
    26.     0x80,                   //bmAttributes(BUSPower);
    27.     0x32,                   //MaxPower(100mA);
    28.     0x09,                   //bLength(9);
    29.     0x04,                   //bDescriptorType(Interface);
    30.     0x00,                   //bInterfaceNumber(0);
    31.     0x00,                   //bAlternateSetting(0);
    32.     0x01,                   //bNumEndpoints(1);
    33.     0x02,                   //bInterfaceClass(Communication Interface Class);
    34.     0x02,                   //bInterfaceSubClass(Abstract Control Model);
    35.     0x01,                   //bInterfaceProtocol(Common AT commands);
    36.     0x00,                   //iInterface(0);
    37.     0x05,                   //bLength(5);
    38.     0x24,                   //bDescriptorType(CS_INTERFACE);
    39.     0x00,                   //bDescriptorSubtype(Header Functional Descriptor);
    40.     0x10,0x01,              //bcdCDC(1.10);
    41.     0x05,                   //bLength(5);
    42.     0x24,                   //bDescriptorType(CS_INTERFACE);
    43.     0x01,                   //bDescriptorSubtype(Call Management Functional Descriptor);
    44.     0x00,                   //bmCapabilities(Device does not handles call management itself);
    45.     0x01,                   //bDataInterface(1);
    46.     0x04,                   //bLength(4);
    47.     0x24,                   //bDescriptorType(CS_INTERFACE);
    48.     0x02,                   //bDescriptorSubtype(Abstract Control Management Functional Descriptor);
    49.     0x02,                   //bmCapabilities(Set/Get_Line_Coding,Serial_State,Set_Control_Line_State);
    50.     0x05,                   //bLength(5);
    51.     0x24,                   //bDescriptorType(CS_INTERFACE);
    52.     0x06,                   //bDescriptorSubtype(Union Functional descriptor);
    53.     0x00,                   //bMasterInterface(0);
    54.     0x01,                   //bSlaveInterface0(1);
    55.     0x07,                   //bLength(7);
    56.     0x05,                   //bDescriptorType(Endpoint);
    57.     0x82,                   //bEndpointAddress(EndPoint2 as IN);
    58.     0x03,                   //bmAttributes(Interrupt);
    59.     0x40,0x00,              //wMaxPacketSize(64);
    60.     0xff,                   //bInterval(255ms);
    61.     0x09,                   //bLength(9);
    62.     0x04,                   //bDescriptorType(Interface);
    63.     0x01,                   //bInterfaceNumber(1);
    64.     0x00,                   //bAlternateSetting(0);
    65.     0x02,                   //bNumEndpoints(2);
    66.     0x0a,                   //bInterfaceClass(Data Interface Class);
    67.     0x00,                   //bInterfaceSubClass(AData Interface Class SubClass Codes);
    68.     0x00,                   //bInterfaceProtocol(USB SPEC);
    69.     0x00,                   //iInterface(0);
    70.     0x07,                   //bLength(7);
    71.     0x05,                   //bDescriptorType(Endpoint);
    72.     0x84,                   //bEndpointAddress(EndPoint4 as IN);
    73.     0x02,                   //bmAttributes(Bulk);
    74.     0x40,0x00,              //wMaxPacketSize(64);
    75.     0x00,                   //bInterval(Ignored);
    76.     0x07,                   //bLength(7);
    77.     0x05,                   //bDescriptorType(Endpoint);
    78.     0x04,                   //bEndpointAddress(EndPoint4 as OUT);
    79.     0x02,                   //bmAttributes(Bulk);
    80.     0x40,0x00,              //wMaxPacketSize(64);
    81.     0x00,                   //bInterval(Ignored);
    82. };
    复制代码
    附件使用一箭双雕USB转双串口A0例程修改USB配置,
    主函数里将自检部分删除避免使用不同板子测试自检通不过导致不识别。
    通过最小改动达到需求。


    USB-CDC转单串口开源例程 - 根据串口波特率自动调整主频.zip

    38.64 KB, 下载次数: 52

    回复 送花

    使用道具 举报

    该用户从未签到

    552

    主题

    9524

    回帖

    1万

    积分

    管理员

    积分
    14098
    发表于 2023-10-9 19:54:05 | 显示全部楼层
    也可从 辅助开发/烧录工具,STC-ISP V6.92D 或以上版本,下载:
    一箭双雕USB转双串口】学习板例程包里面的,开源例程
    截图202310091953039129.jpg

    截图202310091953587757.jpg
    例程A0/例程A1, 都是一箭双雕USB转双串口】演示例程

    回复 支持 反对 送花

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

    GMT+8, 2024-5-19 19:11 , Processed in 0.065963 second(s), 36 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表