Example program demonstrate the use of the User LEDs and the User Button. The example also initializes the I2C3 Bus for the battery charger BQ24295, sets the battery charger and the cellular module driver, powers up the cellular module. However, the UART2 , which is used for communicating with the module, is not configured. Hence, the Serial USB Sniffer could be used for exercising AT commands from a development PC.

Dependencies:   ublox-cellular-base ublox-cellular-driver-gen battery-charger-bq24295 gnss

Committer:
Mudassar Hussain
Date:
Fri Feb 23 18:26:53 2018 +0500
Revision:
5:8f44dab9cb6b
Parent:
3:b9051f3f2fcd
Child:
6:4d61a0f32573
Removed unused libraries and variables

Who changed what in which revision?

UserRevisionLine numberNew contents of line
euygun 0:25fcf12b0ba2 1 /* mbed Microcontroller Library
euygun 0:25fcf12b0ba2 2 * Copyright (c) 2017 u-blox
euygun 0:25fcf12b0ba2 3 *
euygun 0:25fcf12b0ba2 4 * Licensed under the Apache License, Version 2.0 (the "License");
euygun 0:25fcf12b0ba2 5 * you may not use this file except in compliance with the License.
euygun 0:25fcf12b0ba2 6 * You may obtain a copy of the License at
euygun 0:25fcf12b0ba2 7 *
euygun 0:25fcf12b0ba2 8 * http://www.apache.org/licenses/LICENSE-2.0
euygun 0:25fcf12b0ba2 9 *
euygun 0:25fcf12b0ba2 10 * Unless required by applicable law or agreed to in writing, software
euygun 0:25fcf12b0ba2 11 * distributed under the License is distributed on an "AS IS" BASIS,
euygun 0:25fcf12b0ba2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
euygun 0:25fcf12b0ba2 13 * See the License for the specific language governing permissions and
euygun 0:25fcf12b0ba2 14 * limitations under the License.
euygun 0:25fcf12b0ba2 15 */
euygun 0:25fcf12b0ba2 16
euygun 0:25fcf12b0ba2 17 #include "mbed.h"
euygun 3:b9051f3f2fcd 18 #include "gnss.h"
euygun 2:c95852ac6953 19 #include "battery_charger_bq24295.h"
euygun 0:25fcf12b0ba2 20 #include "onboard_modem_api.h"
euygun 0:25fcf12b0ba2 21
euygun 2:c95852ac6953 22 // Set the minimum input voltage limit for the BQ24295 to 3.8 Volt
euygun 2:c95852ac6953 23 #define MIN_INPUT_VOLTAGE_LIMIT_MV 3880
euygun 2:c95852ac6953 24
euygun 0:25fcf12b0ba2 25 // User LEDs
euygun 0:25fcf12b0ba2 26 DigitalOut ledRed(LED1, 1);
euygun 0:25fcf12b0ba2 27 DigitalOut ledGreen(LED2, 1);
euygun 0:25fcf12b0ba2 28 DigitalOut ledBlue(LED3, 1);
euygun 0:25fcf12b0ba2 29
euygun 3:b9051f3f2fcd 30 //GNSS 1V8_MAX IO power
euygun 3:b9051f3f2fcd 31 DigitalOut GNSSOn(GNSSEN, 1);
euygun 3:b9051f3f2fcd 32
euygun 0:25fcf12b0ba2 33 // Ethernet socket LED
euygun 0:25fcf12b0ba2 34 DigitalOut ledYellow(LED4,1);
euygun 0:25fcf12b0ba2 35
euygun 0:25fcf12b0ba2 36 // User Button
euygun 0:25fcf12b0ba2 37 #ifdef TARGET_UBLOX_C027
euygun 0:25fcf12b0ba2 38 // No user button on C027
euygun 0:25fcf12b0ba2 39 InterruptIn userButton(NC);
euygun 0:25fcf12b0ba2 40 #else
euygun 0:25fcf12b0ba2 41 InterruptIn userButton(SW0);
euygun 0:25fcf12b0ba2 42 #endif
euygun 0:25fcf12b0ba2 43
euygun 3:b9051f3f2fcd 44 // GNSS
euygun 3:b9051f3f2fcd 45 GnssSerial gnss;
euygun 3:b9051f3f2fcd 46
euygun 2:c95852ac6953 47 // i2c3 Bus
euygun 2:c95852ac6953 48 I2C i2c3(I2C_SDA_B, I2C_SCL_B);
euygun 2:c95852ac6953 49
euygun 2:c95852ac6953 50 // Battery Charger BQ24295
euygun 2:c95852ac6953 51 BatteryChargerBq24295 charger;
euygun 2:c95852ac6953 52
euygun 0:25fcf12b0ba2 53 // Delay between LED changes in second
euygun 0:25fcf12b0ba2 54 volatile float delay = 0.5;
euygun 0:25fcf12b0ba2 55
euygun 1:e11c75d931b5 56 // To check if the user pressed the User Button or not
euygun 0:25fcf12b0ba2 57 void threadBodyUserButtonCheck(void const *args){
euygun 0:25fcf12b0ba2 58 while (1){
euygun 0:25fcf12b0ba2 59 if (userButton.read() == 1 ) {
euygun 1:e11c75d931b5 60 // User Button is pressed
euygun 0:25fcf12b0ba2 61 delay = 0.1;
euygun 0:25fcf12b0ba2 62 //Indicate the button is pressed
euygun 0:25fcf12b0ba2 63 ledYellow = 0;
euygun 0:25fcf12b0ba2 64 }
euygun 0:25fcf12b0ba2 65 else {
euygun 1:e11c75d931b5 66 // User button is released
euygun 0:25fcf12b0ba2 67 delay = 0.5;
euygun 0:25fcf12b0ba2 68 //Turn off the Yellow LED on Ethernet socket
euygun 0:25fcf12b0ba2 69 ledYellow = 1;
euygun 0:25fcf12b0ba2 70 }
euygun 0:25fcf12b0ba2 71 }
euygun 0:25fcf12b0ba2 72 }
euygun 0:25fcf12b0ba2 73
euygun 0:25fcf12b0ba2 74 /*
euygun 0:25fcf12b0ba2 75 ** Out of the Box Demo for C030 variants
euygun 0:25fcf12b0ba2 76 **
euygun 0:25fcf12b0ba2 77 ** Sets the modem then
euygun 0:25fcf12b0ba2 78 */
euygun 0:25fcf12b0ba2 79
euygun 0:25fcf12b0ba2 80 int main()
euygun 0:25fcf12b0ba2 81 {
euygun 3:b9051f3f2fcd 82 printf("u-blox C030 Out-of-the-Box Demo\n\r");
euygun 3:b9051f3f2fcd 83
euygun 3:b9051f3f2fcd 84 // GNSS initialisation
euygun 3:b9051f3f2fcd 85 if(gnss.init()) {
euygun 3:b9051f3f2fcd 86 printf("GNSS initialised.\n\r");
euygun 3:b9051f3f2fcd 87 }
euygun 3:b9051f3f2fcd 88 else {
euygun 3:b9051f3f2fcd 89 printf("GNSS initialisation failure.\n\r");
euygun 3:b9051f3f2fcd 90 }
euygun 3:b9051f3f2fcd 91
euygun 2:c95852ac6953 92 // The battery charger initialisation
euygun 2:c95852ac6953 93 charger.init(&i2c3);
euygun 2:c95852ac6953 94 charger.setInputVoltageLimit(MIN_INPUT_VOLTAGE_LIMIT_MV);
euygun 2:c95852ac6953 95 // Disable the battery charger's watchdog, otherwise it resets the battry charger
euygun 2:c95852ac6953 96 charger.setWatchdog(0);
euygun 2:c95852ac6953 97
euygun 1:e11c75d931b5 98 // Initialised the modem
euygun 0:25fcf12b0ba2 99 onboard_modem_init();
euygun 0:25fcf12b0ba2 100
euygun 1:e11c75d931b5 101 // Power up the modem
euygun 0:25fcf12b0ba2 102 onboard_modem_power_up();
euygun 0:25fcf12b0ba2 103
euygun 1:e11c75d931b5 104 // Create threadUserButtonCheck thread
euygun 0:25fcf12b0ba2 105 Thread threadUserButtonCheck(threadBodyUserButtonCheck);
euygun 0:25fcf12b0ba2 106
euygun 3:b9051f3f2fcd 107
euygun 3:b9051f3f2fcd 108 //Set GNSS IO On
euygun 3:b9051f3f2fcd 109 GNSSOn = 1;
euygun 3:b9051f3f2fcd 110
euygun 1:e11c75d931b5 111 // Set the LED states
euygun 0:25fcf12b0ba2 112 ledRed = 0;
euygun 0:25fcf12b0ba2 113 ledGreen = 1;
euygun 0:25fcf12b0ba2 114 ledBlue = 1;
euygun 0:25fcf12b0ba2 115
euygun 3:b9051f3f2fcd 116 printf("u-blox C030 Out-of-the-Box Demo: LED loop\n\r");
euygun 0:25fcf12b0ba2 117
euygun 0:25fcf12b0ba2 118 //Main loop
euygun 0:25fcf12b0ba2 119 while(1) {
euygun 0:25fcf12b0ba2 120 wait(delay);
euygun 0:25fcf12b0ba2 121 //Shift the LED states
euygun 0:25fcf12b0ba2 122 int carry = ledBlue;
euygun 0:25fcf12b0ba2 123 ledBlue = ledRed;
euygun 0:25fcf12b0ba2 124 ledRed = ledGreen;
euygun 0:25fcf12b0ba2 125 ledGreen = carry;
euygun 0:25fcf12b0ba2 126 }
euygun 0:25fcf12b0ba2 127 }
euygun 0:25fcf12b0ba2 128
euygun 0:25fcf12b0ba2 129 // End Of File