Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 11 months ago.
USBSerial Initialization
I am using USBSerial on a KL25Z for access via the usb/serial port. I want to run the board on battery and only use the serial port to read out stored data.
My program will not start without the usb/serial port connected. Once it gets started it will run on the battery. I suspect that the "USBSerial serial;" declaration needs to get initialized before anything else can run.
I would like to have it start without having an active usb/serial port connection. Is there a way to do this?
1 Answer
7 years, 11 months ago.
USBSerial is defined as:
USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true)
connect_blocking needs to be set to false, and for that to be able to be set you need also to add the other arguments in your constructor (just copy the default values).
I believe that should do the job, I have done it myself with USBMSD, but not with USBSerial
Thanks for the suggestion. The program will now start put when I then plug in the USBSerial connection, my PC doesn't know it is there so I can't read out the data. I guess what I need is to not initialize the port until there is an actual connection. My program on the micro would have to somehow detect that the connection exists before initializing the port. Any suggestions on how to do this?
posted by 05 Dec 2016There is a USBDevice command that checks if the connection has been made, and you can use it before you start printing information to your PC. However at least USBMSD doesn't require you to do anything else to start the connection. It simply waits on an interrupt to happen. Only when you disable interrupts it wouldn't work.
posted by 05 Dec 2016