Skip to content

Commit 49c6eb2

Browse files
committed
Corrections for Qwiic bus speed (100kHz and 400kHz). Ensure interrupt directions are set correctly.
1 parent 0022b9b commit 49c6eb2

File tree

7 files changed

+63
-12
lines changed

7 files changed

+63
-12
lines changed

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
1414
The Board should be set to SparkFun Apollo3 \ RedBoard Artemis ATP.
1515
16-
Please note: this version of the firmware compiles on v2.1.0+ of the Apollo3 boards.
16+
Please note: this version of the firmware compiles on v2.1.0 of the Apollo3 boards.
17+
18+
(At the time of writing, data logging with the the u-blox ZED-F9P is problematic when using v2.1.1 of the core.)
1719
1820
v1.0 Power Consumption:
1921
Sleep between reads, RTC fully charged, no Qwiic, SD, no USB, no Power LED: 260uA
@@ -95,7 +97,7 @@
9597
9698
(in progress) Update to Apollo3 v2.1.1 - FIRMWARE_VERSION_MAJOR = 2.
9799
(done) Implement printf float (OLA uses printf float in _so_ many places...): https://github.com/sparkfun/Arduino_Apollo3/issues/278
98-
(worked around) Figure out why attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); causes badness
100+
(worked around) attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); causes badness - https://github.com/sparkfun/Arduino_Apollo3/issues/416
99101
(done) Add a setQwiicPullups function
100102
(done) Check if we need ap3_set_pin_to_analog when coming out of sleep
101103
(done) Investigate why code does not wake from deep sleep correctly
@@ -326,7 +328,7 @@ void setup() {
326328
delay(1); // Let PIN_POWER_LOSS stabilize
327329

328330
if (digitalRead(PIN_POWER_LOSS) == LOW) powerDownOLA(); //Check PIN_POWER_LOSS just in case we missed the falling edge
329-
//attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); // TO DO: figure out why this no longer works on v2.1.0
331+
//attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); // We can't do this with v2.1.0 as attachInterrupt causes a spontaneous interrupt
330332
attachInterrupt(PIN_POWER_LOSS, powerLossISR, FALLING);
331333
powerLossSeen = false; // Make sure the flag is clear
332334

@@ -387,25 +389,30 @@ void setup() {
387389
pinMode(PIN_STOP_LOGGING, INPUT_PULLUP);
388390
delay(1); // Let the pin stabilize
389391
attachInterrupt(PIN_STOP_LOGGING, stopLoggingISR, FALLING); // Enable the interrupt
390-
pin_config(PinName(PIN_STOP_LOGGING), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
392+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
393+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
394+
pin_config(PinName(PIN_STOP_LOGGING), intPinConfig); // Make sure the pull-up does actually stay enabled
391395
stopLoggingSeen = false; // Make sure the flag is clear
392396
}
393397

394398
if (settings.useGPIO11ForTrigger == true)
395399
{
396400
pinMode(PIN_TRIGGER, INPUT_PULLUP);
397401
delay(1); // Let the pin stabilize
402+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
398403
if (settings.fallingEdgeTrigger == true)
399404
{
400405
SerialPrintln(F("Falling-edge triggering is enabled. Sensor data will be logged on a falling edge on GPIO pin 11."));
401406
attachInterrupt(PIN_TRIGGER, triggerPinISR, FALLING); // Enable the interrupt
407+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
402408
}
403409
else
404410
{
405411
SerialPrintln(F("Rising-edge triggering is enabled. Sensor data will be logged on a rising edge on GPIO pin 11."));
406412
attachInterrupt(PIN_TRIGGER, triggerPinISR, RISING); // Enable the interrupt
413+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_LO2HI;
407414
}
408-
pin_config(PinName(PIN_TRIGGER), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
415+
pin_config(PinName(PIN_TRIGGER), intPinConfig); // Make sure the pull-up does actually stay enabled
409416
triggerEdgeSeen = false; // Make sure the flag is clear
410417
}
411418

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,20 +1568,32 @@ void setMaxI2CSpeed()
15681568
//Check if i2cSpeed is lowered
15691569
struct_uBlox *sensor = (struct_uBlox*)temp->configPtr;
15701570
if (sensor->i2cSpeed == 100000)
1571+
{
1572+
//printDebug("setMaxI2CSpeed: sensor->i2cSpeed is 100000. Reducing maxSpeed to 100kHz\r\n");
15711573
maxSpeed = 100000;
1574+
}
15721575
}
15731576

15741577
temp = temp->next;
15751578
}
15761579

15771580
//If user wants to limit the I2C bus speed, do it here
15781581
if (maxSpeed > settings.qwiicBusMaxSpeed)
1582+
{
1583+
//printDebug("setMaxI2CSpeed: maxSpeed is > settings.qwiicBusMaxSpeed. Reducing maxSpeed to " + (String)settings.qwiicBusMaxSpeed + "Hz\r\n");
15791584
maxSpeed = settings.qwiicBusMaxSpeed;
1585+
}
15801586

15811587
if (maxSpeed > 200000)
1588+
{
1589+
printDebug("setMaxI2CSpeed: setting qwiic clock speed to " + (String)AM_HAL_IOM_400KHZ + "Hz\r\n");
15821590
qwiic.setClock(AM_HAL_IOM_400KHZ);
1591+
}
15831592
else
1593+
{
1594+
printDebug("setMaxI2CSpeed: setting qwiic clock speed to " + (String)AM_HAL_IOM_100KHZ + "Hz\r\n");
15841595
qwiic.setClock(AM_HAL_IOM_100KHZ);
1596+
}
15851597
for (int i = 0; i < 100; i++) //Allow time for the speed to change
15861598
{
15871599
checkBattery();

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,10 @@ void configureQwiicDevices()
855855
configureDevice(temp);
856856
temp = temp->next;
857857
}
858+
859+
//Now that the settings are loaded and the devices are configured,
860+
//try for 400kHz but reduce to 100kHz if certain devices are attached
861+
setMaxI2CSpeed();
858862
}
859863

860864
//Returns a pointer to the menu function that configures this particular device type

Firmware/OpenLog_Artemis/lowerPower.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void wakeFromSleep()
414414

415415
if (digitalRead(PIN_POWER_LOSS) == LOW) powerDownOLA(); //Check PIN_POWER_LOSS just in case we missed the falling edge
416416

417-
//attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); // TO DO: figure out why this no longer works on v2.1.0
417+
//attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); // We can't do this with v2.1.0 as attachInterrupt causes a spontaneous interrupt
418418
attachInterrupt(PIN_POWER_LOSS, powerLossISR, FALLING);
419419
powerLossSeen = false; // Make sure the flag is clear
420420

@@ -424,7 +424,9 @@ void wakeFromSleep()
424424
pin_config(PinName(PIN_STOP_LOGGING), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pin does actually get re-configured
425425
delay(1); // Let the pin stabilize
426426
attachInterrupt(PIN_STOP_LOGGING, stopLoggingISR, FALLING); // Enable the interrupt
427-
pin_config(PinName(PIN_STOP_LOGGING), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
427+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
428+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
429+
pin_config(PinName(PIN_STOP_LOGGING), intPinConfig); // Make sure the pull-up does actually stay enabled
428430
stopLoggingSeen = false; // Make sure the flag is clear
429431
}
430432

@@ -433,11 +435,20 @@ void wakeFromSleep()
433435
pinMode(PIN_TRIGGER, INPUT_PULLUP);
434436
pin_config(PinName(PIN_TRIGGER), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pin does actually get re-configured
435437
delay(1); // Let the pin stabilize
438+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
436439
if (settings.fallingEdgeTrigger == true)
440+
{
441+
SerialPrintln(F("Falling-edge triggering is enabled. Sensor data will be logged on a falling edge on GPIO pin 11."));
437442
attachInterrupt(PIN_TRIGGER, triggerPinISR, FALLING); // Enable the interrupt
443+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
444+
}
438445
else
446+
{
447+
SerialPrintln(F("Rising-edge triggering is enabled. Sensor data will be logged on a rising edge on GPIO pin 11."));
439448
attachInterrupt(PIN_TRIGGER, triggerPinISR, RISING); // Enable the interrupt
440-
pin_config(PinName(PIN_TRIGGER), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
449+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_LO2HI;
450+
}
451+
pin_config(PinName(PIN_TRIGGER), intPinConfig); // Make sure the pull-up does actually stay enabled
441452
triggerEdgeSeen = false; // Make sure the flag is clear
442453
}
443454

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ bool detectQwiicDevices()
229229
//*** Let's leave pull-ups set to 1k and only disable them when taking to a u-blox device ***
230230
//setQwiicPullups(0); //We've detected something on the bus so disable pullups.
231231

232-
setMaxI2CSpeed(); //Try for 400kHz but reduce to 100kHz or low if certain devices are attached
232+
//We need to call setMaxI2CSpeed in configureQwiicDevices
233+
//We cannot do it here as the device settings have not been loaded
233234

234235
SerialPrintln(F("Autodetect complete"));
235236

Firmware/OpenLog_Artemis/menuPower.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ void menuPower()
6565
pin_config(PinName(PIN_STOP_LOGGING), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pin does actually get re-configured
6666
delay(1); // Let the pin stabilize
6767
attachInterrupt(PIN_STOP_LOGGING, stopLoggingISR, FALLING); // Enable the interrupt
68-
pin_config(PinName(PIN_STOP_LOGGING), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
68+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
69+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
70+
pin_config(PinName(PIN_STOP_LOGGING), intPinConfig); // Make sure the pull-up does actually stay enabled
6971
stopLoggingSeen = false; // Make sure the flag is clear
7072
settings.logA32 = false; // Disable analog logging on pin 32
7173
}

Firmware/OpenLog_Artemis/menuTerminal.ino

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,18 @@ void menuLogRate()
298298
pinMode(PIN_TRIGGER, INPUT_PULLUP);
299299
pin_config(PinName(PIN_TRIGGER), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pin does actually get re-configured
300300
delay(1); // Let the pin stabilize
301+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
301302
if (settings.fallingEdgeTrigger == true)
303+
{
302304
attachInterrupt(PIN_TRIGGER, triggerPinISR, FALLING); // Enable the interrupt
305+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
306+
}
303307
else
308+
{
304309
attachInterrupt(PIN_TRIGGER, triggerPinISR, RISING); // Enable the interrupt
305-
pin_config(PinName(PIN_TRIGGER), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
310+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_LO2HI;
311+
}
312+
pin_config(PinName(PIN_TRIGGER), intPinConfig); // Make sure the pull-up does actually stay enabled
306313
triggerEdgeSeen = false; // Make sure the flag is clear
307314
settings.logA11 = false; // Disable analog logging on pin 11
308315
settings.logMaxRate = false; // Disable max rate logging
@@ -325,11 +332,18 @@ void menuLogRate()
325332
{
326333
detachInterrupt(PIN_TRIGGER); // Disable the interrupt
327334
settings.fallingEdgeTrigger ^= 1; // Invert the flag
335+
am_hal_gpio_pincfg_t intPinConfig = g_AM_HAL_GPIO_INPUT_PULLUP;
328336
if (settings.fallingEdgeTrigger == true)
337+
{
329338
attachInterrupt(PIN_TRIGGER, triggerPinISR, FALLING); // Enable the interrupt
339+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_HI2LO;
340+
}
330341
else
342+
{
331343
attachInterrupt(PIN_TRIGGER, triggerPinISR, RISING); // Enable the interrupt
332-
pin_config(PinName(PIN_TRIGGER), g_AM_HAL_GPIO_INPUT_PULLUP); // Make sure the pull-up does actually stay enabled
344+
intPinConfig.eIntDir = AM_HAL_GPIO_PIN_INTDIR_LO2HI;
345+
}
346+
pin_config(PinName(PIN_TRIGGER), intPinConfig); // Make sure the pull-up does actually stay enabled
333347
triggerEdgeSeen = false; // Make sure the flag is clear
334348
}
335349
else

0 commit comments

Comments
 (0)