So, I had a weird one today while coding using Arduino on an ESP32-S3.
The project I'm working on uses both I2C buses on the device, a screen on BUS0 and a temp sensor and energy monitor on BUS1
The library that the energy meter chip uses, is hard coded to use only the "Wire" object but I know from other parts of my code that the following is true:
Wire == BUS0 == I2C0
Wire1 == BUS1 == I2C1
I ran the sample program for the energy monitor (Who's libs are hard coded to use Wire), and was surprised to see that it picked up the monitor and started to read it without any extra config telling it that it was on a different bus.
My own code however, in my own project using the exact same library consistently failed to read (again due to the device being on BUS1 and the libs using BUS0)
My own code I now know was doing the correct thing.
the default "hardware" configuration on the boards we are using however have the default pins for I2C0 (8 & 9) set as the defaults for I2C1 and (15 & 16) as the defaults for I2C0
The library we assume was using "default" pins (We couldn't find anywhere in the lib source code where the pins for the I2C where assigned), since 8 & 9 are the default for I2C0, we further assumed the example sketch was able to work because Wire using what it thinks are normal defaults, was actually looking at I2C1 by default, but as there is no way, and it worked in terms of I2C the Arduino wire library's didn't question it, and set Wire up to point to BUS1 thinking it was talking to BUS0.
With regards to Wire setting itself up for defaults specifically on Arduino on ESP32-S3 doe anyone know how the default detection is performed and/or set-up, and more specifically is it possible to have Wire1 and Wire mapped the wrong way round?
We've fixed the problem for now by making a local copy of the library and including it directly in the project, then replacing all the "Wire" instances with "Wire1", I may even alter the lib to allow wire config to be passed in and submit a pull request for them, for now however I'd like to try and at least work out how a lib hard coded for I2C0 could see and access a device on I2C1