Giter VIP home page Giter VIP logo

Comments (9)

ivmarkov avatar ivmarkov commented on June 19, 2024

Shouldn't you be using write_read? Have you tried this crate?

from esp-idf-hal.

Gazedo avatar Gazedo commented on June 19, 2024

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.

Dominaezzz avatar Dominaezzz commented on June 19, 2024

What does the working Arduino code look like?

from esp-idf-hal.

Gazedo avatar Gazedo commented on June 19, 2024

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.

MabezDev avatar MabezDev commented on June 19, 2024

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.

Gazedo avatar Gazedo commented on June 19, 2024

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.

Dominaezzz avatar Dominaezzz commented on June 19, 2024

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.

Gazedo avatar Gazedo commented on June 19, 2024

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.

Gazedo avatar Gazedo commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.