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.
Diff: main.cpp
- Revision:
- 1:e73a7c99f767
- Parent:
- 0:0e236e004748
- Child:
- 2:cbc675b0abd5
diff -r 0e236e004748 -r e73a7c99f767 main.cpp
--- a/main.cpp Sat Dec 02 13:21:04 2017 +0000
+++ b/main.cpp Sun Dec 03 13:49:58 2017 +0000
@@ -17,43 +17,85 @@
* dongle in the PC
*
* Make sute Tera Term uses 9600 baud
+ * http://www.wavesen.com
*/
#include "mbed.h"
+#include "MODSERIAL.h"
+MODSERIAL pc(USBTX, USBRX);
+MODSERIAL blue(PTE0, PTE1); // TX, RX
+
+DigitalOut myled1(LED1); //Blue
+DigitalOut myled2(LED2); //Green
+
+// This function is called when a character received from PC
+void pc_rxCallback(MODSERIAL_IRQ_INFO *q)
+{
+ char c;
-Serial pc(USBTX, USBRX);
-Serial blue(PTE0, PTE1); // TX, RX
+ c= pc.getc();
+ blue.putc(c); // Send from PC to Blue
+ pc.putc(c); // Echo to PC
+}
-DigitalOut myled(LED1);
-DigitalOut myled2(LED2);
+// This function is called when a character received from Bluetooth
+void blue_rxCallback(MODSERIAL_IRQ_INFO *q)
+{
+ char b;
+ myled1 = !myled1;
+ b= blue.getc();
+ pc.putc(b);
+}
int main()
{
- int i =0;
- blue.baud(9600); // Default Bluetooth Baudrate
- pc.baud(9600);
+ pc.baud(115200);
+ blue.baud(38400); // Default Bluetooth Baudrate
+
+ pc.printf("Bluetooth HC-05\r\n");
+ pc.printf("Make sure the terminal programm ends with CR-LF\r\n");
+ pc.printf("\r\n");
- pc.printf("Bluetooth Start\r\n");
+ wait_ms(100);
+
+ // Char from PC, interrupt service routine
+ pc.attach(&pc_rxCallback, MODSERIAL::RxIrq);
+
+ // Char from Bluetooth, interrupt service routine
+ blue.attach(&blue_rxCallback, MODSERIAL::RxIrq);
+
- // Write from Bluetooth to PC
- for (i=0; i<10; i++) {
- blue.printf("Hello PC this is the HC-05, %d\n\r", i);
- myled = !myled;
- }
- wait(1);
+ // Set up
+ pc.puts("AT=");
+ blue.puts("AT\r\n");
+ wait_ms(100);
+
+ pc.puts("AT+VERSION?= ");
+ blue.puts("AT+VERSION?\r\n");
+ wait_ms(100);
- // Echo back characters and toggle the LED
+ pc.puts("AT+ADDR?= ");
+ blue.puts("AT+ADDR?\r\n");
+ wait_ms(100);
+
+ pc.puts("AT+NAME?= ");
+ blue.puts("AT+NAME?\r\n");
+ wait_ms(100);
+
+ pc.puts("AT+Role?= ");
+ blue.puts("AT+Role? \r\n");
+ wait_ms(100);
+
+ // Echo back characters
while (1) {
if (blue.readable()) {
pc.putc(blue.getc());
- myled = !myled;
}
if (pc.readable()) {
blue.putc(pc.getc());
- myled2 = !myled2;
}
- wait_ms(10);
}
+
}
\ No newline at end of file