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
Added option to use SBWIRE to avoid well-known I2C hangup problems with Wire lib #160
Conversation
Not quite sure how/why the clang check failed, but the modified files compile fine for me. If there is something I can do to fix this problem, please let me know |
Adafruit is now enforcing strict code formatting rules through the clang-format utility. If you click on the failed build, and then on “clang” to expand the details, you will see the changes that clang-format requires for the test to pass. It's just about keeping the source lines within 80 characters and avoiding consecutive empty lines: --- ./RTClib.h (original)
+++ ./RTClib.h (reformatted)
@@ -25,8 +25,8 @@
#include <Arduino.h>
class TimeSpan;
-//#define USE_SBWIRE //uncomment this to use SBWire, which fixes Wire library lockup problems
-
+//#define USE_SBWIRE //uncomment this to use SBWire, which fixes Wire library
+//lockup problems
/** Registers */
#define PCF8523_ADDRESS 0x68 ///< I2C address for PCF8523
--- ./RTClib.cpp (original)
+++ ./RTClib.cpp (reformatted)
@@ -46,7 +46,8 @@
#ifdef __AVR_ATtiny85__
#include <TinyWireM.h>
#define Wire TinyWireM
-#elif defined USE_SBWIRE //Uncomment this definition in RTClib.h to avoid Wire library lockups
+#elif defined USE_SBWIRE // Uncomment this definition in RTClib.h to avoid Wire
+ // library lockups
#include <SBWire.h>
#else
#include <Wire.h> |
OK, I committed changes to satisfy clang - how do I re-run the tests? Does this happen automatically? |
another clang nitfix |
two more clang nitfixes |
@paynterf Yes, the tests are re-run automatically when you push to the branch you are asking to be pulled. It sounds like you're attempting to make the changes manually. I'd suggest letting
|
Having myself been bitten by this issue of Arduino Wire (which I then “fixed” with the watchdog), I fully appreciate the value of giving users the option to use a better I2C library. I am not convinced, however, by the approach taken by this pull request, as it requires the user to alter the source code of the library. This brings a couple of issues:
Regarding point 1, it is admittedly not very hard to document the procedure and ask the user to “uncomment I wonder whether there is a better option that doesn't require the user to modify the library sources. I guess the nicest solution would look like a template class with a default template argument that gives the user the option to instantiate their RTC as either RTC_DS1307 rtc; // based on classic Wire, for API stability or RTC_DS1307<SomeAlternativeWireImplementation> rtc; for those who want the better option. I am not sure I would be able to implement that though, as I am not very fluent with C++ templates. Mostly I fear that the presence of many |
@edgar-bonet I've not heard of the i2c hanging before, but I think that's the source of a really frusterating issue I'm having right now. I have a Ds3231 and oled connected via i2c on an stm32 (I first noticed the issue on a pro mini) and the code seems to stop at the endTransmission in the rtc begin function. Does that sound familiar? If that is my problem, I'd be in full support of adding capability for an alternate wire library, though I agree with your points about the implementation. I haven't really thought this through, but could we implement the OP's .cpp modifications, and put the #define to swap wire libraries in the user's code, above the #include <RTClib.h>? It's just a quick thought I had. If the new wire library is a drop-in replacement for the old, it should somehow be easy to implement in a clean way. |
@jadonmmiller wrote:
That won't work. The problem is that the library and the user code are compiled separately. When compiling RTClib.cpp, the compiler does not look at the user code. That is, unless the whole library is turned into a header-only library, or at least the bits accessing the hardware are all moved to the header file. Note that libraries based on templates tend to be header-only, or at lest header-heavy. |
@edgar-bonet Okay, thanks for your input! I'm by no means a good C++ programmer and hadn't considered that. There's gotta be some way to easily do it without the user modifying the library! 😃 Thanks! |
It is most likely exactly what is happening. RTC::Begin() uses Wire
(actually twi.cpp/h) functions to initialize the hardware, and the calls
are blocking calls. They don't have any timeout or other recovery schemes
implemented, so if something goes awry, the function never returns, and you
get to tear your hair out for a while (sometimes a LONG while) before
concluding that you've been had by the Arduinio code maintainers who have
refused to maintain their own thrice-damned code for over a decade (and
counting).
Frank
…On Sun, Apr 26, 2020 at 5:04 PM jadonmmiller ***@***.***> wrote:
@edgar-bonet <https://github.com/edgar-bonet> I've not heard of the i2c
hanging before, but I think that's the source of a really frusterating
issue I'm right now. I have a Ds3231 and oled connected via i2c on an stm32
(I first noticed the issue on a pro mini) and the code seems to stop at the
endTransmission in the rtc begin function.
Does that sound familiar? If that is my problem, I'd be in full support of
adding capability for an alternate wire library, though I agree with your
points about the implementation.
I haven't really thought this through, but could we implement the OP's
.cpp modifications, and put the #define to swap wire libraries in the
user's code, above the #include <RTClib.h>?
It's just a quick thought I had. If the new wire library is a drop-in
replacement for the old, it should somehow be easy to implement in a clean
way.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#160 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6T323FEZV35HN6AZ4Z4ELROSOURANCNFSM4MQ7X5PQ>
.
--
G.Frank Paynter, PhD
OSU ESL Research Scientist (ret)
EM Workbench LLC
614 638-6749 (cell)
|
The real answer to all of this IS FOR ARDUINO TO FIX THE !$@#$$%!@#%$!@#
WIRE LIBRARY. It's a trivial, well-tested fix, known to be effective for
at least a decade. Surely you guys (who maintain hundreds of repos) can
navigate the troubled waters of a pull request to Arduino's WIRE library
maintainers with a pre-clang'ed perfectly formatted PR? Heck, you don't
even have to develop or test anything - just copy/paste the SBWIRE code
into your fork of Wire.h/cpp and "Bob's your uncle!" (
https://www.youtube.com/watch?v=02Yy1vihIKs).
I would personally nominate for sainthood anyone who actually manages to
accomplish this feat in my lifetime (but you'd better hurry - I'm an old
man!)
Frank
…On Sun, Apr 26, 2020 at 5:31 PM jadonmmiller ***@***.***> wrote:
@edgar-bonet <https://github.com/edgar-bonet> Okay, thanks for your
input! I'm by no means a good C++ programmer and hadn't considered that.
There's gotta be some way to easily do it without the user modifying the
library! 😃
Thanks!
Jadon
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#160 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6T326XQ7XGNRNR3PXNUL3ROSR4XANCNFSM4MQ7X5PQ>
.
--
G.Frank Paynter, PhD
OSU ESL Research Scientist (ret)
EM Workbench LLC
614 638-6749 (cell)
|
hi looks like there is a PR open - you could politely add any notes or recommendations there |
closing this PR - it is now off topic, please fork if you need a different version of Wire |
The Arduino Wire library has a well-known hangup problem where blocking read & write calls never return. SBWire adds timeouts to all potentially blocking calls. This pull request simply adds the option to switch from the Wire library to SBWIRE.
Note that I submitted this request Feb 17, 2019 but it never got merged.