5
5
6
6
By: Paul Clark
7
7
SparkFun Electronics
8
- Date: April 23rd , 2021
8
+ Date: August 17th , 2021
9
9
License: MIT. See license file for more information but you can
10
10
basically do whatever you want with this code.
11
11
12
12
This example shows how to configure the u-blox GNSS to send RXM SFRBX and RAWX reports automatically
13
13
and log the data to SD card in UBX format
14
14
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
+
15
23
** Please note: this example will only work with u-blox ADR or High Precision GNSS or Time Sync products **
16
24
17
25
Data is logged in u-blox UBX format. Please see the u-blox protocol specification for more details.
28
36
Insert a formatted micro-SD card into the socket on OpenLog Artemis.
29
37
Connect OpenLog Artemis to your computer using a USB-C cable.
30
38
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.
33
39
Press upload to upload the code onto the Artemis.
34
40
Open the Serial Monitor at 115200 baud to see the output.
35
41
49
55
#include < SparkFun_u-blox_GNSS_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
50
56
SFE_UBLOX_GNSS myGNSS;
51
57
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
53
59
54
60
#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.
55
61
#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
72
78
73
79
// Setup Qwiic Port
74
80
#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
76
84
77
85
// Define the pin functions
78
86
// Depends on hardware version. This can be found as a marking on the PCB.
@@ -103,8 +111,6 @@ const byte BREAKOUT_PIN_32 = 32;
103
111
const byte BREAKOUT_PIN_TX = 12 ;
104
112
const byte BREAKOUT_PIN_RX = 13 ;
105
113
const byte BREAKOUT_PIN_11 = 11 ;
106
- const byte PIN_QWIIC_SCL = 8 ;
107
- const byte PIN_QWIIC_SDA = 9 ;
108
114
109
115
// Globals and Consts
110
116
@@ -115,6 +121,8 @@ const int lowBatteryReadingsLimit = 10; // Don't declare the battery voltage low
115
121
const int sdPowerDownDelay = 100 ; // Delay for this many ms before turning off the SD card power
116
122
bool powerLossSeen = false ; // Interrupt flag for power loss detection
117
123
bool 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
118
126
119
127
// Data Logging Specifics:
120
128
@@ -134,7 +142,9 @@ void setup()
134
142
delay (1 ); // Let PIN_POWER_LOSS stabilize
135
143
136
144
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
137
146
attachInterrupt (digitalPinToInterrupt (PIN_POWER_LOSS), powerLossISR, FALLING);
147
+ ignorePowerLossInterrupt = false ;
138
148
139
149
powerLEDOn (); // Turn the power LED on - if the hardware supports it
140
150
@@ -155,15 +165,16 @@ void setup()
155
165
156
166
beginSD (); // Enable power for the SD card
157
167
158
- enableCIPOpullUp (); // Enable CIPO pull-up after beginSD
159
-
160
168
imuPowerOff (); // We're not using the IMU so turn it off
161
169
162
170
delay (2500 ); // Give the GNSS time to power up
163
171
164
172
pinMode (PIN_STOP_LOGGING, INPUT_PULLUP);
165
173
delay (1 ); // Let the pin stabilize
174
+ ignoreStopLoggingInterrupt = true ; // Ignore the stop logging interrupt - when attaching the interrupt
166
175
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 ;
167
178
168
179
Serial.println (" Initializing SD card..." );
169
180
@@ -296,17 +307,23 @@ void loop()
296
307
// Stop Logging ISR
297
308
void stopLoggingISR (void )
298
309
{
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
+ }
302
316
}
303
317
304
318
// Power Loss ISR
305
319
void powerLossISR (void )
306
320
{
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
+ }
310
327
}
311
328
312
329
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -357,7 +374,7 @@ void stopLogging(void) // Stop logging; close the SD file; go into deep sleep
357
374
358
375
SPI.end (); // Power down SPI
359
376
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().
361
378
362
379
Serial.end (); // Power down UART
363
380
@@ -383,9 +400,10 @@ void stopLogging(void) // Stop logging; close the SD file; go into deep sleep
383
400
// Disable pads
384
401
for (int x = 0 ; x < 50 ; x++)
385
402
{
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))
389
407
{
390
408
am_hal_gpio_pinconfig (x, g_AM_HAL_GPIO_DISABLE);
391
409
}
@@ -475,7 +493,43 @@ void beginQwiic()
475
493
pinMode (PIN_QWIIC_POWER, OUTPUT);
476
494
qwiicPowerOn ();
477
495
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);
479
533
}
480
534
481
535
void beginSD ()
@@ -494,22 +548,6 @@ void beginSD()
494
548
495
549
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
496
550
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
-
513
551
// Read the VIN voltage
514
552
float readVIN ()
515
553
{
0 commit comments