# Control BMM150 via BMI270 AUX Interface [中文说明](README_cn.md) This example demonstrates how to access an external BMM150 magnetometer via the BMI270 AUX interface in manual mode, covering device wake-up, Chip ID verification, operational mode configuration, raw data reading, and clean shutdown. It demonstrates four public APIs: - `bmi270_aux_set_config()` - `bmi270_aux_get_config()` - `bmi270_aux_read()` - `bmi270_aux_write()` ## Hardware Connection The communication path is: `ESP32 -> BMI270 (main I2C) -> BMM150 (AUX I2C)` Default configuration targets the **M5Stack AtomS3R** development board: | Signal / Parameter | AtomS3R Default | Description | | --- | --- | --- | | SDA / SCL | GPIO45 / GPIO0 | ESP32-S3 to BMI270 main I2C bus (400 kHz) | | BMI270 Address | `0x68` | SDO connected to GND | | ASDA / ASCL | Onboard link | BMI270 auxiliary I2C bus connected to BMM150 | | BMM150 AUX Address | `0x10` | Auxiliary slave address | | ASDA Pull-up | 2 kΩ | Provided by BMI270 internal pull-up configuration | For other boards, connect the magnetometer to the **ASDA** and **ASCL** pins of the BMI270, ensure common ground and required bus pull-ups, and update the GPIOs and slave address in the configuration. ## Build and Run 1. Navigate to the example directory, set the target chip, and build: ```sh idf.py set-target esp32s3 idf.py menuconfig idf.py build ``` 2. Flash and monitor: ```sh ESPBAUD=921600 idf.py -p PORT flash monitor ``` Under **BMI270 AUX BMM150 Example Configuration** in `menuconfig`, you can adjust the pins, slave address, polling interval, and frame count. ## Execution Flow 1. **Bus and Sensor Initialization**: Create the main I2C bus and initialize the BMI270 instance. 2. **Configure AUX Mode**: Disable advanced power-saving, configure the ASDA pull-up, enable AUX manual mode with an 8-byte burst, and verify the settings. 3. **Enable AUX Power**: Call `bmi2_sensor_enable()` to activate the AUX channel. 4. **Wake and Identify BMM150**: Write wake command to register `0x4B`, wait for power-up, then verify Chip ID at `0x40` (expected `0x32`). 5. **Configure Measurement Mode**: Set XY/Z repetition counts and set the operating mode to 10 Hz normal mode. 6. **Periodic Data Acquisition**: Read an 8-byte frame from `0x42`, parse raw X/Y/Z readings and Hall resistance (RHALL). 7. **Clean Teardown**: Upon reaching the frame limit or encountering an error, suspend the BMM150, disable AUX, and delete the sensor instance and bus. ## Output Successful startup outputs initialization logs followed by CSV formatted data: ```text AUX manual mode, address=0x10, 8-byte read burst BMM150 chip ID=0x32 BMM150 normal mode at 10 Hz, XY repetitions=9, Z repetitions=15 timestamp_us,mag_x_raw,mag_y_raw,mag_z_raw,rhall,valid ``` | CSV Field | Description | | --- | --- | | `timestamp_us` | Host microsecond timestamp when the frame was read | | `mag_x_raw`, `mag_y_raw` | Signed 13-bit raw ADC counts | | `mag_z_raw` | Signed 15-bit raw ADC counts | | `rhall` | Unsigned 14-bit Hall resistance value (for compensation algorithms) | | `valid` | Data valid flag; `0` on overflow or zero RHALL, otherwise `1` | > **Note**: This example outputs raw ADC counts. To convert these readings into microtesla (µT) or compute orientation, apply trim-register compensation (for example, using the official `espressif/bmm150` component). By default, the example terminates and frees resources after reading 20 frames: ```text Finished after 20 frames Sensor and bus released ``` To run continuously, set the frame count (`CONFIG_AUX_BMM150_FRAME_COUNT`) to `0` in `menuconfig`.
To create a project from this example, run:
idf.py create-project-from-example "espressif/bmi270_sensor=0.4.0:aux_bmm150"