Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wiring]: change I2C timeout in FuelGauge and PMIC to a more manageab… #2096

Merged
merged 1 commit into from May 18, 2020

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented May 6, 2020

Steps to Test

  1. Build and flash the following example application to B5SoM that is attached on SoM evaluation board.
  2. Connect SoM evaluation board to serial monitor.
  3. Short PM_SCL with GND and observe the delta time printed on serial monitor.
  4. Sample output:
0000494229 [app] application.cpp:25, loop(): TRACE: PMIC delta T: 557 us
0000495233 [app] application.cpp:19, loop(): TRACE: FuelGauge SoC: 81.40 %, delta T: 647 us
0000495234 [app] application.cpp:25, loop(): TRACE: PMIC delta T: 547 us
0000496364 [app] application.cpp:19, loop(): TRACE: FuelGauge SoC: 256.00 %, delta T: 122494 us
0000496487 [app] application.cpp:25, loop(): TRACE: PMIC delta T: 122085 us
0000497610 [app] application.cpp:19, loop(): TRACE: FuelGauge SoC: 256.00 %, delta T: 121994 us
0000497733 [app] application.cpp:25, loop(): TRACE: PMIC delta T: 122090 us
0000498735 [app] application.cpp:19, loop(): TRACE: FuelGauge SoC: 81.40 %, delta T: 647 us
0000498736 [app] application.cpp:25, loop(): TRACE: PMIC delta T: 555 us
0000499744 [app] application.cpp:19, loop(): TRACE: FuelGauge SoC: 81.40 %, delta T: 648 us
0000499745 [app] application.cpp:25, loop(): TRACE: PMIC delta T: 557 us

Normally, it only takes ~650us per reading/writing register of the FuelGauge or PMIC, so it's enough to sets the default I2C timeout to 10ms for them, instead of using the default 100ms timeout in I2C HAL. If using 100ms default timeout, the delta T if timeout occurred would be ~300ms.

Example App

#include "Particle.h"

SYSTEM_MODE(MANUAL);

SerialLogHandler log(115200, LOG_LEVEL_ALL);

void setup()
{
    Serial.begin(115200);
    while(!Serial.isConnected());
    LOG(TRACE, "Application started.");
}

void loop() {
    FuelGauge gauge;
    system_tick_t start = micros();
    float soc = gauge.getSoC();
    system_tick_t end = micros();
    LOG(TRACE, "FuelGauge SoC: %4.2f %%, delta T: %d us", soc, end - start);

    PMIC pmic;
    start = micros();
    pmic.getVersion();
    end = micros();
    LOG(TRACE, "PMIC delta T: %d us", end - start);

    delay(1000);
}

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui requested a review from avtolstoy May 6, 2020 11:27
@avtolstoy avtolstoy added this to the 2.0.0 milestone May 12, 2020
@avtolstoy avtolstoy added ready to merge PR has been reviewed and tested and removed needs review labels May 14, 2020
wiring/inc/spark_wiring_fuel.h Outdated Show resolved Hide resolved
@XuGuohui XuGuohui force-pushed the feature/configurable_i2c_timeout/ch52808 branch from 7aafa10 to f6cbb45 Compare May 14, 2020 16:18
@XuGuohui XuGuohui force-pushed the feature/configurable_i2c_timeout/ch52808 branch from f6cbb45 to 81cdcc8 Compare May 18, 2020 11:41
@XuGuohui XuGuohui merged commit eadb1b6 into develop May 18, 2020
@XuGuohui XuGuohui deleted the feature/configurable_i2c_timeout/ch52808 branch May 18, 2020 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ready to merge PR has been reviewed and tested
Projects
None yet
2 participants