Multiple IIC sensor problem with stm32 board

Hi everyone.

Thanks for sharing this library. I’m working on a 3-channel driver built around stm32f446re. Here’s a demo of it running open-loop sequence. demo

I tired the blue-pill example with a gimbal motor and AS5600 sensor. To use all 3 channel of IIC sensor, I make a slightly change in encoder.h to use the TwoWire interface. The sensor works fine when there’s only sensor.getAngle() in the main loop. However, If I add the motor.loopFOC() in the main loop, the motor.shaft_angle is always zero in the motor monitor. Also, the calibrate process returns ‘failed to notice sensor movement’.

Here’s my test code

    TwoWire Wire2(PB9, PB8); //sda,scl
    MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4, &Wire2);

    // Motor instance
    BLDCMotor motor = BLDCMotor(PA5, PA6, PA7, 6, PB1);

    HardwareSerial Serial_debug(PA1, PA0);//HardwareSerial Serial1(rx, tx);

    void setup() {
      Wire2.setClock(400000); //400khz frequency

      // initialise magnetic sensor hardware
      // link the motor to the sensor

Any suggestions, thanks.

Ooh a triple board! Did you design that? Tell me more! I guess those are l6234s driving?

I’m not sure what you mean by ‘make small changes to encoder.h’, this doesn’t seem like a good place to start, i guess you meant MagneticSensorI2C.h as per your code.

I did a pull request for dual i2c support 2 weeks ago. It needs some testing, particularly on stm32.

The pull request has a new dual_i2c_bus demo. It was tested on esp32 and a storm32 (stm32f107). Worked on esp32, only i2c2 bus worked on storm32.

To be honest i think the as5600 + stm32 is difficult to work with. As an example, the PR also includes a checkbus method which can fix/clear sda when as5600 holds it low. This often happens when flashing/reset on stm32. Without this fix - you may need to turn off/on power after flashing.

Currently I’m using spi sensors (ma730 and as5047u).

1 Like

Thanks for your quick reply! I’m planning to make a small biped robot with gimbal motors, so I designed this driver. The driver need to be as small as possible, so It’s a four layer PCB design. With CAN bus, SPI and serial port. The driver IC is DRV8313, which can handle about 2a constant current in a tiny qfn36 package.

And yes, I modified the MagneticSensorI2C.h.I was trying to add a TwoWire pointer to read the sensor data, which is pretty similar to your pull request. But It didn’t work as expected. I guess I’ve missed some important part, or it’s caused by some bottom_level hardware define problem? I haven’t try your code yet, I’ll feedback once I did.

I’m also wondering can TwoWire support triple IIC devices? Or It only support a second one.

Now I’m thinking about transplant the library to the Mbed environment. Which natively supports multiple IIC devices. Arduino and Mbed shares similar library style so it should be possible. The voltage control is just finished and here’s a demo.

Let me know how you get. On paper, i can’t see why 3x i2c buses connected to 3x as5600 wouldn’t work. Not all stm32 chips have 3x buses though and I wouldn’t be surprised if there were some issues in the Arduino core.

Are you willing to share your boards schematic? Yesterday, I was designing 4 layer 3x board in kicad based around stm32f405 but with l6234 drivers. I’ve not designed a board before so may have bitten off more than i can chew. My design is heavily influenced on phil’s lab video which is 2.5hrs well spent!