You are viewing an older revision! See the latest version
USBHostSerial
mbed OS 2 and mbed OS 5
This is the handbook for mbed OS 2. If you’re working with mbed OS 5, please see the new handbook and API References.
The USBHostSerial interface is used to communicate with a virtual serial port usb device.
Library in Beta!
This library is in Beta. If you have any problems using the USBHost library, please send a bug report at support@mbed.org
The USB Host connector should be attached to
- p31 (D+), p32 (D-) and GND for the LPC1768
- add two 15k resistors tied to GND on D+ and D-
Hello World¶
Import program
00001 #include "mbed.h" 00002 #include "USBHostSerial.h" 00003 00004 DigitalOut led(LED1); 00005 Serial pc(USBTX, USBRX); 00006 00007 void serial_task(void const*) { 00008 USBHostSerial serial; 00009 00010 while(1) { 00011 00012 // try to connect a serial device 00013 while(!serial.connect()) 00014 Thread::wait(500); 00015 00016 // in a loop, print all characters received 00017 // if the device is disconnected, we try to connect it again 00018 while (1) { 00019 00020 // if device disconnected, try to connect it again 00021 if (!serial.connected()) 00022 break; 00023 00024 // print characters received 00025 while (serial.available()) { 00026 printf("%c", serial.getc()); 00027 } 00028 00029 Thread::wait(50); 00030 } 00031 } 00032 } 00033 00034 int main() { 00035 Thread serialTask(serial_task, NULL, osPriorityNormal, 256 * 4); 00036 while(1) { 00037 led=!led; 00038 Thread::wait(500); 00039 } 00040 }
API¶
Import libraryUSBHost
Troobleshooting
If your mbed board is automatically resetted when you plug a USB device, you should consider to use an external power supply