The LIS3MDL is ST's ultra-low-power, high-performance three-axis digital magnetometer, built on MEMS technology and aimed squarely at two declared applications: magnetometers and compasses. It measures magnetic field on three axes with a 16-bit output and a user-selectable full scale of ±4, ±8, ±12, or ±16 gauss, and it communicates over I²C (100 kHz standard / 400 kHz fast mode) or SPI. The analog supply runs from 1.9 V to 3.6 V, with an independent 1.8 V-class I/O rail for flexible host matching, and current consumption is modest: 270 µA typ in ultra-high-performance mode, 40 µA typ in low-power mode (both at ODR = 20 Hz), and 1 µA typ in power-down. Output data rates span 0.625 Hz to 80 Hz in normal operation, extendable to 1000 Hz via FAST_ODR. If you're building electronic compassing, heading estimation, or any design that needs to sense the earth's field or nearby magnetic disturbances, this is the part.
What the LIS3MDL Is For
The datasheet's Applications list names exactly two target uses: magnetometers and compasses. That's the whole declared scope — the part is a three-axis magnetic field sensor with 16-bit outputs, an interrupt generator for magnetic-field detection, and a built-in self-test for verifying function in the final application. It is not a general-purpose current sensor or a position encoder; it reads magnetic flux density, and everything else (heading, detection, calibration) is your firmware's job on top of that raw data.
Wiring It Up: Power, Decoupling, and the I/O Rail
The LIS3MDL is not fussy about external circuitry, but the datasheet's requirements are specific and non-negotiable:
- Pin 4 (MEMS settling): one external 100 nF capacitor (C1) to GND is required. This is not optional — the MEMS sensing element needs it to settle properly.
- Vdd (core supply): a 100 nF high-frequency ceramic capacitor placed as close as possible to the supply pin, plus a 1 µF low-frequency electrolytic. The placement requirement on the 100 nF is explicit; a ceramic cap three centimeters away doesn't do the high-frequency job it's there for.
- Simultaneous power-up: all supply and ground pins must be energized at the same time for correct behavior. Don't sequence Vdd and Vdd_IO independently or you may see undefined behavior at boot.
On the I/O rail: Vdd_IO is specified at 1.71 V minimum, 1.8 V typical, up to Vdd + 0.1 V maximum, so it can run lower than Vdd. Interface thresholds are gauged at 0.2·Vdd_IO and 0.8·Vdd_IO for both input and output. The practical consequence: if you run Vdd_IO at 1.8 V, a 3.3 V host cannot drive those pins directly. The absolute-maximum limit on the control pins (SCL/SPC, SDA/SDI/SDO, SDO/SA1, CS) is −0.3 to Vdd_IO + 0.3 V, so a stuck-high 3.3 V line into a 1.8 V rail doesn't just misread — it violates the stress rating. Keep host logic referenced to (or translated to) the same rail as Vdd_IO.
The absolute-maximum supply limit on Vdd and Vdd_IO is −0.3 to +4.8 V on any pin. One thing the datasheet deliberately does not specify is I²C/SPI pull-up resistor values — that's a host/bus-side decision governed by the I²C-bus standard and your MCU's drive strength. The threshold spec (0.8·Vdd_IO high, 0.2·Vdd_IO low) is what bounds what your pull-ups must achieve, and nothing more.
Configuration: Full Scale, Modes, and Data Rates
Full scale is selected in CTRL_REG2 (FS bits): ±4 / ±8 / ±12 / ±16 gauss. Sensitivity scales inversely with range:
| Full scale | Sensitivity |
|---|---|
| ±4 gauss | 6842 LSB/gauss |
| ±8 gauss | 3421 LSB/gauss |
| ±12 gauss | 2281 LSB/gauss |
| ±16 gauss | 1711 LSB/gauss |
In prose: at the narrowest ±4 gauss range you get 6842 LSB per gauss — the finest resolution — while ±16 gauss gives only 1711 LSB per gauss, a fourfold resolution penalty. For earth-field compass work (roughly ±0.5 gauss), use the smallest range your expected field allows. Whether ±4 (best resolution, saturates near ±4 gauss) or a wider scale is right for you is an application decision, not a datasheet prescription.
Sensitivity is a function of full scale only — it does not change between low-performance, medium-performance, high-performance, and ultra-high-performance modes. Noise does, but the datasheet quantifies it in exactly one condition: RMS noise of 3.2 mgauss on X and Y, 4.1 mgauss on Z, in ultra-high-performance mode at ±12 gauss. There is no per-mode or per-ODR noise table. If you need the quietest readings, operate in UHP mode and budget against that spec; if you don't, the current numbers (40 µA LP vs 270 µA UHP at 20 Hz) argue for the lowest-performance mode that meets your noise budget.
Operating modes and rates: CTRL_REG3's MD bits select continuous conversion, single-conversion, or power-down (which has two encodings). In single-conversion mode, use ODRs from 0.625 Hz to 80 Hz. DO[2:0] selects 0.625 / 1.25 / 2.5 / 5 / 10 / 20 / 40 / 80 Hz; FAST_ODR raises this to 155 / 300 / 560 / 1000 Hz depending on the operating mode (UHP/HP/MP/LP). For battery designs, power-down between measurements is the datasheet-supported lever — just remember to add your regulator's quiescent current to the budget, since the 1 µA figure is the sensor alone.
Interrupt engine: the field-detection interrupt uses INT_CFG (30h), INT_THS_L/H (32h/33h), and INT_SRC (31h). The threshold is a 16-bit unsigned value, and the device detects both positive and negative thresholds — comparison is against the magnitude of the field. Note the latching semantics: with LIR = 0 (the default), the INT pin remains in its asserted state until INT_SRC is read; that read is the only thing that clears it. There is no hardware hysteresis register — if your application needs a hysteresis window, implement it in firmware. Also watch the MROI bit in INT_SRC: it flags an internal measurement-range overflow, distinct from a normal threshold event, and is your early warning that the field exceeded the selected full scale.
What to Watch Out For
Magnetic handling is the unique hazard of a magnetometer. The zero-gauss offset starts to degrade above a ~50 gauss disturbance field, and the maximum exposed field is 1000 gauss. The datasheet explicitly warns the device is sensitive to magnetic fields and that improper handling can cause permanent damage. In practice: keep the part away from strong permanent magnets, motor and PMSM magnets, and magnetic chucks during assembly and rework. Exposure near those limits risks accuracy loss at best and permanent damage at worst.
Layout for compass accuracy. Datasheet section 4.3 is blunt: high current in wiring and PCB traces causes errors in magnetic field measurements for compassing, because conductor-generated fields add to the earth's field and corrupt heading computation. The rule: keep currents higher than 10 mA a few millimeters away from the sensor IC. That applies to power rails, motor drives, LED strings, speakers — anything carrying meaningful current. Placement and routing, not added components, are the mitigation.
ESD. The datasheet warns the device is sensitive to ESD and improper handling can cause permanent damage. Follow normal assembly ESD controls, and if any bus lines leave the board, add board-level ESD protection on those connectors.
Temperature. The operating range is −40 to +85 °C, storage −40 to +125 °C. The datasheet specifies a zero-gauss level of ±1 gauss typ at ±4 gauss full scale but does not provide an offset-vs-temperature drift coefficient. What it does give you is an on-chip temperature sensor that refreshes at the ODR and changes ~8 LSB/°C — use it in firmware if you need software offset compensation across temperature, since the part won't do it for you.
Testing and Verification
Run the self-test on every power-up. The LIS3MDL has a datasheet-defined self-test, enabled via the ST bit in CTRL_REG1. At ±12 gauss full scale, the expected output shift is 1–3 gauss on X/Y and 0.1–1 gauss on Z. If the measured shift falls inside those windows, the MEMS sensing element is alive and functioning; if not, you have a hardware problem before you've written a line of application code.
Verify the register interface first. Read WHO_AM_I (0Fh), the device identification register, before trusting any sensor data. If that read fails, the part isn't on the bus at the expected address or isn't powered correctly — nothing downstream is meaningful.
Known limitation: this guide verified that WHO_AM_I exists and its purpose, but not its numeric default value — check the register map for the expected ID byte rather than trusting a memorized constant.
Exercise the full signal path. Rotate the board through known orientations and confirm the output vector follows the earth's field plausibly; check that two's-complement outputs move smoothly through zero and don't clip at your selected full scale. If you use the interrupt, deliberately bring a small magnet near the sensor and confirm INT asserts at your programmed threshold and clears on the INT_SRC read (with LIR = 0).
Troubleshooting: A Structured Sequence
When a LIS3MDL misbehaves, work this order — it separates a dead or corrupt part from a healthy sensor giving plausible-but-polluted data:
- WHO_AM_I read. If the host can't read register 0Fh, the part is not on the bus at the expected address or not powered correctly. Fix bus/power before anything else.
- Supply voltages. Operating supply is 1.9 V to 3.6 V with an independent 1.8 V I/O rail. A part that reads as dead at 3.3 V may be brown-outing right at the 1.9 V minimum — check the actual rail under load, not the nominal design value.
- Current signature. Expected typicals: 270 µA (ultra-high-performance) and 40 µA (low-power), both at ODR = 20 Hz, and 1 µA in power-down (a mode, not a data rate — no ODR condition applies). Several milliamps suggests a shorted decoupling cap or misconfigured mode; zero suggests no power or an open supply. Either way, the current meter discriminates faster than any register read.
- CTRL_REG3 (22h) zeros. The datasheet states plainly that certain bits "must be set to '0' for correct functioning of the device." A wrong value here is a documented cause of malfunction — always write the required zeros.
- CTRL_REG2 (21h) recovery bits. If the device is in a bad configuration state, use SOFT_RST (resets configuration and user registers) and REBOOT (reboots memory content) rather than power-cycling the board. FS[1:0] defaults to 00 (±4 gauss).
- CTRL_REG4 (23h) axis modes. Z-axis operating mode is set here (low/medium/high/ultra-high-performance). An axis reading flat or unusually noisy may simply be left in a low-performance mode — performance follows the mode field directly.
- Output range sanity. Outputs are two's complement. Clipping at the extremes of ±4 gauss means you've over-ranged — switch to ±8/±12/±16. Enormous apparent fields that don't follow rotation point to a config or data-format issue, not the sensor. All-zeros or all-F readings suggest a stuck bus or reading the wrong register offset — confirm you're hitting the OUT_* registers, not the config block.
- Environment. A magnetometer "reads wrong" far more often from its surroundings than from a dead chip. Check for >10 mA conductors near the part, and remember that strong magnetic exposure can leave it in a bad state — the fix is removing the interference, then SOFT_RST/REBOOT and re-calibration.
That ordering — power → WHO_AM_I → current signature → CTRL_REG3 zeros → CTRL_REG2 reset bits → CTRL_REG4 modes → output range → environment — isolates hardware failure from configuration error from environmental interference in a minimum number of steps.
Part page: LIS3MDL.