Arduino I2C Wire-Fehler beheben: call of overloaded 'begin(const int&, const int&, int)' is ambiguous
English
Deutsch
Problem:
Man versucht, Wire.begin() für I2C aufzurufen mit
i2c_begin_example.ino
Wire.begin(Pin_I2C_SDA, Pin_I2C_SCL, 400000);aber man erhält eine Fehlermeldung wie
i2c_compile_error.txt
src/NyI2C.cpp:139:47: error: call of overloaded 'begin(const int&, const int&, int)' is ambiguous
src/MyI2C.cpp: In function 'void MyInitI2C()':
src/NyI2C.cpp:139:47: error: call of overloaded 'begin(const int&, const int&, int)' is ambiguous
Wire.begin(Pin_I2C_SDA,Pin_I2C_SCL, 400000);
^
In file included from include/MyIO.hpp:2:0,
from src/MyI2C.cpp:2:
/home/uli/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src/Wire.h:79:10: note: candidate: bool TwoWire::begin(int sda=-1, int scl=-1, uint32_t frequency=0)
bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
^
/home/uli/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src/Wire.h:80:10: note: candidate: bool TwoWire::begin(uint8_t, int, int, uint32_t)
bool begin(uint8_t slaveAddr, int sda=-1, int scl=-1, uint32_t frequency=0);Lösung
Dies tritt bei bestimmten Versionen des Arduino-Frameworks auf. Für mich passierte es speziell beim Upgrade auf arduino-esp32 Version 2.0.1.
Man muss das dritte Argument (400000) explizit nach uint32_t casten, um dem Compiler mitzuteilen, welche der beiden Funktionen aufgerufen werden soll:
i2c_begin_cast_example.ino
Wire.begin(Pin_I2C_SDA, Pin_I2C_SCL, (uint32_t)400000);Check out similar posts by category:
Arduino, C/C++, Embedded, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow