Skip to content

Commit 6d8b97c

Browse files
authored
Merge pull request #98 from sparkfun/update_stand_alone_examples
Update stand alone examples for v2.1.0 of Apollo3
2 parents c741544 + 0ddab50 commit 6d8b97c

File tree

41 files changed

+1160
-3725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1160
-3725
lines changed

Firmware/Test Sketches/GNSS_Data_Logging/GNSS_Data_Logging.ino

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
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.
@@ -28,8 +36,6 @@
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
@@ -49,7 +55,7 @@
4955
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
5056
SFE_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;
103111
const byte BREAKOUT_PIN_TX = 12;
104112
const byte BREAKOUT_PIN_RX = 13;
105113
const 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
115121
const int sdPowerDownDelay = 100; //Delay for this many ms before turning off the SD card power
116122
bool powerLossSeen = false; //Interrupt flag for power loss detection
117123
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
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
297308
void 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
305319
void 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

481535
void 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
514552
float readVIN()
515553
{

Firmware/Test Sketches/IMU_DMP_MultipleSensors/IMU_DMP_MultipleSensors.ino

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
* Example9_DMP_MultipleSensors.ino
55
* ICM 20948 Arduino Library Demo
66
* Initialize the DMP based on the TDK InvenSense ICM20948_eMD_nucleo_1.0 example-icm20948
7-
* Paul Clark, February 15th 2021
7+
* Paul Clark, August 17th 2021
88
* Based on original code by:
99
* Owen Lyke @ SparkFun Electronics
1010
* Original Creation Date: April 17 2019
1111
*
12+
* This version uses v2.1.0 of the SparkFun Apollo3 (artemis) core.
13+
*
14+
* The Board should be set to SparkFun Apollo3 \ RedBoard Artemis ATP.
15+
*
1216
* ** This example is based on InvenSense's _confidential_ Application Note "Programming Sequence for DMP Hardware Functions".
1317
* ** We are grateful to InvenSense for sharing this with us.
1418
*
@@ -31,6 +35,9 @@ const byte PIN_IMU_POWER = 27; // The Red SparkFun version of the OLA (V10) uses
3135
//const byte PIN_IMU_POWER = 22; // The Black SparkX version of the OLA (X04) uses pin 22
3236
const byte PIN_IMU_INT = 37;
3337
const byte PIN_IMU_CHIP_SELECT = 44;
38+
const byte PIN_SPI_SCK = 5;
39+
const byte PIN_SPI_CIPO = 6;
40+
const byte PIN_SPI_COPI = 7;
3441

3542
#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
3643

@@ -43,9 +50,14 @@ ICM_20948_SPI myICM; // Create an ICM_20948_SPI object
4350

4451
void setup() {
4552

53+
// Start the SPI port
4654
SPI_PORT.begin();
47-
48-
enableCIPOpullUp(); // Enable CIPO pull-up on the OLA
55+
// 'Kickstart' the SPI hardware at 4MHz - this changes the CIPO pin mode
56+
SPI_PORT.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
57+
SPI_PORT.transfer(0x00);
58+
SPI_PORT.endTransaction();
59+
// *Now* enable CIPO pull-up on the OLA
60+
enableCIPOpullUp();
4961

5062
pinMode(PIN_IMU_CHIP_SELECT, OUTPUT);
5163
digitalWrite(PIN_IMU_CHIP_SELECT, HIGH); //Be sure IMU is deselected
@@ -75,14 +87,27 @@ void setup() {
7587

7688
//myICM.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
7789

78-
bool initialized = false;
90+
// Initialize the ICM-20948
91+
// If the DMP is enabled, .begin performs a minimal startup. We need to configure the sample mode etc. manually.
92+
myICM.begin( CS_PIN, SPI_PORT, 4000000); //Set IMU SPI rate to 4MHz
93+
bool initialized = (myICM.status == ICM_20948_Stat_Ok);
94+
7995
while( !initialized ){
8096

81-
// Initialize the ICM-20948
82-
// If the DMP is enabled, .begin performs a minimal startup. We need to configure the sample mode etc. manually.
83-
myICM.begin( CS_PIN, SPI_PORT );
97+
enableCIPOpullUp(); // Enable CIPO pull-up on the OLA
98+
99+
//Reset ICM by power cycling it
100+
imuPowerOff();
101+
102+
delay(10);
103+
104+
imuPowerOn(); // Enable power for the OLA IMU
105+
106+
delay(100); // Wait for the IMU to power up
84107

85-
SERIAL_PORT.print( F("Initialization of the sensor returned: ") );
108+
myICM.begin( CS_PIN, SPI_PORT, 4000000); //Set IMU SPI rate to 4MHz
109+
110+
SERIAL_PORT.print( F("Initialization of the IMU returned: ") );
86111
SERIAL_PORT.println( myICM.statusString() );
87112
if( myICM.status != ICM_20948_Stat_Ok ){
88113
SERIAL_PORT.println( F("Trying again...") );
@@ -92,7 +117,7 @@ void setup() {
92117
}
93118
}
94119

95-
SERIAL_PORT.println(F("Device connected!"));
120+
SERIAL_PORT.println(F("IMU connected!"));
96121

97122
bool success = true; // Use success to show if the DMP configuration was successful
98123

@@ -265,16 +290,16 @@ void imuPowerOff()
265290
digitalWrite(PIN_IMU_POWER, LOW);
266291
}
267292

268-
bool enableCIPOpullUp()
293+
void enableCIPOpullUp() // updated for v2.1.0 of the Apollo3 core
269294
{
270-
//Add CIPO pull-up
271-
ap3_err_t retval = AP3_OK;
272-
am_hal_gpio_pincfg_t cipoPinCfg = AP3_GPIO_DEFAULT_PINCFG;
273-
cipoPinCfg.uFuncSel = AM_HAL_PIN_6_M0MISO;
274-
cipoPinCfg.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA;
275-
cipoPinCfg.eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL;
276-
cipoPinCfg.uIOMnum = AP3_SPI_IOM;
295+
//Add 1K5 pull-up on CIPO
296+
am_hal_gpio_pincfg_t cipoPinCfg = g_AM_BSP_GPIO_IOM0_MISO;
277297
cipoPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K;
278-
padMode(MISO, cipoPinCfg, &retval);
279-
return (retval == AP3_OK);
298+
pin_config(PinName(PIN_SPI_CIPO), cipoPinCfg);
299+
}
300+
301+
void disableCIPOpullUp() // updated for v2.1.0 of the Apollo3 core
302+
{
303+
am_hal_gpio_pincfg_t cipoPinCfg = g_AM_BSP_GPIO_IOM0_MISO;
304+
pin_config(PinName(PIN_SPI_CIPO), cipoPinCfg);
280305
}

0 commit comments

Comments
 (0)