Description
"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
resetInterruptConfig()
does not clear the.eventAvailable
bit
InresetInterruptConfig()
, Line 188: this return in the middle of the function prevents the.eventAvailable
bit from being cleared in BUTTON_STATUS regwriteSingleRegisterWithReadback()
does not correctly read the just-written register
InwriteSingleRegisterWithReadback()
, lines 369-370: thewriteSingleRegister()
returns true on success, but this function returns failure code 1 on success instead of callingreadSingleRegister()
to retrieve and compare the just-written datawriteDoubleRegisterWithReadback()
, lines 378-379: thewriteDoubleRegister()
returns true on success, but this function returns failure code 1 on success instead of callingreadDoubleRegister()
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).