* ECHO communication between Bluetooth and RS232 * Using mBED Landtiger Card

Dependencies:   mbed-src

Fork of HC05_Transparent_mode by Edoardo De Marchi

Committer:
edodm85
Date:
Wed Jul 11 18:28:07 2012 +0000
Revision:
0:44f245e8b430
Child:
1:8c500bcdcbc4
Trasparent Mode for the HC05 Bluetooth

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:44f245e8b430 1 #include "mbed.h"
edodm85 0:44f245e8b430 2
edodm85 0:44f245e8b430 3 Serial pc(USBTX, USBRX);
edodm85 0:44f245e8b430 4 Serial blue(p9,p10); // BTM400 == CH05
edodm85 0:44f245e8b430 5 DigitalOut myled(LED1);
edodm85 0:44f245e8b430 6 DigitalOut myled4(LED4);
edodm85 0:44f245e8b430 7
edodm85 0:44f245e8b430 8
edodm85 0:44f245e8b430 9 int main() {
edodm85 0:44f245e8b430 10
edodm85 0:44f245e8b430 11 blue.baud(9600);
edodm85 0:44f245e8b430 12 pc.baud(9600);
edodm85 0:44f245e8b430 13
edodm85 0:44f245e8b430 14 // echo back characters, toggle the LED
edodm85 0:44f245e8b430 15 while (1) {
edodm85 0:44f245e8b430 16 if (blue.readable()) {
edodm85 0:44f245e8b430 17 pc.putc(blue.getc());
edodm85 0:44f245e8b430 18 myled = !myled;
edodm85 0:44f245e8b430 19 }
edodm85 0:44f245e8b430 20 if (pc.readable()) {
edodm85 0:44f245e8b430 21 blue.putc(pc.getc());
edodm85 0:44f245e8b430 22 myled4 = !myled4;
edodm85 0:44f245e8b430 23 }
edodm85 0:44f245e8b430 24
edodm85 0:44f245e8b430 25 }
edodm85 0:44f245e8b430 26 }
edodm85 0:44f245e8b430 27
edodm85 0:44f245e8b430 28
edodm85 0:44f245e8b430 29
edodm85 0:44f245e8b430 30 /*
edodm85 0:44f245e8b430 31 void commandAT(char *v)
edodm85 0:44f245e8b430 32 {
edodm85 0:44f245e8b430 33 int i=0;
edodm85 0:44f245e8b430 34 while(v[i] != '\n')
edodm85 0:44f245e8b430 35 {
edodm85 0:44f245e8b430 36 blue.putc(v[i]);
edodm85 0:44f245e8b430 37 i++;
edodm85 0:44f245e8b430 38 }
edodm85 0:44f245e8b430 39 blue.putc('\n');
edodm85 0:44f245e8b430 40 }
edodm85 0:44f245e8b430 41
edodm85 0:44f245e8b430 42 void readResponse()
edodm85 0:44f245e8b430 43 {
edodm85 0:44f245e8b430 44 int a = blue.readable();
edodm85 0:44f245e8b430 45 pc.printf("Caratteri disponibili: ");
edodm85 0:44f245e8b430 46 pc.putc(a);
edodm85 0:44f245e8b430 47 if(a > 0){
edodm85 0:44f245e8b430 48 for(int i=0; i < a; i++){
edodm85 0:44f245e8b430 49
edodm85 0:44f245e8b430 50 char data = (char)blue.getc();
edodm85 0:44f245e8b430 51
edodm85 0:44f245e8b430 52 pc.putc(data);
edodm85 0:44f245e8b430 53 wait_us(100);
edodm85 0:44f245e8b430 54
edodm85 0:44f245e8b430 55 }
edodm85 0:44f245e8b430 56 }
edodm85 0:44f245e8b430 57
edodm85 0:44f245e8b430 58
edodm85 0:44f245e8b430 59 }
edodm85 0:44f245e8b430 60
edodm85 0:44f245e8b430 61 int main()
edodm85 0:44f245e8b430 62 {
edodm85 0:44f245e8b430 63
edodm85 0:44f245e8b430 64 blue.baud(38400);
edodm85 0:44f245e8b430 65 pc.baud(9600);
edodm85 0:44f245e8b430 66 pc.printf("Inizializzo sistema... \n");
edodm85 0:44f245e8b430 67
edodm85 0:44f245e8b430 68
edodm85 0:44f245e8b430 69 //Comando AT da inviare
edodm85 0:44f245e8b430 70 char s[] = "AT\r\n";
edodm85 0:44f245e8b430 71 pc.printf("Scrivo comando: ");
edodm85 0:44f245e8b430 72 pc.printf(s);
edodm85 0:44f245e8b430 73
edodm85 0:44f245e8b430 74 wait_us(50);
edodm85 0:44f245e8b430 75
edodm85 0:44f245e8b430 76 //Invio comando all'antenna
edodm85 0:44f245e8b430 77 commandAT(s);
edodm85 0:44f245e8b430 78 wait_us(50);
edodm85 0:44f245e8b430 79
edodm85 0:44f245e8b430 80 //Leggo la risposta
edodm85 0:44f245e8b430 81 readResponse();
edodm85 0:44f245e8b430 82 }*/
edodm85 0:44f245e8b430 83
edodm85 0:44f245e8b430 84
edodm85 0:44f245e8b430 85
edodm85 0:44f245e8b430 86
edodm85 0:44f245e8b430 87