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.
Fork of Arch_GPRS_V2_Serial_Debug by
main.cpp@1:ba5061c882ea, 2014-04-28 (annotated)
- Committer:
- lawliet
- Date:
- Mon Apr 28 01:56:27 2014 +0000
- Revision:
- 1:ba5061c882ea
- Parent:
- 0:38b190020352
Version 1.0 (update the power up function)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:38b190020352 | 1 | /* |
lawliet | 0:38b190020352 | 2 | main.cpp |
lawliet | 0:38b190020352 | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 0:38b190020352 | 4 | |
lawliet | 0:38b190020352 | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
lawliet | 0:38b190020352 | 6 | 2014-4-26 |
lawliet | 0:38b190020352 | 7 | |
lawliet | 0:38b190020352 | 8 | This library is free software; you can redistribute it and/or |
lawliet | 0:38b190020352 | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 0:38b190020352 | 10 | License as published by the Free Software Foundation; either |
lawliet | 0:38b190020352 | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 0:38b190020352 | 12 | |
lawliet | 0:38b190020352 | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 0:38b190020352 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 0:38b190020352 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 0:38b190020352 | 16 | Lesser General Public License for more details. |
lawliet | 0:38b190020352 | 17 | |
lawliet | 0:38b190020352 | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 0:38b190020352 | 19 | License along with this library; if not, write to the Free Software |
lawliet | 0:38b190020352 | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 0:38b190020352 | 21 | */ |
lawliet | 0:38b190020352 | 22 | |
lawliet | 0:38b190020352 | 23 | #include "mbed.h" |
lawliet | 0:38b190020352 | 24 | #include "USBSerial.h" |
lawliet | 0:38b190020352 | 25 | |
lawliet | 0:38b190020352 | 26 | #define PIN_PWR P1_2 //power up gprs module |
lawliet | 1:ba5061c882ea | 27 | #define PIN_PWR_KEY P1_7 |
lawliet | 0:38b190020352 | 28 | #define PIN_TX P1_27 //Serial tx pin |
lawliet | 0:38b190020352 | 29 | #define PIN_RX P1_26 //Serial rx pin |
lawliet | 0:38b190020352 | 30 | |
lawliet | 0:38b190020352 | 31 | DigitalOut power(PIN_PWR); |
lawliet | 1:ba5061c882ea | 32 | DigitalOut powerKey(PIN_PWR_KEY); |
lawliet | 0:38b190020352 | 33 | Serial gprs(PIN_TX, PIN_RX); |
lawliet | 0:38b190020352 | 34 | USBSerial pc; |
lawliet | 0:38b190020352 | 35 | |
lawliet | 0:38b190020352 | 36 | // Called by ISR |
lawliet | 0:38b190020352 | 37 | void settingsChanged(int baud, int bits, int parity, int stop) |
lawliet | 0:38b190020352 | 38 | { |
lawliet | 0:38b190020352 | 39 | const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1}; |
lawliet | 0:38b190020352 | 40 | |
lawliet | 0:38b190020352 | 41 | if (stop != 2) { |
lawliet | 0:38b190020352 | 42 | stop = 1; // stop bit(s) = 1 or 1.5 |
lawliet | 0:38b190020352 | 43 | } |
lawliet | 0:38b190020352 | 44 | |
lawliet | 0:38b190020352 | 45 | gprs.baud(baud); |
lawliet | 0:38b190020352 | 46 | gprs.format(bits, parityTable[parity], stop); |
lawliet | 0:38b190020352 | 47 | } |
lawliet | 0:38b190020352 | 48 | |
lawliet | 1:ba5061c882ea | 49 | /* power pin: low enable |
lawliet | 1:ba5061c882ea | 50 | ___ |
lawliet | 1:ba5061c882ea | 51 | |___ |
lawliet | 1:ba5061c882ea | 52 | |
lawliet | 1:ba5061c882ea | 53 | powerKey pin: you can also power up by long press the powerKey. |
lawliet | 1:ba5061c882ea | 54 | |
lawliet | 1:ba5061c882ea | 55 | ___ |
lawliet | 1:ba5061c882ea | 56 | ___| |___ |
lawliet | 1:ba5061c882ea | 57 | |
lawliet | 1:ba5061c882ea | 58 | */ |
lawliet | 0:38b190020352 | 59 | void gprsPowerUp(void) |
lawliet | 0:38b190020352 | 60 | { |
lawliet | 1:ba5061c882ea | 61 | power = 1; |
lawliet | 1:ba5061c882ea | 62 | wait(2); |
lawliet | 0:38b190020352 | 63 | power = 0; |
lawliet | 1:ba5061c882ea | 64 | wait(2); |
lawliet | 1:ba5061c882ea | 65 | |
lawliet | 1:ba5061c882ea | 66 | powerKey = 0; |
lawliet | 1:ba5061c882ea | 67 | wait(1); |
lawliet | 1:ba5061c882ea | 68 | powerKey = 1; |
lawliet | 1:ba5061c882ea | 69 | wait(2); |
lawliet | 1:ba5061c882ea | 70 | powerKey = 0; |
lawliet | 1:ba5061c882ea | 71 | wait(3); |
lawliet | 1:ba5061c882ea | 72 | |
lawliet | 0:38b190020352 | 73 | } |
lawliet | 0:38b190020352 | 74 | |
lawliet | 0:38b190020352 | 75 | int main() |
lawliet | 0:38b190020352 | 76 | { |
lawliet | 1:ba5061c882ea | 77 | pc.attach(settingsChanged); |
lawliet | 1:ba5061c882ea | 78 | pc.printf("wait for GPRS power up..."); |
lawliet | 0:38b190020352 | 79 | gprsPowerUp(); |
lawliet | 1:ba5061c882ea | 80 | pc.printf("gprs Power up success\n"); |
lawliet | 0:38b190020352 | 81 | |
lawliet | 0:38b190020352 | 82 | while (1) { |
lawliet | 0:38b190020352 | 83 | while (gprs.readable()) { |
lawliet | 0:38b190020352 | 84 | pc.putc(gprs.getc()); |
lawliet | 0:38b190020352 | 85 | } |
lawliet | 0:38b190020352 | 86 | |
lawliet | 0:38b190020352 | 87 | while (pc.readable()) { |
lawliet | 0:38b190020352 | 88 | gprs.putc(pc.getc()); |
lawliet | 0:38b190020352 | 89 | } |
lawliet | 0:38b190020352 | 90 | } |
lawliet | 0:38b190020352 | 91 | } |