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:
euygun
Date:
Wed Jan 10 17:03:44 2018 +0000
Revision:
3:b9051f3f2fcd
Parent:
2:c95852ac6953
Child:
5:8f44dab9cb6b
Added GNSS support and initialisation

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 "UbloxCellularDriverGen.h"
euygun 0:25fcf12b0ba2 21 #include "onboard_modem_api.h"
euygun 0:25fcf12b0ba2 22
euygun 2:c95852ac6953 23 // Set the minimum input voltage limit for the BQ24295 to 3.8 Volt
euygun 2:c95852ac6953 24 #define MIN_INPUT_VOLTAGE_LIMIT_MV 3880
euygun 2:c95852ac6953 25
euygun 0:25fcf12b0ba2 26 // User LEDs
euygun 0:25fcf12b0ba2 27 DigitalOut ledRed(LED1, 1);
euygun 0:25fcf12b0ba2 28 DigitalOut ledGreen(LED2, 1);
euygun 0:25fcf12b0ba2 29 DigitalOut ledBlue(LED3, 1);
euygun 0:25fcf12b0ba2 30
euygun 3:b9051f3f2fcd 31 //GNSS 1V8_MAX IO power
euygun 3:b9051f3f2fcd 32 DigitalOut GNSSOn(GNSSEN, 1);
euygun 3:b9051f3f2fcd 33
euygun 0:25fcf12b0ba2 34 // Ethernet socket LED
euygun 0:25fcf12b0ba2 35 DigitalOut ledYellow(LED4,1);
euygun 0:25fcf12b0ba2 36
euygun 0:25fcf12b0ba2 37 // User Button
euygun 0:25fcf12b0ba2 38 #ifdef TARGET_UBLOX_C027
euygun 0:25fcf12b0ba2 39 // No user button on C027
euygun 0:25fcf12b0ba2 40 InterruptIn userButton(NC);
euygun 0:25fcf12b0ba2 41 #else
euygun 0:25fcf12b0ba2 42 InterruptIn userButton(SW0);
euygun 0:25fcf12b0ba2 43 #endif
euygun 0:25fcf12b0ba2 44
euygun 3:b9051f3f2fcd 45 // GNSS
euygun 3:b9051f3f2fcd 46 GnssSerial gnss;
euygun 3:b9051f3f2fcd 47
euygun 2:c95852ac6953 48 // i2c3 Bus
euygun 2:c95852ac6953 49 I2C i2c3(I2C_SDA_B, I2C_SCL_B);
euygun 2:c95852ac6953 50
euygun 2:c95852ac6953 51 // Battery Charger BQ24295
euygun 2:c95852ac6953 52 BatteryChargerBq24295 charger;
euygun 2:c95852ac6953 53
euygun 0:25fcf12b0ba2 54 // Delay between LED changes in second
euygun 0:25fcf12b0ba2 55 volatile float delay = 0.5;
euygun 0:25fcf12b0ba2 56
euygun 1:e11c75d931b5 57 // To check if the user pressed the User Button or not
euygun 0:25fcf12b0ba2 58 void threadBodyUserButtonCheck(void const *args){
euygun 0:25fcf12b0ba2 59 float delayToggle = delay;
euygun 0:25fcf12b0ba2 60 while (1){
euygun 0:25fcf12b0ba2 61 if (userButton.read() == 1 ) {
euygun 1:e11c75d931b5 62 // User Button is pressed
euygun 0:25fcf12b0ba2 63 delay = 0.1;
euygun 0:25fcf12b0ba2 64 //Indicate the button is pressed
euygun 0:25fcf12b0ba2 65 ledYellow = 0;
euygun 0:25fcf12b0ba2 66 }
euygun 0:25fcf12b0ba2 67 else {
euygun 1:e11c75d931b5 68 // User button is released
euygun 0:25fcf12b0ba2 69 delay = 0.5;
euygun 0:25fcf12b0ba2 70 //Turn off the Yellow LED on Ethernet socket
euygun 0:25fcf12b0ba2 71 ledYellow = 1;
euygun 0:25fcf12b0ba2 72 }
euygun 0:25fcf12b0ba2 73 }
euygun 0:25fcf12b0ba2 74 }
euygun 0:25fcf12b0ba2 75
euygun 0:25fcf12b0ba2 76 /*
euygun 0:25fcf12b0ba2 77 ** Out of the Box Demo for C030 variants
euygun 0:25fcf12b0ba2 78 **
euygun 0:25fcf12b0ba2 79 ** Sets the modem then
euygun 0:25fcf12b0ba2 80 */
euygun 0:25fcf12b0ba2 81
euygun 0:25fcf12b0ba2 82 int main()
euygun 0:25fcf12b0ba2 83 {
euygun 3:b9051f3f2fcd 84 printf("u-blox C030 Out-of-the-Box Demo\n\r");
euygun 3:b9051f3f2fcd 85
euygun 3:b9051f3f2fcd 86 // GNSS initialisation
euygun 3:b9051f3f2fcd 87 if(gnss.init()) {
euygun 3:b9051f3f2fcd 88 printf("GNSS initialised.\n\r");
euygun 3:b9051f3f2fcd 89 }
euygun 3:b9051f3f2fcd 90 else {
euygun 3:b9051f3f2fcd 91 printf("GNSS initialisation failure.\n\r");
euygun 3:b9051f3f2fcd 92 }
euygun 3:b9051f3f2fcd 93
euygun 2:c95852ac6953 94 // The battery charger initialisation
euygun 2:c95852ac6953 95 charger.init(&i2c3);
euygun 2:c95852ac6953 96 charger.setInputVoltageLimit(MIN_INPUT_VOLTAGE_LIMIT_MV);
euygun 2:c95852ac6953 97 // Disable the battery charger's watchdog, otherwise it resets the battry charger
euygun 2:c95852ac6953 98 charger.setWatchdog(0);
euygun 2:c95852ac6953 99
euygun 1:e11c75d931b5 100 // Initialised the modem
euygun 0:25fcf12b0ba2 101 onboard_modem_init();
euygun 0:25fcf12b0ba2 102
euygun 1:e11c75d931b5 103 // Power up the modem
euygun 0:25fcf12b0ba2 104 onboard_modem_power_up();
euygun 0:25fcf12b0ba2 105
euygun 1:e11c75d931b5 106 // Create threadUserButtonCheck thread
euygun 0:25fcf12b0ba2 107 Thread threadUserButtonCheck(threadBodyUserButtonCheck);
euygun 0:25fcf12b0ba2 108
euygun 3:b9051f3f2fcd 109
euygun 3:b9051f3f2fcd 110 //Set GNSS IO On
euygun 3:b9051f3f2fcd 111 GNSSOn = 1;
euygun 3:b9051f3f2fcd 112
euygun 1:e11c75d931b5 113 // Set the LED states
euygun 0:25fcf12b0ba2 114 ledRed = 0;
euygun 0:25fcf12b0ba2 115 ledGreen = 1;
euygun 0:25fcf12b0ba2 116 ledBlue = 1;
euygun 0:25fcf12b0ba2 117
euygun 3:b9051f3f2fcd 118 printf("u-blox C030 Out-of-the-Box Demo: LED loop\n\r");
euygun 0:25fcf12b0ba2 119
euygun 0:25fcf12b0ba2 120 //Main loop
euygun 0:25fcf12b0ba2 121 while(1) {
euygun 0:25fcf12b0ba2 122 wait(delay);
euygun 0:25fcf12b0ba2 123 //Shift the LED states
euygun 0:25fcf12b0ba2 124 int carry = ledBlue;
euygun 0:25fcf12b0ba2 125 ledBlue = ledRed;
euygun 0:25fcf12b0ba2 126 ledRed = ledGreen;
euygun 0:25fcf12b0ba2 127 ledGreen = carry;
euygun 0:25fcf12b0ba2 128 }
euygun 0:25fcf12b0ba2 129 }
euygun 0:25fcf12b0ba2 130
euygun 0:25fcf12b0ba2 131 // End Of File