This is a demo code for ARCH GPRS 2.0 Serial debug

Dependencies:   USBDevice mbed

Fork of Arch_GPRS_V2_Serial_Debug by wei zou

Committer:
lawliet
Date:
Sat Apr 26 12:46:40 2014 +0000
Revision:
0:38b190020352
Child:
1:ba5061c882ea
Initial Version

Who changed what in which revision?

UserRevisionLine numberNew 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 0:38b190020352 27 #define PIN_TX P1_27 //Serial tx pin
lawliet 0:38b190020352 28 #define PIN_RX P1_26 //Serial rx pin
lawliet 0:38b190020352 29
lawliet 0:38b190020352 30 DigitalOut power(PIN_PWR);
lawliet 0:38b190020352 31 Serial gprs(PIN_TX, PIN_RX);
lawliet 0:38b190020352 32 USBSerial pc;
lawliet 0:38b190020352 33
lawliet 0:38b190020352 34 // Called by ISR
lawliet 0:38b190020352 35 void settingsChanged(int baud, int bits, int parity, int stop)
lawliet 0:38b190020352 36 {
lawliet 0:38b190020352 37 const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1};
lawliet 0:38b190020352 38
lawliet 0:38b190020352 39 if (stop != 2) {
lawliet 0:38b190020352 40 stop = 1; // stop bit(s) = 1 or 1.5
lawliet 0:38b190020352 41 }
lawliet 0:38b190020352 42
lawliet 0:38b190020352 43 gprs.baud(baud);
lawliet 0:38b190020352 44 gprs.format(bits, parityTable[parity], stop);
lawliet 0:38b190020352 45 }
lawliet 0:38b190020352 46
lawliet 0:38b190020352 47 void gprsPowerUp(void)
lawliet 0:38b190020352 48 {
lawliet 0:38b190020352 49 power = 0;
lawliet 0:38b190020352 50 }
lawliet 0:38b190020352 51
lawliet 0:38b190020352 52 int main()
lawliet 0:38b190020352 53 {
lawliet 0:38b190020352 54 gprsPowerUp();
lawliet 0:38b190020352 55 wait(2);
lawliet 0:38b190020352 56
lawliet 0:38b190020352 57 pc.attach(settingsChanged);
lawliet 0:38b190020352 58
lawliet 0:38b190020352 59 while (1) {
lawliet 0:38b190020352 60 while (gprs.readable()) {
lawliet 0:38b190020352 61 pc.putc(gprs.getc());
lawliet 0:38b190020352 62 }
lawliet 0:38b190020352 63
lawliet 0:38b190020352 64 while (pc.readable()) {
lawliet 0:38b190020352 65 gprs.putc(pc.getc());
lawliet 0:38b190020352 66 }
lawliet 0:38b190020352 67 }
lawliet 0:38b190020352 68 }