Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial USBDevice mbed
Fork of USB2UART by
Diff: main.cpp
- Revision:
- 0:8c4eea221dcf
- Child:
- 1:efa9f62a12c4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Oct 30 02:01:50 2013 +0000
@@ -0,0 +1,37 @@
+/**
+ * USB to UART Bridge
+ */
+
+#include "mbed.h"
+#include "USBSerial.h"
+
+Serial uart(USBTX, USBRX);
+USBSerial pc;
+
+// Called by ISR
+void settingsChanged(int baud, int bits, int parity, int stop)
+{
+ const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1};
+
+ if (stop != 2) {
+ stop = 1; // stop bit(s) = 1 or 1.5
+ }
+
+ uart.baud(baud);
+ uart.format(bits, parityTable[parity], stop);
+}
+
+int main()
+{
+ pc.attach(settingsChanged);
+
+ while (1) {
+ while (uart.readable()) {
+ pc.putc(uart.getc());
+ }
+
+ while (pc.readable()) {
+ uart.putc(pc.getc());
+ }
+ }
+}
