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

Dependencies:   mbed-src MODSERIAL

Notebook page HERE

Files at this revision

API Documentation at this revision

Comitter:
edodm85
Date:
Fri Oct 18 21:31:21 2013 +0000
Parent:
1:a11db105c379
Child:
3:2f5485de3328
Commit message:
Rewrited some parts

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/MODSERIAL.lib	Thu May 31 19:56:30 2012 +0000
+++ b/MODSERIAL.lib	Fri Oct 18 21:31:21 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/AjK/code/MODSERIAL/#c11ea36f17f9
+http://mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
--- a/main.cpp	Thu May 31 19:56:30 2012 +0000
+++ b/main.cpp	Fri Oct 18 21:31:21 2013 +0000
@@ -1,58 +1,94 @@
 /*
  * Author: Edoardo De Marchi
- * Date: 31-05-12
- * Notes: AT command
+ * Date: 02-07-13
+ * Notes: HC05 AT command
 */
 
 #include "mbed.h"
 #include "MODSERIAL.h"
 
 
-MODSERIAL pc(USBTX, USBRX);      
+#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);
 
 
-void commandAT(char *v){        // Send the AT command
+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){ 
+  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());
+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(){
-  
+int main()
+{
    blue.baud(38400);
-   pc.baud(115200);
-
-   char s[80];
+   pc.baud(9600);
+   
+   blue.attach(&rxBlueCallback, MODSERIAL::RxIrq);
+   pc.attach(&rxPcCallback, MODSERIAL::RxIrq);
+    
+   pc.printf("AT Mode Start\r\n"); 
    
-   while(1){
-        pc.printf("Command: ");
-        pc.scanf("%s",s);
-      
-        wait_us(100);
-      
-        commandAT(s);
-        wait_us(100);
+   while(1)
+   {
+        if(new_send)
+        {
+            int i = 0;
         
-        pc.printf("Response: ");
-      
-        blue.attach(&rxCallback, MODSERIAL::RxIrq);
-        wait(1);
+            while(pc.readable())
+            {
+                ATCmd[i] = pc.getc();
+                i++;
+            }
+            commandAT(ATCmd);
+            new_send = false;
+        }else
+        if(new_response)
+        {
+            int i = 0;
+            while(blue.readable())
+            {
+                blueChar[i] = blue.getc();
+                i++;
+            }
+            printf("Response: %s", blueChar);  
+            new_response = false;   
+        }    
+        wait_ms(100);
     } 
 }
\ No newline at end of file
--- a/mbed.bld	Thu May 31 19:56:30 2012 +0000
+++ b/mbed.bld	Fri Oct 18 21:31:21 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file