Jan Kamidra
/
Mbed_A9G_test
Test
main.cpp@1:56cb59d5a0e6, 2022-03-23 (annotated)
- Committer:
- JohnnyK
- Date:
- Wed Mar 23 15:07:28 2022 +0000
- Revision:
- 1:56cb59d5a0e6
- Parent:
- 0:aaec057956ca
- Child:
- 2:e7101cf1ca6e
Pins
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JohnnyK | 0:aaec057956ca | 1 | #include "mbed.h" |
JohnnyK | 0:aaec057956ca | 2 | #include<stdio.h> |
JohnnyK | 0:aaec057956ca | 3 | #include<string.h> |
JohnnyK | 0:aaec057956ca | 4 | |
JohnnyK | 0:aaec057956ca | 5 | /* !!!Change pins according to your connection!!! */ |
JohnnyK | 1:56cb59d5a0e6 | 6 | //DigitalOut RST_KEY(D4,0); |
JohnnyK | 1:56cb59d5a0e6 | 7 | //DigitalOut LOW_PWR_KEY(D5,1); |
JohnnyK | 1:56cb59d5a0e6 | 8 | DigitalOut PWR_KEY(D9,1); |
JohnnyK | 0:aaec057956ca | 9 | |
JohnnyK | 0:aaec057956ca | 10 | /*DigitalOut LED_R(D7,1); |
JohnnyK | 0:aaec057956ca | 11 | DigitalOut LED_G(D8,1); |
JohnnyK | 0:aaec057956ca | 12 | DigitalOut LED_B(D9,1);*/ |
JohnnyK | 0:aaec057956ca | 13 | |
JohnnyK | 0:aaec057956ca | 14 | |
JohnnyK | 0:aaec057956ca | 15 | /* !!!Change pins according to your connection!!! */ |
JohnnyK | 0:aaec057956ca | 16 | BufferedSerial uart(D8,D2, 115200); // UART TX, RX |
JohnnyK | 0:aaec057956ca | 17 | ATCmdParser module(&uart,"\r\n"); |
JohnnyK | 0:aaec057956ca | 18 | |
JohnnyK | 0:aaec057956ca | 19 | // init the module |
JohnnyK | 0:aaec057956ca | 20 | bool ModulePowerOn() { |
JohnnyK | 0:aaec057956ca | 21 | int i=0; |
JohnnyK | 0:aaec057956ca | 22 | bool result = false; |
JohnnyK | 0:aaec057956ca | 23 | RST_KEY = 0; |
JohnnyK | 0:aaec057956ca | 24 | thread_sleep_for(3000); |
JohnnyK | 0:aaec057956ca | 25 | RST_KEY = 1; |
JohnnyK | 0:aaec057956ca | 26 | thread_sleep_for(15000); |
JohnnyK | 0:aaec057956ca | 27 | |
JohnnyK | 0:aaec057956ca | 28 | result = module.recv("OK"); |
JohnnyK | 0:aaec057956ca | 29 | if(!result){ |
JohnnyK | 0:aaec057956ca | 30 | for(i=0;i<10;i++){ |
JohnnyK | 0:aaec057956ca | 31 | module.send("AT"); |
JohnnyK | 0:aaec057956ca | 32 | thread_sleep_for(500); |
JohnnyK | 0:aaec057956ca | 33 | result = module.recv("OK"); |
JohnnyK | 0:aaec057956ca | 34 | if(result){ |
JohnnyK | 0:aaec057956ca | 35 | break; |
JohnnyK | 0:aaec057956ca | 36 | } |
JohnnyK | 0:aaec057956ca | 37 | } |
JohnnyK | 0:aaec057956ca | 38 | } |
JohnnyK | 0:aaec057956ca | 39 | return result; |
JohnnyK | 0:aaec057956ca | 40 | } |
JohnnyK | 0:aaec057956ca | 41 | |
JohnnyK | 0:aaec057956ca | 42 | // setup |
JohnnyK | 0:aaec057956ca | 43 | int main() { |
JohnnyK | 0:aaec057956ca | 44 | |
JohnnyK | 0:aaec057956ca | 45 | printf("Mbed A9G test\n"); |
JohnnyK | 0:aaec057956ca | 46 | module.debug_on(true); |
JohnnyK | 0:aaec057956ca | 47 | if(ModulePowerOn()){ |
JohnnyK | 0:aaec057956ca | 48 | printf("Module is up!\n"); |
JohnnyK | 0:aaec057956ca | 49 | } else { |
JohnnyK | 0:aaec057956ca | 50 | printf("No communication with module!\n"); |
JohnnyK | 0:aaec057956ca | 51 | } |
JohnnyK | 0:aaec057956ca | 52 | |
JohnnyK | 0:aaec057956ca | 53 | // loop |
JohnnyK | 0:aaec057956ca | 54 | while(true) |
JohnnyK | 0:aaec057956ca | 55 | { |
JohnnyK | 0:aaec057956ca | 56 | //do something in loop |
JohnnyK | 0:aaec057956ca | 57 | thread_sleep_for(1000); |
JohnnyK | 0:aaec057956ca | 58 | } |
JohnnyK | 0:aaec057956ca | 59 | } |