Mbed USB client

From emboxit
Revision as of 16:51, 11 September 2015 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Suga koubou libraries and programs


mbed handbook

  • Driver required on Windows!


USBSerial Hello World!

#include "mbed.h"
#include "USBSerial.h"

//Virtual serial port over USB
USBSerial serial;

int main(void) {

    while(1)
    {
        serial.printf("I am a virtual serial port\r\n");
        wait(1);
    }
}



USBSerial echo

#include "mbed.h"
#include "USBSerial.h"

//Virtual serial port over USB
USBSerial serial;
Serial pc(USBTX, USBRX);

int main(void) {
    uint8_t buf[128];
    while(1)
    {
        serial.scanf("%s", buf);
        serial.printf("recv: %s", buf);
        pc.printf("recv: %s\r\n", buf);
    }
}

comments

The USBSerial constructor waits until the device is connected. So if the cable is not plugged, the mbed will hang. 
You can see if the connection is working in the device manager on windows. 
I think that the best way to check the usb connection is USBMouse. 
If the cursor is moving on your screen, it means that the usb connection is correct.