55
66 By: Paul Clark
77 SparkFun Electronics
8- Date: April 23rd , 2021
8+ Date: August 17th , 2021
99 License: MIT. See license file for more information but you can
1010 basically do whatever you want with this code.
1111
1212 This example shows how to configure the u-blox GNSS to send RXM SFRBX and RAWX reports automatically
1313 and log the data to SD card in UBX format
1414
15+ This version uses v2.1.0 of the SparkFun Apollo3 (artemis) core.
16+
17+ Please note: v2.1.1 of the core contains a change to the I2C interface which makes communication
18+ with u-blox modules over I2C less reliable. If you are building this code yourself,
19+ please use V2.1.0 of the core.
20+
21+ The Board should be set to SparkFun Apollo3 \ RedBoard Artemis ATP.
22+
1523 ** Please note: this example will only work with u-blox ADR or High Precision GNSS or Time Sync products **
1624
1725 Data is logged in u-blox UBX format. Please see the u-blox protocol specification for more details.
2836 Insert a formatted micro-SD card into the socket on OpenLog Artemis.
2937 Connect OpenLog Artemis to your computer using a USB-C cable.
3038 Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
31- This code has been tested using version 1.2.1 of the Apollo3 boards on Arduino IDE 1.8.13.
32- Select "SparkFun Artemis ATP" as the board type.
3339 Press upload to upload the code onto the Artemis.
3440 Open the Serial Monitor at 115200 baud to see the output.
3541
4955#include < SparkFun_u-blox_GNSS_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
5056SFE_UBLOX_GNSS myGNSS;
5157
52- #include < SdFat.h> // SdFat v2.0.6 by Bill Greiman. Click here to get the library: http://librarymanager/All#SdFat_exFAT
58+ #include < SdFat.h> // SdFat v2.0.7 by Bill Greiman. Click here to get the library: http://librarymanager/All#SdFat_exFAT
5359
5460#define SD_FAT_TYPE 3 // SD_FAT_TYPE = 0 for SdFat/File, 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
5561#define SD_CONFIG SdSpiConfig (PIN_MICROSD_CHIP_SELECT, SHARED_SPI, SD_SCK_MHZ(24 )) // 24MHz
@@ -72,7 +78,9 @@ File myFile; //File that all GNSS data is written to
7278
7379// Setup Qwiic Port
7480#include < Wire.h>
75- TwoWire qwiic (1 ); // Will use pads 8/9
81+ const byte PIN_QWIIC_SCL = 8 ;
82+ const byte PIN_QWIIC_SDA = 9 ;
83+ TwoWire qwiic (PIN_QWIIC_SDA,PIN_QWIIC_SCL); // Will use pads 8/9
7684
7785// Define the pin functions
7886// Depends on hardware version. This can be found as a marking on the PCB.
@@ -103,8 +111,6 @@ const byte BREAKOUT_PIN_32 = 32;
103111const byte BREAKOUT_PIN_TX = 12 ;
104112const byte BREAKOUT_PIN_RX = 13 ;
105113const byte BREAKOUT_PIN_11 = 11 ;
106- const byte PIN_QWIIC_SCL = 8 ;
107- const byte PIN_QWIIC_SDA = 9 ;
108114
109115// Globals and Consts
110116
@@ -115,6 +121,8 @@ const int lowBatteryReadingsLimit = 10; // Don't declare the battery voltage low
115121const int sdPowerDownDelay = 100 ; // Delay for this many ms before turning off the SD card power
116122bool powerLossSeen = false ; // Interrupt flag for power loss detection
117123bool stopLoggingSeen = false ; // Interrupt flag for stop logging detection
124+ bool ignorePowerLossInterrupt = true ; // Ignore the power loss interrupt - when attaching the interrupt
125+ bool ignoreStopLoggingInterrupt = true ; // Ignore the stop logging interrupt - when attaching the interrupt
118126
119127// Data Logging Specifics:
120128
@@ -134,7 +142,9 @@ void setup()
134142 delay (1 ); // Let PIN_POWER_LOSS stabilize
135143
136144 if (digitalRead (PIN_POWER_LOSS) == LOW) powerLossISR (); // Check PIN_POWER_LOSS just in case we missed the falling edge
145+ ignorePowerLossInterrupt = true ; // Ignore the power loss interrupt - when attaching the interrupt
137146 attachInterrupt (digitalPinToInterrupt (PIN_POWER_LOSS), powerLossISR, FALLING);
147+ ignorePowerLossInterrupt = false ;
138148
139149 powerLEDOn (); // Turn the power LED on - if the hardware supports it
140150
@@ -155,15 +165,16 @@ void setup()
155165
156166 beginSD (); // Enable power for the SD card
157167
158- enableCIPOpullUp (); // Enable CIPO pull-up after beginSD
159-
160168 imuPowerOff (); // We're not using the IMU so turn it off
161169
162170 delay (2500 ); // Give the GNSS time to power up
163171
164172 pinMode (PIN_STOP_LOGGING, INPUT_PULLUP);
165173 delay (1 ); // Let the pin stabilize
174+ ignoreStopLoggingInterrupt = true ; // Ignore the stop logging interrupt - when attaching the interrupt
166175 attachInterrupt (digitalPinToInterrupt (PIN_STOP_LOGGING), stopLoggingISR, FALLING); // Enable the stop logging interrupt
176+ pinMode (PIN_STOP_LOGGING, INPUT_PULLUP); // Re-attach the pull-up (bug in v2.1.0 of the core)
177+ ignoreStopLoggingInterrupt = false ;
167178
168179 Serial.println (" Initializing SD card..." );
169180
@@ -296,17 +307,23 @@ void loop()
296307// Stop Logging ISR
297308void stopLoggingISR (void )
298309{
299- Serial.println (F (" Stop Logging Seen!" ));
300- detachInterrupt (digitalPinToInterrupt (PIN_STOP_LOGGING)); // Prevent multiple interrupts
301- stopLoggingSeen = true ;
310+ if (ignoreStopLoggingInterrupt == false )
311+ {
312+ Serial.println (F (" Stop Logging Seen!" ));
313+ detachInterrupt (digitalPinToInterrupt (PIN_STOP_LOGGING)); // Prevent multiple interrupts
314+ stopLoggingSeen = true ;
315+ }
302316}
303317
304318// Power Loss ISR
305319void powerLossISR (void )
306320{
307- Serial.println (F (" Power Loss Detected!" ));
308- detachInterrupt (digitalPinToInterrupt (PIN_POWER_LOSS)); // Prevent multiple interrupts
309- powerLossSeen = true ;
321+ if (ignorePowerLossInterrupt == false )
322+ {
323+ Serial.println (F (" Power Loss Detected!" ));
324+ detachInterrupt (digitalPinToInterrupt (PIN_POWER_LOSS)); // Prevent multiple interrupts
325+ powerLossSeen = true ;
326+ }
310327}
311328
312329// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -357,7 +374,7 @@ void stopLogging(void) // Stop logging; close the SD file; go into deep sleep
357374
358375 SPI.end (); // Power down SPI
359376
360- power_adc_disable ( ); // Power down ADC. It it started by default before setup().
377+ powerControlADC ( false ); // Power down ADC. It it started by default before setup().
361378
362379 Serial.end (); // Power down UART
363380
@@ -383,9 +400,10 @@ void stopLogging(void) // Stop logging; close the SD file; go into deep sleep
383400 // Disable pads
384401 for (int x = 0 ; x < 50 ; x++)
385402 {
386- if ((x != ap3_gpio_pin2pad (PIN_MICROSD_POWER)) &&
387- (x != ap3_gpio_pin2pad (PIN_QWIIC_POWER)) &&
388- (x != ap3_gpio_pin2pad (PIN_IMU_POWER)))
403+ if ((x != PIN_MICROSD_POWER) &&
404+ // (x != PIN_LOGIC_DEBUG) &&
405+ (x != PIN_QWIIC_POWER) &&
406+ (x != PIN_IMU_POWER))
389407 {
390408 am_hal_gpio_pinconfig (x, g_AM_HAL_GPIO_DISABLE);
391409 }
@@ -475,7 +493,43 @@ void beginQwiic()
475493 pinMode (PIN_QWIIC_POWER, OUTPUT);
476494 qwiicPowerOn ();
477495 qwiic.begin ();
478- qwiic.setPullups (0 ); // Just to make it really clear what pull-ups are being used, set pullups here.
496+ setQwiicPullups (0 ); // Just to make it really clear what pull-ups are being used, set pullups here.
497+ }
498+
499+ void setQwiicPullups (uint32_t i2cBusPullUps)
500+ {
501+ // Change SCL and SDA pull-ups manually using pin_config
502+ am_hal_gpio_pincfg_t sclPinCfg = g_AM_BSP_GPIO_IOM1_SCL;
503+ am_hal_gpio_pincfg_t sdaPinCfg = g_AM_BSP_GPIO_IOM1_SDA;
504+
505+ if (i2cBusPullUps == 0 )
506+ {
507+ sclPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_NONE; // No pull-ups
508+ sdaPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_NONE;
509+ }
510+ else if (i2cBusPullUps == 1 )
511+ {
512+ sclPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K; // Use 1K5 pull-ups
513+ sdaPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K;
514+ }
515+ else if (i2cBusPullUps == 6 )
516+ {
517+ sclPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_6K; // Use 6K pull-ups
518+ sdaPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_6K;
519+ }
520+ else if (i2cBusPullUps == 12 )
521+ {
522+ sclPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_12K; // Use 12K pull-ups
523+ sdaPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_12K;
524+ }
525+ else
526+ {
527+ sclPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_24K; // Use 24K pull-ups
528+ sdaPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_24K;
529+ }
530+
531+ pin_config (PinName (PIN_QWIIC_SCL), sclPinCfg);
532+ pin_config (PinName (PIN_QWIIC_SDA), sdaPinCfg);
479533}
480534
481535void beginSD ()
@@ -494,22 +548,6 @@ void beginSD()
494548
495549// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
496550
497- bool enableCIPOpullUp ()
498- {
499- // Add CIPO pull-up
500- ap3_err_t retval = AP3_OK;
501- am_hal_gpio_pincfg_t cipoPinCfg = AP3_GPIO_DEFAULT_PINCFG;
502- cipoPinCfg.uFuncSel = AM_HAL_PIN_6_M0MISO;
503- cipoPinCfg.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA;
504- cipoPinCfg.eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL;
505- cipoPinCfg.uIOMnum = AP3_SPI_IOM;
506- cipoPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K;
507- padMode (MISO, cipoPinCfg, &retval);
508- return (retval == AP3_OK);
509- }
510-
511- // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
512-
513551// Read the VIN voltage
514552float readVIN ()
515553{
0 commit comments