-
Notifications
You must be signed in to change notification settings - Fork 7.6k
I2C still not working #90
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
Comments
what is that slave device that you are trying to access? |
MPU9250 and MS5637. |
OK, I confirmed I can read the I2C pressure/temperature sensor MS5637, which essentially uses one byte at a time for reads and writes. Here is the sketch that works just fine:
But if I try to read the MPU9250 which requires write of a device address, then a register address (more than one byte), then I can not read any data from it. Here is the multi-byte I2C function:
Some how the second byte is causing the I2C bus to get hing up. Not sure why but this is the reason most I2C devices cannot be read by the ESP32 except for the very simple (command and response types) ones. Although now that I look at both readByte functions, they look pretty similar so now I don't know why one works and one does not. |
@kriswiner hey man can you please explain how did you connect the MS5637 to the esp32 im trying to conect the mpu6050 motion sensor but i failed |
I connected pin 21 to SDA, pin 22 to SCL and then 3V3 and GND. But this won't help you since i can't get anything but the I2C address out of the companion MPU9250. There is something different about the Invensense I2C bus/controller that is causing the I2C bus to latch up. Might be a clock stretching issue. I have seen this before on the ESP8266/85. I am using 4K7 pullips on the I2C lines, which usually works for a variety of controllers including the ESP8266/85. But somehow the ESP32 is having trouble with it. |
So now what is the solution if i wanna get the motion sensor connected to esp32 i tried alot to find in the internet i did not fine anything |
Don't know, I'd like to get the other I2C sensors working as well. I am going to test more but I have not been able to get the MPU9250 to work yet. Lokks like we will both have to just wait until this is fixed. Or go backt o using the ESP8266/85! |
Okay man if i got anything i will post it here and let u know ,good luck |
guys calm down :) i'm working on it and so far I can read MPU fine. Update will be up soon. |
No disresepect intended, you guys are doing great work! Just trying to do my part ;> I am looking forward to your fix. |
issue with MPU was directly connected to the fact that before you read from it, you do not send stop (Wire.endTransfer(false)). Now that I have that fixed, I can not write more than 9 bytes to I2C... cat and mouse with this bus |
please try the latest commit |
I just tried the new core and I am still having the same problem. I can see the I2C devices on the bus but cannot read from the MPU9250 WHO_AM_I register. This is the output I get:
I verified I can still get data from the MS5637 alone. That is, if I only ask for MS5637 data, read and write from/to MS5637 only then everything works, but when I try to talk with the MPU9250 the bus gets stuck and I can't talk to either. |
I also verified that I can get data from the VEML6040 I2C RGBW sensor. So some work and some don't. Odd... |
But cannot read the BMX055:
|
@kriswiner Can you try adding another Wire.beginTransmission to get the result instead of using endTransmission(false)? Just curious, I haven't received my ESP32 yet to help test. If it works.. might be a hint.
Change to...
|
I tried this:
|
const uint8_t MPU_addr=0x68; // I2C address of the MPU-6050
#define WHO_AM_I_MPU9250 0x75 // Should return 0x71
uint8_t mpuWhoAmI()
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(MPU_addr); // Initialize the Tx buffer
Wire.write(WHO_AM_I_MPU9250); // Put slave register address in Tx buffer
Wire.endTransmission(true); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(MPU_addr, (uint8_t) 2); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
Wire.read();
return data; // Return data read from slave register
}
|
Just tested manually and the MPU does not release SDA until it gets another 8 clocks. |
Tried the fix and it seems to work. I can read the MPU9250 and AK8963C. The fusion rate I measure is 20 kHz (compare to 60 kHz with STM32L4) but the fusion is not behaving properly because of the lack of floating point sqrt and sin/tan functions I think. Anyway, this I2C issue ios solved. There is one curious problem I am having. I was polling the data ready register bit of the AK8963C to test whether bnew data was available. Now that I am reading the next byte, which is the first data byte, it is clearing the data registers so I have had to abandong the data ready test to read the data. Oh well, can't have everything! I have reposited working ESP32 Arduino sketches here: https://github.com/kriswiner/ESP32 I have sketches for the MPU9250+MS5637, MS5637, VEML6040 and will be adding more as I can test other sensors. |
awesome! BTW you should not need to read two bytes anymore :) I found the reason why one byte was not working and I hope I fixed it. So you are welcome to try reading one byte again. |
I tested the BNO055 and it works with the extra read byte also. I will download the latest and try without it next. |
Tried the latest with reading no extra byte and this does not work. Reading the extra byte does work. |
With the latest version: "works" means that not only recognition but also communication works. Great, it gets better and better. Until this version BMP180 did not work. That looks good:
|
I'm reading the documentation for the chips and I'm looking at the decoded data by my logic analyzer and all looks exactly as it should, so I do not get why the extra byte would be needed here and not on other platforms |
I am just trying to use the above code which is a clip from your code. I don't seem to be having the clock working. |
Yup, that should work, sure you have the I2C addresses correct? What
happens if you just run an I2C scan?
Maybe your dev board is busted...
…On Tue, Oct 17, 2017 at 3:13 PM, muktillc ***@***.***> wrote:
I am just trying to use the above code which is a clip from your code. I
don't seem to be having the clock working.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qhQ4Ut6B843uaUsg-Sbq5BgaVbNXks5stSZ3gaJpZM4LKA2r>
.
|
the blink program and the internet connectivity works. I am using 10k pull up resistors. Do you recommend me using any other pins for I2C? If I want to use any other pins, I just need to change the number in the wire.begin() to the other pin number, right? Do I have to change anything else? I was also wondering that how does the ESP32 know that pins are being used for I2C. I don't see that being mentioned anywhere. |
what is the I2C_Scan() function doing? Do I have first include the function in my code first? |
You tell it via wire.begin(sda/scl);
You need to add a i2c scan function.
…On Tue, Oct 17, 2017 at 3:38 PM muktillc ***@***.***> wrote:
what is the I2C_Scan() function doing? Do I have first include the
function in my code first?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qqe4ynwaPmNzWgycDkAPlBYPBNPsks5stSxbgaJpZM4LKA2r>
.
|
the board is not busted. I just wrote a code to output 1kHz at pin 22 and it works. I am getting 1kHz output |
Sounds like a problem for the ESP32 forum...
…On Tue, Oct 17, 2017 at 5:44 PM, muktillc ***@***.***> wrote:
the board is not busted. I just wrote a code to output 1kHz at pin 22 and
it works. I am getting 1kHz output
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1ql1B-CdSpYfTOiadALoRgYrPlYWSks5stUnngaJpZM4LKA2r>
.
|
Are you using the latest Arduino core?
…On Tue, Oct 17, 2017 at 5:53 PM, Kris Winer ***@***.***> wrote:
Sounds like a problem for the ESP32 forum...
On Tue, Oct 17, 2017 at 5:44 PM, muktillc ***@***.***>
wrote:
> the board is not busted. I just wrote a code to output 1kHz at pin 22 and
> it works. I am getting 1kHz output
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#90 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AGY1ql1B-CdSpYfTOiadALoRgYrPlYWSks5stUnngaJpZM4LKA2r>
> .
>
|
I am getting the above clock. the saw shape clock does not make sense to me. |
Is the frequency 40 Hz?
…On Tue, Oct 17, 2017 at 6:03 PM, muktillc ***@***.***> wrote:
I am getting the above clock. the saw shape clock does not make sense to
me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qvarQBP-NbL_SzUbOsjCP68_7nB2ks5stU5EgaJpZM4LKA2r>
.
|
no. it is 400kHz. the X axis is set to 20us/div |
when you say Arduino core, you mean the version of the Arduino IDE, right? I installed it only a week ago. |
No, I mean the ESP32 Arduino core.
…On Tue, Oct 17, 2017 at 7:07 PM, muktillc ***@***.***> wrote:
when you say Arduino core, you mean the version of the Arduino IDE, right?
I installed it only a week ago.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qkiQpIUEkMz2kT6VeTfTawPxtI4Aks5stV15gaJpZM4LKA2r>
.
|
Which board are you choosing for your ESP device?
…On Tue, Oct 17, 2017 at 7:15 PM, Kris Winer ***@***.***> wrote:
No, I mean the ESP32 Arduino core.
On Tue, Oct 17, 2017 at 7:07 PM, muktillc ***@***.***>
wrote:
> when you say Arduino core, you mean the version of the Arduino IDE,
> right? I installed it only a week ago.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#90 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AGY1qkiQpIUEkMz2kT6VeTfTawPxtI4Aks5stV15gaJpZM4LKA2r>
> .
>
|
I am using the DOIT ESP32 development board. The ESP32 Arduino core was downloaded last night. |
I am asking which board do you choose in the board manager?
…On Tue, Oct 17, 2017 at 7:19 PM, muktillc ***@***.***> wrote:
I am using the DOIT ESP32 development board. The ESP32 Arduino core was
downloaded last night.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qk1NdlJQA4bAn-JrWBq8cS1jWDmTks5stWBCgaJpZM4LKA2r>
.
|
I am selecting ESP32 Dev Module. |
@me-no-dev. Do you have any comments on this issue that I am facing. |
@muktillc , Is your pullup really 10K? Philips Electronics( the inventor of the I2C bus) specifies the pullup current to be from 3mA to 20mA. A 10k pullup with 3.3v only provides 0.33mA. I am using I2C with a WeMos Bluetooth&Battery. I am having a different problem with I2C, once in a while, the SDA is driven low continuously from the ESP32. A Wire.begin() will not fix it, but a RESET usually will. I think the Wire library is either leaving SDA as an output and Waiting for the bus to clear(it never does) or the Hardware is glitching. I am decoding the I2C section to see if I can find this problem. Chuck. |
4K7 pullups work well in most cases.If you are seeing 3V3 on SDA/SCL then
you have a different problem.
…On Tue, Oct 17, 2017 at 9:43 PM, chuck todd ***@***.***> wrote:
@muktillc <https://github.com/muktillc> , Is your pullup really 10K?
Philips Electronics( the inventor of the I2C bus) specifies the pullup
current to be from 3mA to 20mA.
Philips AppNote (UM10204)
A 10k pullup with 3.3v only provides 0.33mA.
Your sawtooth waveform is that 0.33mA driving the buss capacitance.
You are trying to run the bus at 400kHz with weak pullups
Change your pullups to 1k for 3.3v
I am using I2C with a WeMos Bluetooth&Battery.
I have both 5v devices and 3.3v devices. I use a Sparkfun Level converter
(BSS138 FET) between the two segments.
3.3V segment, 3x 24LC64, 3x 24LC512
5V segment 24LC32, DS1307, 2x MCP23008
I use 3.3k pullups on the 5v segment. The Sparkfun circuit adds a 10k pull
so my effective pullup on the 5v bus is 2.48k, which provides 2mA, and
another 10k pullup to the 3.3V side, adding 0.33mA so my total pullup is
2.34mA. On the low side, but, much better than 0.33mA.
I am having a different problem with I2C, once in a while, the SDA is
driven low continuously from the ESP32. A Wire.begin() will not fix it, but
a RESET usually will. I think the Wire library is either leaving SDA as an
output and Waiting for the bus to clear(it never does) or the Hardware is
glitching. I am decoding the I2C section to see if I can find this problem.
Chuck.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qiaXgh8KXoc9SYtxdqgrKieQ-RtVks5stYIJgaJpZM4LKA2r>
.
|
Did anyone ever solve the DMP aspect of the mpu6050? with FIFO buffers I know this is a cheapo board but that makes it great for teaching. I get my device to be seen by the i2c but i2devlib doesnt seem to be ported over to esp32 yet. I have a bosch bno055 sitting around perhaps im better off with that for now @kriswiner |
I've used the MPU6050 DMP but not for a couple of years and never with the
ESP32:
https://github.com/kriswiner/MPU6050/wiki/Affordable-9-DoF-Sensor-Fusion
…On Sat, Jan 13, 2018 at 11:05 AM, carbonadam ***@***.***> wrote:
Did anyone ever solve the DMP aspect of the mpu6050? with FIFO buffers I
know this is a cheapo board but that makes it great for teaching. I get my
device to be seen by the i2c but i2devlib doesnt seem to be ported over to
esp32 yet. I have a bosch bno055 sitting around perhaps im better off with
that for now @kriswiner <https://github.com/kriswiner>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qmND-T-b_YJhXXEtLR1hPNX5ogrrks5tKP5qgaJpZM4LKA2r>
.
|
Yes nice work, I had it working with the Nano but now have fallin in love with the esp32, Ill have to give the bno055 a go then..its sitting here on my desk anyway. I wonder if someone has a working i2Cdevx.h for the esp32? I cant seem to get it to compile under the arduino IDE. It seems others might have but feel like I am chasing my tale here |
IMHO i2cdev is crap, I wouldn;t use it.
https://github.com/kriswiner/ESP32/tree/master/Bosch
…On Sat, Jan 13, 2018 at 11:54 AM, carbonadam ***@***.***> wrote:
Yes nice work, I had it working with the Nano but now have fallin in love
with the esp32, Ill have to give the bno055 a go then..its sitting here on
my desk anyway. I wonder if someone has a working i2Cdevx.h for the esp32?
I cant seem to get it to compile under the arduino IDE. It seems others
might have but feel like I am chasing my tale here
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGY1qlMkUAx5sO7pLPwKbV1AcrUgujcbks5tKQoFgaJpZM4LKA2r>
.
|
Fantastic work, I will give it a shot:) |
* Enable FREERTOS_WATCHPOINT_END_OF_STACK only for Xtensa * Skip collecting optimization flag and esptool.py
I can read the I2C addresses of the I2C sensors with pins 21/22 but I cannot read the WHO_AM_I byte.
This works on the Teensy and STM32L4:
The text was updated successfully, but these errors were encountered: