This program send an AT command to the HC05 module and shows the response into a terminal.

Dependencies:   mbed-src MODSERIAL

Notebook page HERE

main.cpp

Committer:
edodm85
Date:
2012-05-31
Revision:
0:7bb229e58814
Child:
1:a11db105c379

File content as of revision 0:7bb229e58814:

/*
 * Author: Edoardo De Marchi
 * Date: 31-05-12
 * Notes: AT command
*/

#include "mbed.h"
#include "MODSERIAL.h"


MODSERIAL pc(USBTX, USBRX);      // tx, rx
MODSERIAL blue(p9,p10);          // HC05
DigitalOut led1(LED1);
DigitalOut led4(LED4);


void commandAT(char *v){

  int i=0;
  
  while(v[i] != NULL){ 
    blue.putc(v[i]);
    i++;
  }
  
  blue.printf("\r\n");
}


// This function is called when a character goes into the RX buffer.
void rxCallback(MODSERIAL_IRQ_INFO *q) {
    led4 = !led4;
    pc.putc(blue.getc());
}


int main(){
  
   blue.baud(38400);
   pc.baud(115200);

   char s[80];
   
   while(1){
        pc.printf("Command: ");
        pc.scanf("%s",s);
      
        wait_us(100);
      
        commandAT(s);
        wait_us(100);
        
        pc.printf("Response: ");
      
        blue.attach(&rxCallback, MODSERIAL::RxIrq);
        wait(1);
    } 
}