Closed heliophagus closed 2 years ago
Can't say that I've seen this in the example code, but since you seem to be able to repro it I'd recommend you start looking at the lines https://github.com/earlephilhower/arduino-pico/blob/d689165a390401bd0ac3356d57bfd32cffe26fc2/libraries/Wire/src/Wire.cpp#L136-L139
These set the GPIO pins to I2C with weak onchip pullups (100K or so?) and under control of the I2C HW itself.
One possibility would be to
gpio_set_dir(_sda, false);
gpio_put(_sda, 0);
gpio_set_dir(_scl, false);
gpio_put(_scl, 0);
on the 2 pins, but I believe the I2C HW actually controls the OEs anyway.
The other possibility is the HW FIFO read is going wacky in https://github.com/earlephilhower/arduino-pico/blob/d689165a390401bd0ac3356d57bfd32cffe26fc2/libraries/Wire/src/Wire.cpp#L171-L178
Thanks for the reply. I must confess to being exceedingly dense (neutron star grade). The solution was staring me in the face & I just didn't see it. In the target code, where I was expecting i2c input on channel 1, not channel 0 (Wire1, not Wire), I used the line
rCommand = Wire.read();
when it should have been
rCommand = Wire1.read();
Of course, because nothing was being received on channel 0, reading from it returned -1 as an int which got truncated to 0xFF as a byte.
Thanks for answering, though. I learned something from the code you referenced.
And now, I'll see myself out.
Greetings. Here's a problem that I've been battling for a couple of days now. Any help would be appreciated!
I am setting up an RP2040 as a target i2c device. The controller is an ESP32. When doing a minimal test of this setup, any bytes sent from the controller ("master") are correctly sent, as validated by a logic analyzer (Kingst LA1010, which works nicely). However, on the RP2040, they are invariably received as 255. I have tried pullups ranging from 10k down to 1k with no effect. The i2c lines are short (about 20 cm).
The sent bytes reliably trigger the receive event on the RP2040, but because they are always "read" as 255, they trigger the return of an error float (-255) rather than return of the test data. I started off with the Example code for "TalkingToMyself", with the target and controller on the same chip, which usually worked as expected but also read received bytes in the range 0 ... 5 as 255, though only about 10% of the time as opposed to 100% of the time. Unfortunately there is a mission-critical need for code running on an ESP32 to read sensor data via i2c from an RP2040. So, using a single chip is not an option.
Here is the code for the controller, running on an ESP32, with the correct i2c outputs verified using a logic analyzer:
And here is code running on the target (RP2040):
Maybe I'm just being dense! But, I cannot get this to work, and would greatly appreciate any help I can get.