Skip to content

Custom TwoWire and begin() #237

Description

@thijstriemstra

#231 (1.14.0) added the option to use a custom TwoWire instance, which is great.

1.13.0 RTCLib's begin looked like this:

boolean RTC_DS3231::begin() {
  Wire.begin();
  Wire.beginTransmission(DS3231_ADDRESS);
  if (Wire.endTransmission() == 0)
    return true;
  return false;
}

it now looks like this:

boolean RTC_DS3231::begin(TwoWire *wireInstance) {
  RTCWireBus = wireInstance;
  RTCWireBus->begin();
  RTCWireBus->beginTransmission(DS3231_ADDRESS);
  if (RTCWireBus->endTransmission() == 0)
    return true;
  return false;
}

In my application I use custom SDA/SCL so I choose not to use RTC_DS3231::begin() but use my own that uses this begin call:

  // rtc
  Wire.begin(_sdaPin, _sclPin);
  Wire.beginTransmission(DS3231_ADDRESS);
  if (Wire.endTransmission() != 0) {
    Log.warning(F("Initializing DS3231... Error!" CR));
  }

In the latest version (1.14.0) I can't do this because begin now sets a protected var that I can't set from my code:

boolean RTC_DS3231::begin(TwoWire *wireInstance) {
  RTCWireBus = wireInstance;
  // etc..

I can also not use Wire.setPins(x, y) because the code still calls begin on Wire, which I want to do elsewhere.

So I'm stuck with 1.13.0. Any ideas how to work around this pesky situation?

cc @ubidefeo

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