单片机学习小组
直播中

王健

7年用户 919经验值
私信 关注

M483KG如何使用HSUSBH_USBH_VCOM读写PL2303?

环境:
    开发版: M483KG
    usb转uart:   PL 2303/ FT 232

目的:       如何使用HSUSBH_USBH_VCOM 读写PL 2303/ FT 232?


问题:
    插拔PL2303/FR232装置,会显示Connect device, disconnect device
    但是不知道如何传收资料。

    讯息如下:
+---------------------------------------------------------+
|           M480 USB Host VCOM sample program             |
+---------------------------------------------------------+
|  (NOTE: This sample supports only one CDC device, but   |
|         driver supports multiple CDC devices. If you    |
|         want to support multiple CDC devices, you       |
|         have to modify this sample.                     |
+---------------------------------------------------------+
USB static memory: 6/256, heap used: 0
Connect device =>
New full-speed device address 2 assigned.
USB static memory: 7/256, heap used: 568
disconnect device...
USB static memory: 6/256, heap used: 0
USB static memory: 6/256, heap used: 0
Connect device =>
New full-speed device address 3 assigned.
USB static memory: 7/256, heap used: 568
disconnect device...
USB static memory: 6/256, heap used: 0
USB static memory: 6/256, heap used: 0
Connect device =>
New full-speed device address 4 assigned.
USB static memory: 7/256, heap used: 568

回帖(1)

刘敏

2024-1-2 16:36:17
                  |+---------------------------------------------------------+Connect Device!.............................................Disconnect Device!..........................................Device Descriptor:    bLength = 18    bDescriptorType = 1    bcdUSB = 2.00    bDeviceClass = 0    bDeviceSubClass = 0    bDeviceProtocol = 0    bMaxPacketSize0 = 8    idVendor = 67B    idProduct = 2303    bcdDevice = 3.00    iManufacturer = 1    iProduct = 2    iSerialNumber = 0    bNumConfigurations = 1Configuration Descriptor:    bLength = 9    bDescriptorType = 2    wTotalLength = 39    bNumInterfaces = 1    bConfigurationValue = 1    iConfiguration = 4    bmAttributes = 0x80    bMaxPower = 2 mAInterface Descriptor:    bLength = 9    bDescriptorType = 4    bInterfaceNumber = 0    bAlternateSetting = 0    bNumEndpoints = 2    bInterfaceClass = 0xff    bInterfaceSubClass = 0xff    bInterfaceProtocol = 0xff    iInterface = 4Endpoint Descriptor:    bLength = 7    bDescriptorType = 5    bEndpointAddress = 0x81    bmAttributes = 0x03    wMaxPacketSize = 64    bInterval = 0x00Endpoint Descriptor:    bLength = 7    bDescriptorType = 5    bEndpointAddress = 0x01    bmAttributes = 0x03    wMaxPacketSize = 64    bInterval = 0x00

解答:

在使用HSUSBH_USBH_VCOM时,需要使用以下步骤来读写PL 2303/ FT 232:

1. 在初始化时,通过VID 和 PID 确认已连接设备。

```c
USBH_PL2303_Init(USBH_Pl2303VendorID, USBH_Pl2303ProductID); // 使用 VID 和 PID 初始化 PL 2303
```

2. 在USB设备连接后,可以通过 USBH_PL2303_IsConnected() 函数确认是否连接:

```c
if(USBH_PL2303_IsConnected(&USB_OTG_Core_dev)) // 如果连接了 PL2303
{
  printf("PL2303 connected!rn"); // 打印设备已连接
}
```

3. 通过USBH_PL2303_TransmitData() 函数进行数据写入:

```c
USBH_PL2303_TransmitData(&USB_OTG_Core_dev, txbuf, strlen((const char *)txbuf)); // 发送数据
```

4. 使用USBH_PL2303_ReceiveData() 函数进行数据读取:

```c
USBH_PL2303_ReceiveData(&USB_OTG_Core_dev, rxbuf, &rxlen); // 接收数据
```

5. 需要注意的是,USB转UART的芯片在使用时需要通过虚拟串口的方式进行操作,需要安装对应的驱动程序。同时,在使用PL2303/ FT 232时,需要在Windows设备管理器中查看虚拟串口的号码,然后使用对应的串口进行数据读写。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分