Comments (9)
Shouldn't you be using write_read
? Have you tried this crate?
from esp-idf-hal.
Shouldn't you be using
write_read
? Have you tried this crate?
I've tried all of those options, I was trying to reduce the code to the bare minimum to show the error. I get the same error on all of those options because at the base level they all use the write function at some point.
from esp-idf-hal.
What does the working Arduino code look like?
from esp-idf-hal.
This is the Arduino code that works. It is the example from Bolder Flight Systems:
#include "mpu9250.h"
/* Mpu9250 object */
bfs::Mpu9250 imu;
void setup() {
/* Serial to display data */
Serial.begin(115200);
while(!Serial) {}
/* Start the I2C bus */
Wire.begin();
Wire.setClock(400000);
/* I2C bus, 0x68 address */
imu.Config(&Wire, bfs::Mpu9250::I2C_ADDR_PRIM);
/* Initialize and configure IMU */
if (!imu.Begin()) {
Serial.println("Error initializing communication with IMU");
while(1) {}
}
/* Set the sample rate divider */
if (!imu.ConfigSrd(19)) {
Serial.println("Error configured SRD");
while(1) {}
}
}
void loop() {
/* Check if data read */
if (imu.Read()) {
Serial.print(imu.new_imu_data());
Serial.print("\t");
Serial.print(imu.new_mag_data());
Serial.print("\t");
Serial.print(imu.accel_x_mps2());
Serial.print("\t");
Serial.print(imu.accel_y_mps2());
Serial.print("\t");
Serial.print(imu.accel_z_mps2());
Serial.print("\t");
Serial.print(imu.gyro_x_radps());
Serial.print("\t");
Serial.print(imu.gyro_y_radps());
Serial.print("\t");
Serial.print(imu.gyro_z_radps());
Serial.print("\t");
Serial.print(imu.mag_x_ut());
Serial.print("\t");
Serial.print(imu.mag_y_ut());
Serial.print("\t");
Serial.print(imu.mag_z_ut());
Serial.print("\t");
Serial.print(imu.die_temp_c());
Serial.print("\n");
}
}
from esp-idf-hal.
According to this article, the default sda and scl are pins 8 & 9. So the first question is, does it work if you use pins 8 & 9? Secondly, if it still doesn't work, and you are convinced it really is on pins 4 & 5, what happens if you set Wire.setPins(4, 5);
in your arduino example?
from esp-idf-hal.
I've verified via multimeter that the pins are 4=sda and 5=scl. I also checked the power input to the imu. Unfortunately I don't currently have a multimeter to watch the hardware signals but I may be able to borrow a cheap one. I forgot to modify the example again as I copied and pasted the generic example included with the library. In order to get the pasted example to work, I had to modify Wire.begin();
to be Wire.begin(4, 5);
Things I've tried:
- MPU9250 library and passing in
i2cdev
along with delay from Ets - using the Write_Read trait
- Switching to 4=scl and 5=sda
- using 8 and 9 just to see
- going back to 33.2 of esp_idf_hal. If you have known good version please let me know.
Things I'd like to confirm:
- Does the esp32c3 naturally run at a sane clock rate or do I need to specify one to get i2c to work? This does really look like either a configuration issue or a clock speed issue.
- Why use the command link interface for i2c rather than the simpler and more robust functions outlined in https://github.com/espressif/esp-idf/blob/master/examples/peripherals/i2c/i2c_simple/main/i2c_simple_main.c
- Was there a version that the i2c is for sure working?
- Is there a way to enable backtraces on the console? I'm pretty sure my program is failing on line 230 of i2c.rs but I would like that confirmed and I don't know how to pass in environmental variables to a mcu.
- Should I be trying different versions of the esp-idf-sys crate? Maybe different rust versions?
from esp-idf-hal.
Command link is necessary for transactions. There's a strict contract that embedded hal requires for i2c, as to when to receive and send ACKs, which is easy to do with command link.
I currently use the i2c implementation to drive a touch screen so it definitely works.
You should just set clock yourself.
Have a look at the embedded hal i2c contract and see if your device cam comply. .i.e. does it respond with ACKs at the write time?
from esp-idf-hal.
What versions of esp-idf-hal and esp-idf-sys are you using? According to the docs for the mpu9250 the device does an ack after each write.
This is the MPU 9250 Datasheet and I read the details of the i2c communication on page 34.
from esp-idf-hal.
Figured it out, you can't do into_output or into_input_output on the pins before passing them into the Master struct. That is confusing and there are no warnings to prevent that.
from esp-idf-hal.
Related Issues (20)
- Conflict between esp-idf-hal and display-interface-spi on embedded-hal version HOT 1
- Documentation/API regarding default input pin pull up/down state HOT 6
- Ubuntu 22.04.3 LTS Cross-Compilation for the target = "riscv32imac-esp-espidf" (IDFGH-11878) HOT 4
- Remove 4096 limit for SPI dma transfer size HOT 2
- Can't enable the `edge-executor` feature HOT 2
- i2c broken on esp32-c6 HOT 1
- Never return type for `reset::restart`
- Simple blink example for RGB Led on Esp32 C6
- Shared I2C bus example HOT 1
- Support async in i2c Driver by using new ESP-IDF V5.2 driver impl
- rmt_neopixel no longer works (on esp32c6) HOT 3
- Mutating struct in ISR HOT 1
- Error: dangerous relocation: call8: call target out of range:(xtensa-esp32s3-espidf) HOT 3
- Transport(Failed to load system certs: No valid certificate found) (xtensa-esp32s3-espidf/STD) HOT 4
- need uart dtr, for rs485 control HOT 1
- SpiBusDriver is not Send HOT 1
- I2C default baudrate too high, is 1M, using this parameter is likely to be wrong HOT 2
- Problem with CHANGELOG.md in v0.43.0 release: Unable to find valid link for esp-ulp-riscv-hal crate. HOT 2
- Spi has some problems. or clk needs to pull up resistors、or other...(esp32c2 rust-std) HOT 3
- spi async need some config in the Cargo.toml and sdkconfig.defaults?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-idf-hal.