Grupo1 Proyectopioix19 / Mbed 2 deprecated proyectoHC05_KL25Z_Hello_PC

Dependencies:   mbed MODSERIAL

Committer:
tanofgennaro
Date:
Fri Oct 25 02:46:52 2019 +0000
Revision:
3:20222fa63b3e
Parent:
2:cbc675b0abd5
commit publicacion;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerritPathuis 0:0e236e004748 1 /*
GerritPathuis 0:0e236e004748 2 * Author: G. Pathuis
GerritPathuis 0:0e236e004748 3 * Date: 02-12-17
GerritPathuis 0:0e236e004748 4 * Notes: HC05 connected to a KL25Z
GerritPathuis 0:0e236e004748 5 * Pair with PC use password 1234
GerritPathuis 0:0e236e004748 6 *
GerritPathuis 0:0e236e004748 7 * Four wire connection
GerritPathuis 0:0e236e004748 8 * HC05 to KL25Z
GerritPathuis 0:0e236e004748 9 * GND to GND
GerritPathuis 0:0e236e004748 10 * +5V to 5V
GerritPathuis 0:0e236e004748 11 * TX to pin PTE0
GerritPathuis 0:0e236e004748 12 * RX to pin PTE1
GerritPathuis 0:0e236e004748 13 *
GerritPathuis 0:0e236e004748 14 * Open Tera Term session to connect to KL25Z
GerritPathuis 0:0e236e004748 15 * and
GerritPathuis 0:0e236e004748 16 * Open second Tera Term session to read the Bluetooth
GerritPathuis 2:cbc675b0abd5 17 * dongle in the PC set at 38400 baud
GerritPathuis 0:0e236e004748 18 *
GerritPathuis 1:e73a7c99f767 19 * http://www.wavesen.com
GerritPathuis 0:0e236e004748 20 */
GerritPathuis 0:0e236e004748 21
GerritPathuis 0:0e236e004748 22 #include "mbed.h"
GerritPathuis 1:e73a7c99f767 23 #include "MODSERIAL.h"
GerritPathuis 0:0e236e004748 24
GerritPathuis 2:cbc675b0abd5 25 MODSERIAL pc(USBTX, USBRX, 256, 256);
GerritPathuis 2:cbc675b0abd5 26 MODSERIAL blue(PTE0, PTE1, 256, 256); // TX, RX
GerritPathuis 1:e73a7c99f767 27
GerritPathuis 1:e73a7c99f767 28 DigitalOut myled1(LED1); //Blue
GerritPathuis 1:e73a7c99f767 29 DigitalOut myled2(LED2); //Green
GerritPathuis 1:e73a7c99f767 30
GerritPathuis 1:e73a7c99f767 31 // This function is called when a character received from PC
GerritPathuis 1:e73a7c99f767 32 void pc_rxCallback(MODSERIAL_IRQ_INFO *q)
GerritPathuis 1:e73a7c99f767 33 {
GerritPathuis 2:cbc675b0abd5 34 int c;
GerritPathuis 0:0e236e004748 35
GerritPathuis 1:e73a7c99f767 36 c= pc.getc();
GerritPathuis 1:e73a7c99f767 37 blue.putc(c); // Send from PC to Blue
GerritPathuis 1:e73a7c99f767 38 pc.putc(c); // Echo to PC
GerritPathuis 1:e73a7c99f767 39 }
GerritPathuis 0:0e236e004748 40
GerritPathuis 1:e73a7c99f767 41 // This function is called when a character received from Bluetooth
GerritPathuis 1:e73a7c99f767 42 void blue_rxCallback(MODSERIAL_IRQ_INFO *q)
GerritPathuis 1:e73a7c99f767 43 {
GerritPathuis 2:cbc675b0abd5 44 //char b;
GerritPathuis 2:cbc675b0abd5 45 int b;
GerritPathuis 0:0e236e004748 46
GerritPathuis 1:e73a7c99f767 47 myled1 = !myled1;
GerritPathuis 1:e73a7c99f767 48 b= blue.getc();
GerritPathuis 1:e73a7c99f767 49 pc.putc(b);
GerritPathuis 1:e73a7c99f767 50 }
GerritPathuis 0:0e236e004748 51
GerritPathuis 0:0e236e004748 52 int main()
GerritPathuis 0:0e236e004748 53 {
GerritPathuis 2:cbc675b0abd5 54
GerritPathuis 2:cbc675b0abd5 55 pc.baud(9600);
GerritPathuis 2:cbc675b0abd5 56 pc.format(8,SerialBase::None,1);
tanofgennaro 3:20222fa63b3e 57 blue.baud(9600); // Default Bluetooth Baudrate
GerritPathuis 2:cbc675b0abd5 58 blue.format(8,SerialBase::None,1);
GerritPathuis 1:e73a7c99f767 59
GerritPathuis 1:e73a7c99f767 60 pc.printf("Bluetooth HC-05\r\n");
GerritPathuis 1:e73a7c99f767 61 pc.printf("Make sure the terminal programm ends with CR-LF\r\n");
GerritPathuis 1:e73a7c99f767 62 pc.printf("\r\n");
GerritPathuis 0:0e236e004748 63
GerritPathuis 1:e73a7c99f767 64 wait_ms(100);
GerritPathuis 1:e73a7c99f767 65
GerritPathuis 1:e73a7c99f767 66 // Char from PC, interrupt service routine
GerritPathuis 1:e73a7c99f767 67 pc.attach(&pc_rxCallback, MODSERIAL::RxIrq);
GerritPathuis 1:e73a7c99f767 68
GerritPathuis 1:e73a7c99f767 69 // Char from Bluetooth, interrupt service routine
GerritPathuis 1:e73a7c99f767 70 blue.attach(&blue_rxCallback, MODSERIAL::RxIrq);
GerritPathuis 1:e73a7c99f767 71
GerritPathuis 0:0e236e004748 72
GerritPathuis 1:e73a7c99f767 73 // Set up
GerritPathuis 2:cbc675b0abd5 74 pc.puts("\r\nAT=");
GerritPathuis 1:e73a7c99f767 75 blue.puts("AT\r\n");
GerritPathuis 2:cbc675b0abd5 76 wait_ms(1000);
GerritPathuis 1:e73a7c99f767 77
GerritPathuis 2:cbc675b0abd5 78 pc.puts("\r\nAT+VERSION?= ");
GerritPathuis 1:e73a7c99f767 79 blue.puts("AT+VERSION?\r\n");
GerritPathuis 2:cbc675b0abd5 80 wait_ms(1000);
GerritPathuis 0:0e236e004748 81
GerritPathuis 2:cbc675b0abd5 82 pc.puts("\r\nAT+ADDR?= ");
GerritPathuis 1:e73a7c99f767 83 blue.puts("AT+ADDR?\r\n");
GerritPathuis 2:cbc675b0abd5 84 wait_ms(1000);
GerritPathuis 1:e73a7c99f767 85
GerritPathuis 2:cbc675b0abd5 86 pc.puts("\r\nAT+NAME?= ");
GerritPathuis 1:e73a7c99f767 87 blue.puts("AT+NAME?\r\n");
GerritPathuis 2:cbc675b0abd5 88 wait_ms(1000);
GerritPathuis 2:cbc675b0abd5 89
tanofgennaro 3:20222fa63b3e 90 pc.puts("\r\nAT+UART=9600,0,0"); //No parity, 1 Stop bit
tanofgennaro 3:20222fa63b3e 91 blue.puts("AT+UART=9600,0,0\r\n"); //No parity, 1 Stop bit
GerritPathuis 2:cbc675b0abd5 92 wait_ms(1000);
GerritPathuis 1:e73a7c99f767 93
GerritPathuis 2:cbc675b0abd5 94 pc.puts("\r\nAT+UART?= ");
GerritPathuis 2:cbc675b0abd5 95 blue.puts("AT+UART?\r\n");
GerritPathuis 2:cbc675b0abd5 96 wait_ms(1000);
GerritPathuis 2:cbc675b0abd5 97
GerritPathuis 2:cbc675b0abd5 98 pc.puts("\r\nAT+Role?= ");
GerritPathuis 2:cbc675b0abd5 99 blue.puts("AT+Role?\r\n");
GerritPathuis 2:cbc675b0abd5 100 wait_ms(1000);
GerritPathuis 1:e73a7c99f767 101
GerritPathuis 2:cbc675b0abd5 102 pc.puts("\r\nAT+RESET= ");
GerritPathuis 2:cbc675b0abd5 103 blue.puts("AT+RESET\r\n");
GerritPathuis 2:cbc675b0abd5 104 wait_ms(1000);
GerritPathuis 2:cbc675b0abd5 105
GerritPathuis 2:cbc675b0abd5 106
GerritPathuis 0:0e236e004748 107 while (1) {
GerritPathuis 0:0e236e004748 108 }
GerritPathuis 0:0e236e004748 109 }