* ECHO communication between Bluetooth and RS232 * Using mBED Landtiger Card
Fork of HC05_Transparent_mode by
main.cpp@4:c68d2d96da42, 2016-03-12 (annotated)
- Committer:
- alex_G_blanco
- Date:
- Sat Mar 12 01:12:36 2016 +0000
- Revision:
- 4:c68d2d96da42
- Parent:
- 3:8783bfb5d8fa
* ECHO communication between Bluetooth and RS232; * Using mBED Landtiger Card
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edodm85 | 1:8c500bcdcbc4 | 1 | /* |
alex_G_blanco | 4:c68d2d96da42 | 2 | * ECHO communication between Bluetooth and RS232 |
alex_G_blanco | 4:c68d2d96da42 | 3 | * Using mBED Landtiger Card |
alex_G_blanco | 4:c68d2d96da42 | 4 | * Based on HC05 work by: |
edodm85 | 1:8c500bcdcbc4 | 5 | * Author: Edoardo De Marchi |
edodm85 | 3:8783bfb5d8fa | 6 | * Date: 11-08-14 |
edodm85 | 1:8c500bcdcbc4 | 7 | * Notes: HC05 Trasparent Mode |
edodm85 | 1:8c500bcdcbc4 | 8 | */ |
edodm85 | 1:8c500bcdcbc4 | 9 | |
alex_G_blanco | 4:c68d2d96da42 | 10 | //mBED Complete libraries |
edodm85 | 0:44f245e8b430 | 11 | #include "mbed.h" |
edodm85 | 0:44f245e8b430 | 12 | |
alex_G_blanco | 4:c68d2d96da42 | 13 | //Serial Pin port configurations |
alex_G_blanco | 4:c68d2d96da42 | 14 | //pc - RS232 serial port, blue - bluetootk serial port |
alex_G_blanco | 4:c68d2d96da42 | 15 | Serial pc(P0_10, P0_11); //tx, rx pins for the Landtiger, use COM2 UART2 connector direct from the card |
alex_G_blanco | 4:c68d2d96da42 | 16 | Serial blue(P0_2, P0_3); // UART0_TX, UART0_RX for the LandTiger. Connect a BT module to these pins |
edodm85 | 3:8783bfb5d8fa | 17 | |
alex_G_blanco | 4:c68d2d96da42 | 18 | //Define activity leds for RS232 and BT |
alex_G_blanco | 4:c68d2d96da42 | 19 | DigitalOut myled4(P2_7);//landtiger LEDS LD4, LD5 |
alex_G_blanco | 4:c68d2d96da42 | 20 | DigitalOut myled5(P2_6); |
alex_G_blanco | 4:c68d2d96da42 | 21 | BusOut LEDS(P2_5, P2_4, P2_3, P2_2, P2_1, P2_0); //landtiger all leds |
edodm85 | 3:8783bfb5d8fa | 22 | |
alex_G_blanco | 4:c68d2d96da42 | 23 | int temp; |
edodm85 | 1:8c500bcdcbc4 | 24 | |
alex_G_blanco | 4:c68d2d96da42 | 25 | //Main routine |
edodm85 | 1:8c500bcdcbc4 | 26 | int main() |
edodm85 | 1:8c500bcdcbc4 | 27 | { |
alex_G_blanco | 4:c68d2d96da42 | 28 | //Serial ports initialization |
alex_G_blanco | 4:c68d2d96da42 | 29 | blue.baud(9600); |
alex_G_blanco | 4:c68d2d96da42 | 30 | pc.baud(9600); |
edodm85 | 1:8c500bcdcbc4 | 31 | pc.printf("Bluetooth Start\r\n"); |
alex_G_blanco | 4:c68d2d96da42 | 32 | blue.printf("Communication Start \r\n\0"); |
alex_G_blanco | 4:c68d2d96da42 | 33 | LEDS = 0; //turn off other leds |
edodm85 | 1:8c500bcdcbc4 | 34 | |
edodm85 | 1:8c500bcdcbc4 | 35 | // echo back characters and toggle the LED |
edodm85 | 1:8c500bcdcbc4 | 36 | while (1) |
edodm85 | 1:8c500bcdcbc4 | 37 | { |
edodm85 | 1:8c500bcdcbc4 | 38 | if (blue.readable()) |
edodm85 | 1:8c500bcdcbc4 | 39 | { |
alex_G_blanco | 4:c68d2d96da42 | 40 | temp = blue.getc(); //reads BT one character |
alex_G_blanco | 4:c68d2d96da42 | 41 | pc.putc(temp); // puts character in serial |
alex_G_blanco | 4:c68d2d96da42 | 42 | blue.putc(temp); //echo BT |
alex_G_blanco | 4:c68d2d96da42 | 43 | myled4 = !myled4; //Led BT activity |
edodm85 | 0:44f245e8b430 | 44 | } |
edodm85 | 1:8c500bcdcbc4 | 45 | if (pc.readable()) |
edodm85 | 1:8c500bcdcbc4 | 46 | { |
alex_G_blanco | 4:c68d2d96da42 | 47 | temp = pc.getc(); //reads RS232 one character |
alex_G_blanco | 4:c68d2d96da42 | 48 | blue.putc(temp); //puts character thru BT |
alex_G_blanco | 4:c68d2d96da42 | 49 | pc.putc(temp); // echo serial |
alex_G_blanco | 4:c68d2d96da42 | 50 | blue.printf("\0"); //null character to empty BT buffer |
alex_G_blanco | 4:c68d2d96da42 | 51 | myled5 = !myled5; // RS232 activity led |
edodm85 | 0:44f245e8b430 | 52 | } |
edodm85 | 0:44f245e8b430 | 53 | |
edodm85 | 0:44f245e8b430 | 54 | } |
alex_G_blanco | 4:c68d2d96da42 | 55 | } |