This program send an AT command to the HC05 module and shows the response into a terminal.
Dependencies: MODSERIAL
Fork of HC05_AT_mode by
main.cpp
- Committer:
- edodm85
- Date:
- 2013-10-19
- Revision:
- 3:2f5485de3328
- Parent:
- 2:08505f23f37a
- Child:
- 5:73ac83c240ec
File content as of revision 3:2f5485de3328:
/* * Author: Edoardo De Marchi * Date: 02-07-13 * Notes: HC05 AT command */ #include "mbed.h" #include "MODSERIAL.h" #define SERIAL_1 #ifdef SERIAL_1 MODSERIAL blue(p9,p10); // HC05 #endif #ifdef SERIAL_2 MODSERIAL blue(p13,p14); // HC05 #endif MODSERIAL pc(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led4(LED4); bool new_send = false; bool new_response = false; char ATCmd[80]; char blueChar[80]; void commandAT(char *v) // Send the AT command { 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 rxBlueCallback(MODSERIAL_IRQ_INFO *q) { new_response = true; } // This function is called when a character goes into the RX buffer. void rxPcCallback(MODSERIAL_IRQ_INFO *q) { new_send = true; } int main() { blue.baud(38400); pc.baud(9600); blue.attach(&rxBlueCallback, MODSERIAL::RxIrq); pc.attach(&rxPcCallback, MODSERIAL::RxIrq); pc.printf("AT Mode Start\r\n"); while(1) { if(new_send) { int i = 0; while(pc.readable()) { ATCmd[i] = pc.getc(); i++; } commandAT(ATCmd); memset(ATCmd, 0, sizeof(ATCmd)); new_send = false; }else if(new_response) { int i = 0; while(blue.readable()) { blueChar[i] = blue.getc(); i++; } printf("Response: %s", blueChar); memset(blueChar, 0, sizeof(blueChar)); new_response = false; } wait_ms(100); } }