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

[Bug]: RP2040 - Wire.begin does not accept two arguments with SDA/SCL pins #3032

Closed
Mictronics opened this issue Dec 23, 2023 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@Mictronics
Copy link
Contributor

Category

Hardware Compatibility

Hardware

Raspberry Pi Pico (W)

Firmware Version

2.2.17

Description

The actual firmware doesn't build for RP2040 when the I2C_0 or I2C_1 pins are redefined via I2C_SDA or I2C_SDA1.

In main.cpp, line 372:

#ifdef I2C_SDA1
    Wire1.begin(I2C_SDA1, I2C_SCL1);
#endif

#ifdef I2C_SDA
    Wire.begin(I2C_SDA, I2C_SCL);
#elif HAS_WIRE
    Wire.begin();
#endif

and line 426:

#ifdef I2C_SDA1
    Wire1.begin(I2C_SDA1, I2C_SCL1);
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1);
#endif

#ifdef I2C_SDA
    Wire.begin(I2C_SDA, I2C_SCL);
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE);
#elif HAS_WIRE
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE);
#endif

the Wire.begin function is called with two arguments to set the SDA and SCL pins. However, the Arduino Pico Framework library Wire has no begin that accept two arguments for pin change. Done via setSDA and setSCL.

Not sure if other hardware needs that specific Wire.begin call but a possible fix for the RP2040 might be:

#if defined(I2C_SDA1) && defined(ARCH_RP2040)
    Wire1.setSDA(I2C_SDA1);
    Wire1.setSCL(I2C_SCL1);
    Wire1.begin();
#elif defined(I2C_SDA1) && !defined(ARCH_RP2040)
    Wire1.begin(I2C_SDA1, I2C_SCL);
#endif

#if defined(I2C_SDA) && defined(ARCH_RP2040)
    Wire.setSDA(I2C_SDA);
    Wire.setSCL(I2C_SCL);
    Wire.begin();
#elif defined(I2C_SDA) && !defined(ARCH_RP2040)
    Wire.begin(I2C_SDA, I2C_SCL);
#elif HAS_WIRE
    Wire.begin();
#endif
#if defined(I2C_SDA1) && defined(ARCH_RP2040)
    Wire1.setSDA(I2C_SDA1);
    Wire1.setSCL(I2C_SCL1);
    Wire1.begin();
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1);
#elif defined(I2C_SDA1) && !defined(ARCH_RP2040)
    Wire1.begin(I2C_SDA1, I2C_SCL1);
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1);
#endif

#if defined(I2C_SDA) && defined(ARCH_RP2040)
    Wire.setSDA(I2C_SDA);
    Wire.setSCL(I2C_SCL);
    Wire.begin();
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE);
#elif defined(I2C_SDA) && !defined(ARCH_RP2040)
    Wire.begin(I2C_SDA, I2C_SCL);
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE);
#elif HAS_WIRE
    i2cScanner->scanPort(ScanI2C::I2CPort::WIRE);
#endif

Relevant log output

Using meshtastic platformio-custom.py, firmware version 2.2.17.db8f8db8
Compiling .pio/build/pico_waveshare/src/main.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:373:16: error: no matching function for call to 'TwoWire::begin(int, int)'
  373 |     Wire1.begin(I2C_SDA1, I2C_SCL1);
      |     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from .pio/libdeps/pico_waveshare/Adafruit BusIO/Adafruit_I2CDevice.h:5,
                 from .pio/libdeps/pico_waveshare/Adafruit BusIO/Adafruit_BusIO_Register.h:9,
                 from .pio/libdeps/pico_waveshare/Adafruit INA219/Adafruit_INA219.h:21,
                 from src/modules/Telemetry/Sensor/INA219Sensor.h:4,
                 from src/power.h:26,
                 from src/main.cpp:11:
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:42:10: note: candidate: 'virtual void TwoWire::begin()'
   42 |     void begin() override;
      |          ^~~~~
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:42:10: note:   candidate expects 0 arguments, 2 provided
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:44:10: note: candidate: 'virtual void TwoWire::begin(uint8_t)'
   44 |     void begin(uint8_t address) override;
      |          ^~~~~
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:44:10: note:   candidate expects 1 argument, 2 provided
src/main.cpp:427:16: error: no matching function for call to 'TwoWire::begin(int, int)'
  427 |     Wire1.begin(I2C_SDA1, I2C_SCL1);
      |     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:42:10: note: candidate: 'virtual void TwoWire::begin()'
   42 |     void begin() override;
      |          ^~~~~
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:42:10: note:   candidate expects 0 arguments, 2 provided
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:44:10: note: candidate: 'virtual void TwoWire::begin(uint8_t)'
   44 |     void begin(uint8_t address) override;
      |          ^~~~~
/home/lupus/.platformio/packages/framework-arduinopico/libraries/Wire/src/Wire.h:44:10: note:   candidate expects 1 argument, 2 provided
*** [.pio/build/pico_waveshare/src/main.cpp.o] Error 1
@Mictronics Mictronics added the bug Something isn't working label Dec 23, 2023
@GUVWAF
Copy link
Member

GUVWAF commented Dec 26, 2023

The change you propose looks fine to me.

Seems for nRF52 it needs to be done with setPins, but there's currently no nRF52 variant using a second I2C with Meshtastic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants