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:
- 2:cbc675b0abd5
- Parent:
- 1:e73a7c99f767
- Child:
- 3:20222fa63b3e
diff -r e73a7c99f767 -r cbc675b0abd5 main.cpp
--- a/main.cpp Sun Dec 03 13:49:58 2017 +0000
+++ b/main.cpp Fri Dec 08 19:27:13 2017 +0000
@@ -14,17 +14,16 @@
* Open Tera Term session to connect to KL25Z
* and
* Open second Tera Term session to read the Bluetooth
- * dongle in the PC
+ * dongle in the PC set at 38400 baud
*
- * 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
+MODSERIAL pc(USBTX, USBRX, 256, 256);
+MODSERIAL blue(PTE0, PTE1, 256, 256); // TX, RX
DigitalOut myled1(LED1); //Blue
DigitalOut myled2(LED2); //Green
@@ -32,7 +31,7 @@
// This function is called when a character received from PC
void pc_rxCallback(MODSERIAL_IRQ_INFO *q)
{
- char c;
+ int c;
c= pc.getc();
blue.putc(c); // Send from PC to Blue
@@ -42,7 +41,8 @@
// This function is called when a character received from Bluetooth
void blue_rxCallback(MODSERIAL_IRQ_INFO *q)
{
- char b;
+ //char b;
+ int b;
myled1 = !myled1;
b= blue.getc();
@@ -51,8 +51,12 @@
int main()
{
- pc.baud(115200);
+ char c = 'A';
+
+ pc.baud(9600);
+ pc.format(8,SerialBase::None,1);
blue.baud(38400); // Default Bluetooth Baudrate
+ blue.format(8,SerialBase::None,1);
pc.printf("Bluetooth HC-05\r\n");
pc.printf("Make sure the terminal programm ends with CR-LF\r\n");
@@ -68,34 +72,49 @@
// Set up
- pc.puts("AT=");
+ pc.puts("\r\nAT=");
blue.puts("AT\r\n");
- wait_ms(100);
+ wait_ms(1000);
- pc.puts("AT+VERSION?= ");
+ pc.puts("\r\nAT+VERSION?= ");
blue.puts("AT+VERSION?\r\n");
- wait_ms(100);
+ wait_ms(1000);
- pc.puts("AT+ADDR?= ");
+ pc.puts("\r\nAT+ADDR?= ");
blue.puts("AT+ADDR?\r\n");
- wait_ms(100);
+ wait_ms(1000);
- pc.puts("AT+NAME?= ");
+ pc.puts("\r\nAT+NAME?= ");
blue.puts("AT+NAME?\r\n");
- wait_ms(100);
+ wait_ms(1000);
+
+ pc.puts("\r\nAT+UART=38400,0,0"); //No parity, 1 Stop bit
+ blue.puts("AT+UART=38400,0,0\r\n"); //No parity, 1 Stop bit
+ wait_ms(1000);
- pc.puts("AT+Role?= ");
- blue.puts("AT+Role? \r\n");
- wait_ms(100);
+ pc.puts("\r\nAT+UART?= ");
+ blue.puts("AT+UART?\r\n");
+ wait_ms(1000);
+
+ pc.puts("\r\nAT+Role?= ");
+ blue.puts("AT+Role?\r\n");
+ wait_ms(1000);
- // Echo back characters
+ pc.puts("\r\nAT+RESET= ");
+ blue.puts("AT+RESET\r\n");
+ wait_ms(1000);
+
+
+ // Send the alphabet
while (1) {
- if (blue.readable()) {
- pc.putc(blue.getc());
- }
- if (pc.readable()) {
- blue.putc(pc.getc());
+ for (int loop = 0; loop < 512; loop++) {
+
+ blue.printf("%c", c);
+ c++;
+ if (c > 'Z') c = 'A';
+ if (loop > 510) loop = 0;
+
+ wait_ms(100);
}
}
-
}
\ No newline at end of file