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.
Dependencies: Custom_LSM303 Custom_UBloxGPS LRAT-mbed-os USBDevice mbed-lora-radio-drv stm32EEPROM
Fork of LRAT-example-lorawan by
Diff: main.cpp
- Revision:
- 39:6da6cb44f22e
- Parent:
- 38:fd7a407bfe3e
- Child:
- 40:eaf476b94684
--- a/main.cpp Thu Aug 30 20:51:03 2018 +0000 +++ b/main.cpp Thu Aug 30 21:29:22 2018 +0000 @@ -228,6 +228,24 @@ #define CFG_ACC_LEN 7 #define CFG_MAG_ADR LSM303_REG_MAG_CTRL_REG1_M #define CFG_MAG_LEN 5 + + // HUOT ADDITIONS -- 08/30/2018 -- Port of LRAT LSM303CTR ACC Register definitions + // LSM303CTR Specific ACC Register ID's + #define LSM303_REG_ACC_INT1_THS_X1_A 0x32 + #define LSM303_REG_ACC_INT1_THS_Y1_A 0x33 + #define LSM303_REG_ACC_INT1_THS_Z1_A 0x34 + #define LSM303_REG_ACC_INT1_DURATION_A 0x35 + #define LSM303_REG_ACC_INT2_CFG_A 0x36 + #define LSM303_REG_ACC_INT2_SRC_A 0x37 + #define LSM303_REG_ACC_INT2_THS_A 0x38 + #define LSM303_REG_ACC_INT2_DURATION_A 0x39 + #define LSM303_REG_ACC_XL_REFERENCE 0x3A + #define LSM303_REG_ACC_XH_REFERENCE 0x3B + #define LSM303_REG_ACC_YL_REFERENCE 0x3C + #define LSM303_REG_ACC_YH_REFERENCE 0x3D + #define LSM303_REG_ACC_ZL_REFERENCE 0x3E + #define LSM303_REG_ACC_ZH_REFERENCE 0x3F + #else #define LEDR PB_7 #define LEDG PB_5 @@ -310,7 +328,7 @@ char cmdReadCfgU[8] {0xB5, 0x62, 0x06, 0x1B, 0x00, 0x00}; // Leave 2 bytes for CRC. char cmdPollPort[9] {0xB5, 0x62, 0x06, 0x00, 0x01, 0x00, 0x00}; -// HUOT Additions - 08/29/18 +// HUOT ADDITIONS - 08/29/18 -- ADDED UBX-CFG CHAR BUFFERS -- BOTTOM TWO WORK! // UBX-CFG-GNSS -- Disable Glonass (also leave 2 bytes) char cmdDisableGLONASS[68] {0xB5, 0x62, 0x06, 0x3E, 0x3C, 0x00, 0x00, 0x20, 0x20, 0x07, 0x00, 0x08, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0x01, 0x02, 0x04, 0x08, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x08, 0x10, 0x00, 0x00, 0x00, 0x01, 0x01, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x03, 0x05, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x05, 0x06, 0x08, 0x0E, 0x00, 0x01, 0x00, 0x01, 0x01}; // UBX-CFG-TP5 -- Disable Timepulse (also leave 2 bytes) @@ -444,7 +462,7 @@ magInitSequence(); accInitSequence(); - // HUOT Addition -- Reset GPS from previous tests + // HUOT ADDITION -- 08/30/2018 -- RESET GPS TO DEFAULT BEFORE MOVING FORWARD gpsExecuteCommand(cmdResetDefaults, sizeof(cmdResetDefaults)); gpsInitSequence(); @@ -536,16 +554,11 @@ // ubxRead(); // return 0; - int x = 0; - +// HUOT ADDITION -- 08/30/2018 -- MAIN LOOP TO TEST GPS SLEEP/WAKE FUNCTIONALITY -- GOT IT WORKING + int x = 0; printf("Putting to sleep... Good Luck ================ \r\n"); gpsExecuteCommand(secondTimeSleep, sizeof(secondTimeSleep)); -// printf("Attempting to read GPS while down... \r\n"); -// wait(1); -// gpsRead(); -// printf("Entering GPS Sleep/Test Loop \r\n"); - while(1) { if ((x != 0) && (x % 10 == 0)) @@ -565,7 +578,6 @@ } - // Initialize LoRaWAN stack if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { printf("\r\n LoRa initialization failed! \r\n"); @@ -960,6 +972,57 @@ cmd[0] = LSM303_REG_ACC_CTRL_REG1_A; cmd[1] = 0xB7; // High Resolution, ODR=100Hz, Enable XYZ Axes i2c.write(LSM303_ADR_ACC, cmd, 2); + + // HUOT ADDITION -- 08/30/2018 -- Accelerometer Intterupt Init Sequence + #if defined(ACC_INTERRUPT_ON) + // ACC INTERRUPT SETUP + // Enable Interrupt Pin + cmd[0] = LSM303_REG_ACC_CTRL_REG3_A; + i2c.write(LSM303_ADR_ACC, cmd, 1); + i2c.read(LSM303_ADR_ACC, &ret, 1); + + // Configure Control Register 3 + cmd[0] = LSM303_REG_ACC_CTRL_REG3_A; + cmd[1] = 0x08; + // cmd[1] = ret | 0x40; + i2c.write(LSM303_ADR_ACC, cmd, 2); + + cmd[0] = LSM303_CTRL_REG7_A; + i2c.write(LSM303_ADR_ACC, cmd, 1); + i2c.read(LSM303_ADR_ACC, &ret, 1); + + // Latch Interrupt Enabling + cmd[0] = LSM303_CTRL_REG7_A; + cmd[1] = 0x04; + //cmd[1] = ret | 0x08; + i2c.write(LSM303_ADR_ACC, cmd, 2); + + // Set Threshold/Duration/Config + // Set Threshold on X axis + cmd[0] = LSM303_REG_ACC_INT1_THS_X1_A; + cmd[1] = 0x7D; + i2c.write(LSM303_ADR_ACC, cmd, 2); + + // Set Threshold on Y axis + cmd[0] = LSM303_REG_ACC_INT1_THS_Y1_A; + i2c.write(LSM303_ADR_ACC, cmd, 2); + + // Set Y Threshold on Z axis + cmd[0] = LSM303_REG_ACC_INT1_THS_Z1_A; + i2c.write(LSM303_ADR_ACC, cmd, 2); + + // Set Interrupt Duration + cmd[0] = LSM303_REG_ACC_INT1_DURATION_A; + cmd[1] = 0x00; + i2c.write(LSM303_ADR_ACC, cmd, 2); + + // Set Interrupt Configuration + cmd[0] = LSM303_REG_ACC_INT1_CFG_A; + cmd[1] = 0x02; // Set Interrupt Generation on X-Axis High event + i2c.write(LSM303_ADR_ACC, cmd, 2); + accPin.rise(&onAccIrq); + #endif + #else cmd[0] = LSM303_REG_ACC_CTRL_REG1_A; cmd[1] = 0x57; // Enable XYZ Axes, ODR=100Hz @@ -1099,7 +1162,7 @@ //printf("LPM Init Sequence Complete. \r\n"); } -// HUOT Addition 08/30/2018 -- Generic GPS Execute command function +// HUOT ADDITION 08/30/2018 -- GENERIC GPS EXECUTE COMMAND FUNCTION void gpsExecuteCommand(char *command, int length) { @@ -1285,7 +1348,7 @@ } -// HUOT Alteration -- Change GPS read from "void" to return "int" to solidfy if fix was good or bad +// HUOT ALTERATION -- 08/30/2018 -- Change GPS read from "void" to return "int" to solidfy if fix was good or bad int gpsRead() { bool gpsDone = false;