|+---------------------------------------------------------+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设备管理器中查看虚拟串口的号码,然后使用对应的串口进行数据读写。
|+---------------------------------------------------------+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设备管理器中查看虚拟串口的号码,然后使用对应的串口进行数据读写。
举报