Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-src MODSERIAL
Revision 2:08505f23f37a, committed 2013-10-18
- 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
--- 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
Bluetooth HC-05