Skip to content

"SparkFun_Qwiic_Button.cpp" Bugs #6

Open
@dlkeng

Description

@dlkeng

"SparkFun_Qwiic_Button.cpp" Bugs

The resetInterruptConfig(), writeSingleRegisterWithReadback(), and writeDoubleRegisterWithReadback() do not operate correctly.

Your workbench

  • Tested with Arduino Nano board powered via USB port and using a logic analyzer to monitor the I2C traffic.

Steps to reproduce

  1. resetInterruptConfig() does not clear the .eventAvailable bit
    In resetInterruptConfig(), Line 188: this return in the middle of the function prevents the .eventAvailable bit from being cleared in BUTTON_STATUS reg
  2. writeSingleRegisterWithReadback() does not correctly read the just-written register
    In writeSingleRegisterWithReadback(), lines 369-370: the writeSingleRegister() returns true on success, but this function returns failure code 1 on success instead of calling readSingleRegister() to retrieve and compare the just-written data
  3. writeDoubleRegisterWithReadback(), lines 378-379: the writeDoubleRegister() returns true on success, but this function returns failure code 1 on success instead of calling readDoubleRegister() to retrieve and compare the just-written data

These last two bugs also cause the following functions to not correctly read back the register written and also returns the wrong return code with a successful I2C write operation:

  • setDebounceTime()
  • enablePressedInterrupt()
  • disablePressedInterrupt()
  • enableClickedInterrupt()
  • disableClickedInterrupt()
  • clearEventBits()
  • resetInterruptConfig()

Related Notes:

The SparkFun Qwiic Button Hookup Guide's Qwiic Button Arduino Library API documentation at:
https://learn.sparkfun.com/tutorials/sparkfun-qwiic-button-hookup-guide/all#qwiic-button-arduino-library
has related documentation issues.

  • writeSingleRegister()
    • Says returns 0 if there was no error on I2C transmission, and 1 otherwise.
    • Actually returns 'true' if successful I2C transmission, else returns 'false'.
  • writeDoubleRegister()
    • Says returns 0 if there was no error on I2C transmission, and 1 otherwise.
    • Actually returns 'true' if successful I2C transmission, else returns 'false'.
  • writeSingleRegisterWithReadback()
    • Says returns 0 on no error, 1 on I2C write fail, and 2 if the register doesn't read back the same value that was written.
    • This is probably how it should work, but actually incorrectly (see above) returns 1 on no error, 2 if the register doesn't read back the same value that was written, else returns 0.
  • writeDoubleRegisterWithReadback()
    • Says returns 0 on no error, 1 on I2C write fail, and 2 if the register doesn't read back the same value that was written.
    • This is probably how it should work, but actually incorrectly (see above) returns 1 on no error, 2 if the register doesn't read back the same value that was written, else returns 0.

Attached File Information:

In the attached file is an Arduino test sketch (for an Arduino Nano) that demonstrates the problems. That Arduino Nano is connected via the I2C bus to another Arduino Nano that is running the Sparkfun Qwiic_Button.ino firmware emulating the actual Sparkfun Qwiic Button device. In the comments at the end of the file are shown the actual results of running the sketch and the expected results of running the sketch if the above issues did not occur (after modifications to SparkFun_Qwiic_Button.cpp).

QwiicButtonBugTest.ino.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions