Cellular module AT Serial interface passthrough to Debug COM port. This program can be used on the C030 boards excluding the C030 N2xx version.

Committer:
fahimalavi
Date:
Fri Aug 30 14:09:29 2019 +0500
Revision:
6:886ffd0f05fd
Parent:
1:f39e92fcdf5e
removing mbed-os folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
euygun 0:fd90bb768e20 1 /* mbed Microcontroller Library
euygun 0:fd90bb768e20 2 * Copyright (c) 2017 u-blox
euygun 0:fd90bb768e20 3 *
euygun 0:fd90bb768e20 4 * Licensed under the Apache License, Version 2.0 (the "License");
euygun 0:fd90bb768e20 5 * you may not use this file except in compliance with the License.
euygun 0:fd90bb768e20 6 * You may obtain a copy of the License at
euygun 0:fd90bb768e20 7 *
euygun 0:fd90bb768e20 8 * http://www.apache.org/licenses/LICENSE-2.0
euygun 0:fd90bb768e20 9 *
euygun 0:fd90bb768e20 10 * Unless required by applicable law or agreed to in writing, software
euygun 0:fd90bb768e20 11 * distributed under the License is distributed on an "AS IS" BASIS,
euygun 0:fd90bb768e20 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
euygun 0:fd90bb768e20 13 * See the License for the specific language governing permissions and
euygun 0:fd90bb768e20 14 * limitations under the License.
euygun 0:fd90bb768e20 15 */
euygun 0:fd90bb768e20 16
mudassar0121 1:f39e92fcdf5e 17 /* The example program for the u-blox C030 boards. It sets up
mudassar0121 1:f39e92fcdf5e 18 * - the GNSS module for automatic fix
mudassar0121 1:f39e92fcdf5e 19 * - the I2C3 Bus to access bq27441 Battery Charger
mudassar0121 1:f39e92fcdf5e 20 * - the bq27441 Battery Charger.
mudassar0121 1:f39e92fcdf5e 21 *
mudassar0121 1:f39e92fcdf5e 22 */
mudassar0121 1:f39e92fcdf5e 23
euygun 0:fd90bb768e20 24 #include "mbed.h"
euygun 0:fd90bb768e20 25 #include "gnss.h"
mudassar0121 1:f39e92fcdf5e 26 #include "battery_gauge_bq27441.h"
euygun 0:fd90bb768e20 27 #include "UbloxCellularDriverGen.h"
euygun 0:fd90bb768e20 28 #include "onboard_modem_api.h"
euygun 0:fd90bb768e20 29
mudassar0121 1:f39e92fcdf5e 30 // Set the Baudrate for mcu(pc) and modem(dev)
mudassar0121 1:f39e92fcdf5e 31 #define BAUDRATE 115200
mudassar0121 1:f39e92fcdf5e 32
mudassar0121 1:f39e92fcdf5e 33 // Set the minimum input voltage limit for the bq27441 to 3.8 Volt
euygun 0:fd90bb768e20 34 #define MIN_INPUT_VOLTAGE_LIMIT_MV 3880
euygun 0:fd90bb768e20 35
euygun 0:fd90bb768e20 36
euygun 0:fd90bb768e20 37 // User LEDs
euygun 0:fd90bb768e20 38 DigitalOut ledRed(LED1, 1);
euygun 0:fd90bb768e20 39 DigitalOut ledGreen(LED2, 1);
euygun 0:fd90bb768e20 40 DigitalOut ledBlue(LED3, 1);
euygun 0:fd90bb768e20 41
euygun 0:fd90bb768e20 42 // Ethernet socket LED
euygun 0:fd90bb768e20 43 DigitalOut ledYellow(LED4,1);
euygun 0:fd90bb768e20 44
euygun 0:fd90bb768e20 45 // User Button
euygun 0:fd90bb768e20 46 #ifdef TARGET_UBLOX_C027
euygun 0:fd90bb768e20 47 // No user button on C027
euygun 0:fd90bb768e20 48 InterruptIn userButton(NC);
euygun 0:fd90bb768e20 49 #else
euygun 0:fd90bb768e20 50 InterruptIn userButton(SW0);
euygun 0:fd90bb768e20 51 #endif
euygun 0:fd90bb768e20 52
euygun 0:fd90bb768e20 53 // GNSS
euygun 0:fd90bb768e20 54 GnssSerial gnss;
euygun 0:fd90bb768e20 55
euygun 0:fd90bb768e20 56 // i2c3 Bus
euygun 0:fd90bb768e20 57 I2C i2c3(I2C_SDA_B, I2C_SCL_B);
euygun 0:fd90bb768e20 58
mudassar0121 1:f39e92fcdf5e 59 // Battery Charger bq27441
mudassar0121 1:f39e92fcdf5e 60 BatteryGaugeBq27441 charger;
mudassar0121 1:f39e92fcdf5e 61
mudassar0121 1:f39e92fcdf5e 62 RawSerial pc(PD_5, PD_6);
mudassar0121 1:f39e92fcdf5e 63 RawSerial dev(PA_9, PA_10);
euygun 0:fd90bb768e20 64
euygun 0:fd90bb768e20 65 // Delay between LED changes in second
euygun 0:fd90bb768e20 66 volatile float delay = 0.5;
euygun 0:fd90bb768e20 67
euygun 0:fd90bb768e20 68 // To check if the user pressed the User Button or not
euygun 0:fd90bb768e20 69 void threadBodyUserButtonCheck(void const *args){
euygun 0:fd90bb768e20 70 float delayToggle = delay;
euygun 0:fd90bb768e20 71 while (1){
euygun 0:fd90bb768e20 72 if (userButton.read() == 1 ) {
euygun 0:fd90bb768e20 73 // User Button is pressed
euygun 0:fd90bb768e20 74 delay = 0.1;
euygun 0:fd90bb768e20 75 // Indicate with the Yellow LED on Ethernet socket
euygun 0:fd90bb768e20 76 ledYellow = 0;
euygun 0:fd90bb768e20 77 }
euygun 0:fd90bb768e20 78 else {
euygun 0:fd90bb768e20 79 // User button is released
euygun 0:fd90bb768e20 80 delay = 0.5;
euygun 0:fd90bb768e20 81 // Turn off the Yellow LED on Ethernet socket
euygun 0:fd90bb768e20 82 ledYellow = 1;
euygun 0:fd90bb768e20 83 }
euygun 0:fd90bb768e20 84 }
euygun 0:fd90bb768e20 85 }
euygun 0:fd90bb768e20 86
euygun 0:fd90bb768e20 87 void dev_recv()
euygun 0:fd90bb768e20 88 {
euygun 0:fd90bb768e20 89 while(dev.readable()) {
euygun 0:fd90bb768e20 90 pc.putc(dev.getc());
euygun 0:fd90bb768e20 91 }
euygun 0:fd90bb768e20 92 }
euygun 0:fd90bb768e20 93
euygun 0:fd90bb768e20 94 void pc_recv()
euygun 0:fd90bb768e20 95 {
euygun 0:fd90bb768e20 96 while(pc.readable()) {
euygun 0:fd90bb768e20 97 dev.putc(pc.getc());
euygun 0:fd90bb768e20 98 }
euygun 0:fd90bb768e20 99 }
mudassar0121 1:f39e92fcdf5e 100
euygun 0:fd90bb768e20 101 /*
euygun 0:fd90bb768e20 102 ** Out of the Box Demo for C030 variants
euygun 0:fd90bb768e20 103 **
euygun 0:fd90bb768e20 104 */
euygun 0:fd90bb768e20 105 int main()
euygun 0:fd90bb768e20 106 {
euygun 0:fd90bb768e20 107 printf("u-blox C030-R410M Bring-up baseline using Out-of-the-Box Demo\n\r");
euygun 0:fd90bb768e20 108
euygun 0:fd90bb768e20 109 // GNSS initialisation
euygun 0:fd90bb768e20 110 if(gnss.init()) {
mudassar0121 1:f39e92fcdf5e 111 printf("GNSS initialized.\n\r");
euygun 0:fd90bb768e20 112 }
euygun 0:fd90bb768e20 113 else {
mudassar0121 1:f39e92fcdf5e 114 printf("GNSS initialization failure.\n\r");
euygun 0:fd90bb768e20 115 }
euygun 0:fd90bb768e20 116
euygun 0:fd90bb768e20 117 // The battery charger initialisation
euygun 0:fd90bb768e20 118 if(charger.init(&i2c3)) {
mudassar0121 1:f39e92fcdf5e 119 printf("Battery charger initialized.\n\r");
euygun 0:fd90bb768e20 120 }
euygun 0:fd90bb768e20 121 else {
mudassar0121 1:f39e92fcdf5e 122 printf("Battery charger initialization failure.\n\r");
euygun 0:fd90bb768e20 123 }
euygun 0:fd90bb768e20 124 printf("\n\r");
euygun 0:fd90bb768e20 125
euygun 0:fd90bb768e20 126 // The modem initialisation
euygun 0:fd90bb768e20 127 onboard_modem_init();
euygun 0:fd90bb768e20 128
euygun 0:fd90bb768e20 129 // Power up the modem
euygun 0:fd90bb768e20 130 onboard_modem_power_up();
euygun 0:fd90bb768e20 131
euygun 0:fd90bb768e20 132 // Create threadUserButtonCheck thread
euygun 0:fd90bb768e20 133 Thread threadUserButtonCheck(threadBodyUserButtonCheck);
euygun 0:fd90bb768e20 134
euygun 0:fd90bb768e20 135 // Set the LED states
euygun 0:fd90bb768e20 136 ledRed = 0;
euygun 0:fd90bb768e20 137 ledGreen = 1;
euygun 0:fd90bb768e20 138 ledBlue = 1;
euygun 0:fd90bb768e20 139
mudassar0121 1:f39e92fcdf5e 140 pc.baud(BAUDRATE);
mudassar0121 1:f39e92fcdf5e 141 dev.baud(BAUDRATE);
euygun 0:fd90bb768e20 142
euygun 0:fd90bb768e20 143 pc.attach(&pc_recv, Serial::RxIrq);
euygun 0:fd90bb768e20 144 dev.attach(&dev_recv, Serial::RxIrq);
euygun 0:fd90bb768e20 145
euygun 0:fd90bb768e20 146 // Main loop
euygun 0:fd90bb768e20 147 while(1) {
euygun 0:fd90bb768e20 148 wait(delay);
euygun 0:fd90bb768e20 149 // Shift the LED states
euygun 0:fd90bb768e20 150 int carry = ledBlue;
euygun 0:fd90bb768e20 151 ledBlue = ledRed;
euygun 0:fd90bb768e20 152 ledRed = ledGreen;
euygun 0:fd90bb768e20 153 ledGreen = carry;
euygun 0:fd90bb768e20 154 }
euygun 0:fd90bb768e20 155 }
euygun 0:fd90bb768e20 156
mudassar0121 1:f39e92fcdf5e 157 // End Of File
mudassar0121 1:f39e92fcdf5e 158