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

[I2C] Add support for multiple I2C buses #5235

Open
wants to merge 28 commits into
base: mega
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bacad99
[I2C] Add support for multiple I2C interfaces
tonhuisman Jan 29, 2025
c30cfee
[I2C] Re-order I2C variables for better alignment, add (Custom) defaults
tonhuisman Jan 30, 2025
f8cba3c
[I2C] Add conversion to adjust defaults if all zeroes
tonhuisman Jan 30, 2025
114161a
[I2C] Add more getters to SettingsStruct to simplify code
tonhuisman Jan 30, 2025
1eb141c
[I2C] Fix compilation for ESP8266
tonhuisman Jan 31, 2025
1cc8d79
[I2C] Code improvements and UI issues fixed
tonhuisman Feb 1, 2025
a8bea04
[I2C] Code improvements and UI issues fixed
tonhuisman Feb 1, 2025
406ee02
[I2C] Make I2C Interface selector reload page when needed (multiplexe…
tonhuisman Feb 2, 2025
c67cf01
[I2C] I2C Scan layout improvements
tonhuisman Feb 2, 2025
ec8a927
[I2C] Update documentation
tonhuisman Feb 2, 2025
bdbfa02
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Feb 2, 2025
7801582
Merge branch 'mega' into feature/I2C-multiple-interfaces-support
tonhuisman Feb 7, 2025
064a9a1
Merge branch 'feature/I2C-multiple-interfaces-support' of https://git…
tonhuisman Feb 8, 2025
22b02d7
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Feb 10, 2025
26c9fa8
[Libs] Avoid using Wire.begin()
tonhuisman Feb 10, 2025
c32bf94
[Device] Initialization and alignment improvements on struct
tonhuisman Feb 10, 2025
79ebde9
[I2C] GPIO (de)coupling improvements
tonhuisman Feb 10, 2025
8ae4e82
[DeviceStruct] Properly initialize DeviceStruct class
TD-er Feb 11, 2025
ebf5025
[I2C] Fix build failure on ESP8266
TD-er Feb 11, 2025
273f417
[I2C] Clean up unneeded logging
tonhuisman Feb 11, 2025
ab73437
[FormSelector] Use INT_MAX as default to avoid -1 -none- value being …
tonhuisman Feb 11, 2025
007eb4c
[I2C] Update screenshot without (default)
tonhuisman Feb 11, 2025
b280f40
[GPIO Selector] Show Wifi Status LED and Reset Pin when configured
tonhuisman Feb 11, 2025
8611b79
[I2C] Switch to correct bus for PCF/MCP GPIO monitoring
tonhuisman Feb 11, 2025
c78a087
[I2C] Show conflicting I2C bus when using multiple I2C busses
TD-er Feb 12, 2025
7812f63
[I2C] Fix saving 2nd I2C bus GPIOs
TD-er Feb 12, 2025
c28c989
[I2C] Rename "I2C Interface" to "I2C Bus"
TD-er Feb 12, 2025
876273e
[I2C] Docs: Use I2C Bus instead of I2C Interface
tonhuisman Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/source/Hardware/Device_I2CBusSelection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/Hardware/Device_I2CBusSelection3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 62 additions & 7 deletions docs/source/Hardware/Hardware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ This feature can be useful in a development/laboratory environment, for when the


-------------
I2C Interface
I2C Bus
-------------

When using devices that use the I2C bus (Inter-integrated circuit, also known as IIC, and mostly compatible with SM Bus) (`Wikipedia: I2C <https://en.wikipedia.org/wiki/I%C2%B2C>`_) some pins have to be configured, and initialized during boot, for the SDA and SCL connections. This can be any unused pair of pins on the ESP board.

The pins can be configured here, and will have default values initially (ESP8266: SDA: GPIO-4 (D2), SCL: GPIO-5 (D3), ESP32: SDA: GPIO-22, SCL: GPIO-23). When I2C is not used, these can be set to `- None -`, so the pins are available for other purposes.
The pins can be configured here, and will have default values initially (ESP8266: SDA: GPIO-4 (D2), SCL: GPIO-5 (D3), ESP32: No defaults). When I2C is not used, these can be set to `- None -`, so the pins are available for other purposes.

When having an I2C Priority task configured, the I2C GPIO pins can no longer be changed, as that could disable the hardware, thus blocking the device. The configured GPIO pins will be display-only.
When having an I2C Priority task configured, the I2C GPIO pins (for that bus, when multiple buses are available) can no longer be changed, as that could disable the hardware, thus blocking the device. The configured GPIO pins will be display-only.

The default bus clock speed can also be set here. If only devices supporting 100 kHz are connected (Old/Slow devices), then the value can be set to 100 kHz, by default 400 kHz is configured, that is supported by newer devices, though there are many devices supporting higher frequencies. ESP8266 is able to achieve ca. 400 kHz, while ESP32 allows much higher speeds.
The default bus clock speed can also be set here. If only devices supporting 100 kHz are connected (Old/Slow devices), then the value can be set to 100 kHz, by default 400 kHz is configured, that is supported by newer devices, though there are many devices supporting higher frequencies. ESP8266 is able to achieve ca. 400 kHz, while ESP32 allows higher speeds.

ESPEasy has a separate setting for Slow I2C devices, and per I2C device this slow clock speed can be selected in the Device edit page. This value is by default set to 100 kHz, but can be set lower or higher if desired.
ESPEasy has a separate setting for Slow I2C devices, and per I2C device this slow clock speed can be selected in the Device configuration page. This value is by default set to 100 kHz, but can be set lower or higher if desired.

.. image:: Hardware_I2CInterface.png
.. image:: Hardware_I2CBus.png

*Device specific Force Slow I2C speed selection:*

Expand All @@ -57,6 +57,36 @@ Added: 2023-11-23

A device flag has been added for specific devices to have **Force Slow I2C speed** set by default. After adding the device this option will be checked, but can still be unchecked to use (try) Fast I2C speed (400 kHz).

Added: 2025-02-02

Multiple I2C Buses can be configured on ESP32 builds. This aids in connecting all on-board sensors and devices when multiple GPIO pin-pairs are used for I2C devices. By default, 2 I2C Buses are made available, but via compile-time options, a 3rd I2C Bus can be enabled, if required.

.. image:: Hardware_I2CBus2.png

The available options are the same as for the first I2C Bus.

If a second (or third) I2C Bus are not needed, then leave the GPIO settings on ``- None -``, and the interface won't be initialized, and not shown in the configuration options.

NB: The second (or third) I2C Bus should of course not be configured for the same GPIO pins as any other I2C Bus.

NB2: Some boards require that in the Serial Console Settings (Tools/Advanced), the ``Fall-back to Serial 0`` option is disabled, to free the GPIO pins for I2C use.

When multiple I2C Buses are configured (so, ``SDA`` and ``SCL`` GPIO-pins configured), each task configured with an I2C device will show a selection for the I2C Bus to use. As expected, the first I2C Bus is selected by default, and another interface can be selected as required.

*Device specific I2C Bus selection:*

.. image:: Device_I2CBusSelection.png

NB: If a multiplexer is configured for 1 of the I2C Buses (but *not* for all interfaces), the I2C Bus selector will save & reload the page to show/hide the multiplexer options, below.

.. image:: Device_I2CBusSelectionReload.png

This screenshot shows the reload icon, to indicate that changing the selection will reload the page.

.. image:: Device_I2CBusSelection3.png

And an example for when 3 I2C Buses are available (compile-time option!) and configured.

---------------
I2C Multiplexer
---------------
Expand Down Expand Up @@ -106,10 +136,18 @@ All these chips/boards can be found at Adafruit, Aliexpress, Banggood, EBay, etc
.. image:: Hardware_I2CMultiplexer_Address.png


Added: 2025-02-02

With the introduction of multiple I2C Buses, it is also plausible to configure an I2C Multiplexer on the second (or third, when included in the build) I2C Bus.

.. image:: Hardware_I2CMultiplexer2.png

This allows the same configuration options as shown above for the first I2C Bus, as all I2C Buses are completely independent from each other.

Device configuration
^^^^^^^^^^^^^^^^^^^^

If an I2C multiplexer is configured, every Device edit page for I2C devices will show extra options to select the channel the device is connected on.
If an I2C multiplexer is configured for the selected I2C Bus, the Device edit page for I2C devices will show extra options to select the multiplexer channel the device is connected on.

There is the default option of Single channel, or, when a TCA9548a, TCA9546a or TCA9543a is configured, Multiple channels.

Expand All @@ -136,6 +174,23 @@ Above configuration results in channels 0, 4, 5, 6 and 7 being connected to the
NB: Only acceptable channel checkboxes (0-7/0-3/0-1) will be shown, depending on the Multiplexer type configured.


--------------------
PCF & MCP Direct I/O
--------------------

Added: 2025-02-02

For interacting with the PCF8574 or MCP23017 GPIO Extenders no Device Task is required, so no I2C Bus configuration is available.

When multiple I2C Buses are configured (ESP32 only), we need some configuration to overcome that situation, to avoid having to connect these I/O extenders on the first I2C Bus.

.. image:: Hardware_PCFMCP_I2CSelector.png

When using multiple PCF and/or MCP GPIO extenders, they must all be connected to this I2C Bus, and any Device Tasks should also use the same I2C Bus.

NB: If only 1 I2C Bus is configured, this section isn't shown.


-------------
SPI Interface
-------------
Expand Down
Binary file added docs/source/Hardware/Hardware_I2CBus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/Hardware/Hardware_I2CBus2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/source/Hardware/Hardware_I2CInterface.png
Binary file not shown.
Binary file added docs/source/Hardware/Hardware_I2CMultiplexer2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 29 additions & 1 deletion docs/source/Tools/Tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ This allows ESPEasy to know the correct date and time after been powered off for

N.B. these modules all use I2C, so they need to be connected to the configured I2C pins and those pins should be set.

Added: 2025-02-02

When multiple I2C Buses are configured (ESP32 only), we need to configure on which I2C Bus the RTC chip is connected:

.. image:: images/Tools_RTC_I2CSelector.png

NB: If only 1 I2C Bus is configured, this configuration option isn't shown.


Procedure to configure a real time clock (RTC) chip:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -409,6 +418,15 @@ WD I2C Address
The Watchdog timer can be accessed via I2C.
What can be read/set/changed must still be documented.

Added: 2025-02-02

When multiple I2C Buses are configured (ESP32 only), we need to configure on which I2C Bus the Watchdog chip is connected:

.. image:: images/Tools_WD_I2CSelector.png

NB: If only 1 I2C Bus is configured, this configuration option isn't shown.


JSON bool output without quotes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -936,7 +954,7 @@ Interfaces
I2C Scan
========

To verify if any connected I2C devices are properly detected by the ESP, the I2C Scan is available. This will scan the I2C bus, and, when configured, the additional busses provided via an I2C multiplexer, for available devices.
To verify if any connected I2C devices are properly detected by the ESP, the I2C Scan is available. This will scan the I2C bus, and, when configured, the additional buses/channels provided via an I2C multiplexer, for available devices.

The scan is performed if the I2C ``SDA`` and ``SCL`` GPIO pins are configured on the Hardware page, and will use the configured ``Slow device Clock Speed`` setting (default: 100 kHz) during the scan, as that should be supported by any I2C device available.

Expand All @@ -950,9 +968,19 @@ Example scan using an I2C multiplexer, showing multiple devices across multiple

.. image:: images/Tools_I2Cscan_multiplexer.png

Added: 2025-02-02

When having multiple I2C Buses configured, for each configured interface an I2C Scan is performed, including the multiplexer if that's configured.

An example: (No actual multiplexer connected...)

.. image:: images/Tools_I2Cscan_multipleBuses.png

|

.. note:: On builds that have ``LIMIT_BUILD_SIZE`` set, like the ESP8266 Collection and Display builds, the names of the supported devices and plugins are **not** included in the output, only the address(es) are listed.

|

Settings
********
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/Tools/images/Tools_WD_I2CSelector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Sodaq_UBlox_GPS::resetValues()
void Sodaq_UBlox_GPS::init(int8_t enable_pin)
{
_enablePin = enable_pin;
Wire.begin();
// Wire.begin(); ESPEasy has already taken care of this
digitalWrite(_enablePin, GPS_ENABLE_OFF);
pinMode(_enablePin, OUTPUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Sodaq_UBlox_GPS::resetValues()
void Sodaq_UBlox_GPS::init(int8_t enable_pin)
{
_enablePin = enable_pin;
Wire.begin();
// Wire.begin(); ESPEasy has already taken care of this
digitalWrite(_enablePin, GPS_ENABLE_OFF);
pinMode(_enablePin, OUTPUT);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SparkFun_ADXL345_Arduino_Library/src/SparkFun_ADXL345.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ ADXL345::ADXL345(int CS) {
}

void ADXL345::powerOn() {
if (I2C) {
Wire.begin(); // If in I2C Mode Only
}
// if (I2C) {
// Wire.begin(); // If in I2C Mode Only ESPEasy has already taken care of this
// }

// ADXL345 TURN ON
writeTo(ADXL345_POWER_CTL, 0); // Wakeup
Expand Down
2 changes: 1 addition & 1 deletion lib/esp8266-oled-ssd1306/SH1106Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_scl(scl) {}

bool SH1106Wire::connect() {
Wire.begin(this->_sda, this->_scl);
// Wire.begin(this->_sda, this->_scl); // ESPEasy already has Wire initialized properly
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/esp8266-oled-ssd1306/SSD1306Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

bool SSD1306Wire::connect() {
Wire.begin(this->_sda, this->_scl);
// Wire.begin(this->_sda, this->_scl); // ESPEasy already has Wire initialized properly
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Custom-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
#ifdef ESP32
#define DEFAULT_PIN_I2C_SCL -1 // Undefined
#endif
#define DEFAULT_PIN_I2C2_SDA -1 // Undefined
#define DEFAULT_PIN_I2C3_SDA -1 // Undefined
#define DEFAULT_PIN_I2C3_SCL -1 // Undefined
#define DEFAULT_PIN_I2C3_SCL -1 // Undefined
#define DEFAULT_I2C_CLOCK_SPEED 400000 // Use 100 kHz if working with old I2C chips
#define FEATURE_I2C_DEVICE_SCAN 1

Expand Down
9 changes: 7 additions & 2 deletions src/_P017_PN532.ino
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ bool P017_handle_timer_in(struct EventStruct *event)
# endif // ifdef P017_DEBUG_LOGIC_ANALYZER_PIN

// TODO: Clock stretching issue https://github.com/esp8266/Arduino/issues/1541
if (Settings.isI2CEnabled()
&& ((DIRECT_pinRead(Settings.Pin_i2c_sda) == 0) || (DIRECT_pinRead(Settings.Pin_i2c_scl) == 0)))
#if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = Settings.getI2CInterface(event->TaskIndex);
#else
const uint8_t i2cBus = 0;
#endif // if FEATURE_I2C_MULTIPLE
if (Settings.isI2CEnabled(i2cBus)
&& ((DIRECT_pinRead(Settings.getI2CSdaPin(i2cBus)) == 0) || (DIRECT_pinRead(Settings.getI2CSclPin(i2cBus)) == 0)))
{
addLog(LOG_LEVEL_ERROR, F("PN532: BUS error"));
Plugin_017_Init(CONFIG_PIN3);
Expand Down
9 changes: 7 additions & 2 deletions src/_P036_FrameOLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,17 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
P036_CheckHeap(F("_INIT: Before P036_data->init()"));
# endif // P036_CHECK_HEAP

#if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = Settings.getI2CInterface(event->TaskIndex);
#else
const uint8_t i2cBus = 0;
#endif // if FEATURE_I2C_MULTIPLE
if (!(P036_data->init(event->TaskIndex,
get4BitFromUL(P036_FLAGS_0, P036_FLAG_SETTINGS_VERSION), // Bit23-20 Version CustomTaskSettings
P036_CONTROLLER, // Type
P036_ADR, // I2C address
Settings.Pin_i2c_sda,
Settings.Pin_i2c_scl,
Settings.getI2CSdaPin(i2cBus),
Settings.getI2CSclPin(i2cBus),
static_cast<p036_resolution>(P036_RESOLUTION), // OLED index
(P036_ROTATE == 2), // 1 = Normal, 2 = Rotated
P036_CONTRAST,
Expand Down
2 changes: 1 addition & 1 deletion src/_P139_AXP2101.ino
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ boolean Plugin_139(uint8_t function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
if (Settings.isI2CEnabled()) {
if (Settings.isI2CEnabled(Settings.getI2CInterface(event->TaskIndex))) { // FIXME
P139_data_struct *P139_init = static_cast<P139_data_struct *>(getPluginTaskData(event->TaskIndex));

if (nullptr != P139_init) {
Expand Down
2 changes: 1 addition & 1 deletion src/_P166_GP8403.ino
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ boolean Plugin_166(uint8_t function, struct EventStruct *event, String& string)

case PLUGIN_INIT:
{
if (Settings.isI2CEnabled()) {
if (Settings.isI2CEnabled(Settings.getI2CInterface(event->TaskIndex))) {
initPluginTaskData(event->TaskIndex,
new (std::nothrow) P166_data_struct(P166_I2C_ADDRESS,
static_cast<DFRobot_GP8403::eOutPutRange_t>(P166_MAX_VOLTAGE)));
Expand Down
16 changes: 16 additions & 0 deletions src/src/Commands/GPIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "../Helpers/PortStatus.h"
#include "../Helpers/Numerical.h"

#if FEATURE_I2C_MULTIPLE
#include "../Globals/Settings.h"
#include "../Helpers/Hardware_device_info.h"
#include "../Helpers/I2C_access.h"
#endif // if FEATURE_I2C_MULTIPLE

#if FEATURE_GPIO_USE_ESP8266_WAVEFORM
# include <core_esp8266_waveform.h>
#endif
Expand Down Expand Up @@ -1216,6 +1222,11 @@ bool getGPIOPinStateValues(String& str) {
#if FEATURE_PINSTATE_EXTENDED
pluginID = PLUGIN_MCP;
#endif // if FEATURE_PINSTATE_EXTENDED
#if FEATURE_I2C_MULTIPLE
if (getI2CBusCount() >= 2) {
I2CSelectHighClockSpeed(Settings.getI2CInterfacePCFMCP());
}
#endif // if FEATURE_I2C_MULTIPLE
str = GPIO_MCP_Read(par1);
#ifndef BUILD_NO_DEBUG
logPrefix = F("MCP");
Expand All @@ -1229,6 +1240,11 @@ bool getGPIOPinStateValues(String& str) {
#if FEATURE_PINSTATE_EXTENDED
pluginID = PLUGIN_PCF;
#endif // if FEATURE_PINSTATE_EXTENDED
#if FEATURE_I2C_MULTIPLE
if (getI2CBusCount() >= 2) {
I2CSelectHighClockSpeed(Settings.getI2CInterfacePCFMCP());
}
#endif // if FEATURE_I2C_MULTIPLE
str = GPIO_PCF_Read(par1);
#ifndef BUILD_NO_DEBUG
logPrefix = F("PCF");
Expand Down
37 changes: 22 additions & 15 deletions src/src/Commands/i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,34 @@ void i2c_scanI2Cbus(bool dbg, int8_t channel) {

const __FlashStringHelper* Command_i2c_Scanner(struct EventStruct *event, const char *Line)
{
if (Settings.isI2CEnabled()) {
const bool dbg = equals(parseString(Line, 2), F("1"));
I2CSelect_Max100kHz_ClockSpeed(); // Scan bus using low speed
const bool dbg = equals(parseString(Line, 2), F("1"));
#if !FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = 0;
#else // if !FEATURE_I2C_MULTIPLE
for (uint8_t i2cBus = 0; i2cBus < getI2CBusCount(); ++i2cBus)
#endif // if !FEATURE_I2C_MULTIPLE
{
if (Settings.isI2CEnabled(i2cBus)) {
I2CSelect_Max100kHz_ClockSpeed(i2cBus); // Scan bus using low speed

i2c_scanI2Cbus(dbg, -1); // Base I2C bus
i2c_scanI2Cbus(dbg, -1); // Base I2C bus

#if FEATURE_I2CMULTIPLEXER
#if FEATURE_I2CMULTIPLEXER

if (isI2CMultiplexerEnabled()) {
uint8_t mux_max = I2CMultiplexerMaxChannels();
if (isI2CMultiplexerEnabled(i2cBus)) {
uint8_t mux_max = I2CMultiplexerMaxChannels(i2cBus);

for (int8_t channel = 0; channel < mux_max; ++channel) {
I2CMultiplexerSelect(channel);
i2c_scanI2Cbus(dbg, channel); // Multiplexer I2C bus
for (int8_t channel = 0; channel < mux_max; ++channel) {
I2CMultiplexerSelect(i2cBus, channel);
i2c_scanI2Cbus(dbg, channel); // Multiplexer I2C bus
}
I2CMultiplexerOff(0);
}
I2CMultiplexerOff();
#endif // if FEATURE_I2CMULTIPLEXER
} else {
serialPrintln(F("I2C : Not enabled."));
}
#endif // if FEATURE_I2CMULTIPLEXER
I2CSelectHighClockSpeed(); // By default the bus is in standard speed
} else {
serialPrintln(F("I2C : Not enabled."));
}
I2CSelectHighClockSpeed(0); // By default the bus is in standard speed
return return_see_serial(event);
}
12 changes: 12 additions & 0 deletions src/src/CustomBuild/ESPEasyDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@
#define DEFAULT_PIN_I2C_SDA -1 // Undefined
#endif
#endif
#ifndef DEFAULT_PIN_I2C2_SDA
#define DEFAULT_PIN_I2C2_SDA -1 // Undefined
#endif
#ifndef DEFAULT_PIN_I2C3_SDA
#define DEFAULT_PIN_I2C3_SDA -1 // Undefined
#endif
#ifndef DEFAULT_PIN_I2C_SCL
#ifdef ESP8266
#define DEFAULT_PIN_I2C_SCL 5
Expand All @@ -228,6 +234,12 @@
#define DEFAULT_PIN_I2C_SCL -1 // Undefined
#endif
#endif
#ifndef DEFAULT_PIN_I2C2_SCL
#define DEFAULT_PIN_I2C2_SCL -1 // Undefined
#endif
#ifndef DEFAULT_PIN_I2C3_SCL
#define DEFAULT_PIN_I2C3_SCL -1 // Undefined
#endif
#ifndef DEFAULT_I2C_CLOCK_SPEED
#define DEFAULT_I2C_CLOCK_SPEED 400000 // Use 100 kHz if working with old I2C chips
#endif
Expand Down
Loading
Loading