Test

Committer:
JohnnyK
Date:
Wed Mar 23 16:58:28 2022 +0000
Revision:
3:17fe954e8cfc
Parent:
2:e7101cf1ca6e
Child:
4:928351381957
Correction

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JohnnyK 0:aaec057956ca 1 #include "mbed.h"
JohnnyK 0:aaec057956ca 2
JohnnyK 0:aaec057956ca 3 /* !!!Change pins according to your connection!!! */
JohnnyK 3:17fe954e8cfc 4 BufferedSerial uart(D10,D2 115200); // UART TX, RX
JohnnyK 0:aaec057956ca 5 ATCmdParser module(&uart,"\r\n");
JohnnyK 0:aaec057956ca 6
JohnnyK 0:aaec057956ca 7 // init the module
JohnnyK 0:aaec057956ca 8 bool ModulePowerOn() {
JohnnyK 0:aaec057956ca 9 bool result = false;
JohnnyK 0:aaec057956ca 10 result = module.recv("OK");
JohnnyK 0:aaec057956ca 11 if(!result){
JohnnyK 2:e7101cf1ca6e 12 for(int i=0;i<10;i++){
JohnnyK 0:aaec057956ca 13 module.send("AT");
JohnnyK 0:aaec057956ca 14 thread_sleep_for(500);
JohnnyK 0:aaec057956ca 15 result = module.recv("OK");
JohnnyK 0:aaec057956ca 16 if(result){
JohnnyK 0:aaec057956ca 17 break;
JohnnyK 0:aaec057956ca 18 }
JohnnyK 0:aaec057956ca 19 }
JohnnyK 0:aaec057956ca 20 }
JohnnyK 0:aaec057956ca 21 return result;
JohnnyK 0:aaec057956ca 22 }
JohnnyK 0:aaec057956ca 23
JohnnyK 0:aaec057956ca 24 // setup
JohnnyK 0:aaec057956ca 25 int main() {
JohnnyK 0:aaec057956ca 26
JohnnyK 0:aaec057956ca 27 printf("Mbed A9G test\n");
JohnnyK 0:aaec057956ca 28 module.debug_on(true);
JohnnyK 0:aaec057956ca 29 if(ModulePowerOn()){
JohnnyK 0:aaec057956ca 30 printf("Module is up!\n");
JohnnyK 0:aaec057956ca 31 } else {
JohnnyK 0:aaec057956ca 32 printf("No communication with module!\n");
JohnnyK 0:aaec057956ca 33 }
JohnnyK 0:aaec057956ca 34
JohnnyK 0:aaec057956ca 35 // loop
JohnnyK 0:aaec057956ca 36 while(true)
JohnnyK 0:aaec057956ca 37 {
JohnnyK 0:aaec057956ca 38 //do something in loop
JohnnyK 0:aaec057956ca 39 thread_sleep_for(1000);
JohnnyK 0:aaec057956ca 40 }
JohnnyK 0:aaec057956ca 41 }