Skip to main content

Subsection 12.3.3 Part 3: The LSM303AGR, and Its Datasheet

Our device is the STMicro LSM303AGR, the chip whose WHO_AM_I register we read yesterday. It carries a 3-axis accelerometer, a 3-axis magnetometer, and a temperature sensor; we’ll only use the accelerometer. Inside it (FigureĀ 12.3.13), the signal follows the path we just discussed: a pair of variable capacitors per axis, then, through a multiplexer, one charge amplifier (a capacitance-to-voltage circuit) and one analog-to-digital converter shared by all three axes, and control logic that puts the result on the I2C bus. You interact with the chip through its control and data registers, over I2C (SPI is the other option, and the breakout wires it for I2C by default), and through hardware interrupt pins we’re not using.
Figure 12.3.13. The LSM303AGR’s block diagram, from its datasheet. The accelerometer is the upper half, boxed in blue: six sense capacitors, a pair per axis (X±, Y±, Z±), feed a multiplexer, and the three axes share one charge amplifier and one analog-to-digital converter behind it, the same architecture as the STM32C031C6’s ADC (ChapterĀ 6), which likewise multiplexes several input channels through one shared converter. Control logic answers on the SCL and SDA pins, boxed in red (the datasheet prints them SCL/SPC and SDA/SDI/SDO, because the same pins serve SPI). The lower half is a magnetometer, which we don’t use; the chip also contains a temperature sensor.
The next number to take from the datasheet is the size of one step of the converter’s output. The A/D converter inside the sensor works like the ADC on our microcontroller: it turns an analog quantity, here the amplified signal from the sense capacitors, into a number with a fixed number of bits. One step is one least significant bit of that number: the smallest change in acceleration that changes the output. The size of that step is the sensitivity, and it depends on two choices the datasheet lets us make: the number of bits (the more bits, the finer the steps) and the measurement range (the larger the range, the more acceleration each step has to cover). We can derive it before we read it off the table.

Activity 12.3.2. Derive the sensitivity.

The datasheet’s sensor-characteristics table (LSM303AGR datasheet, §2.1, Table 3, pp. 13–14) says how acceleration at the input is turned into bits at the output. The sensor’s A/D converter turns a continuous signal into a digital one, and the datasheet lets us choose how many bits we get (8, 10, or 12) and the measurement range: ±2 g, ±4 g, ±8 g, or ±16 g, where 1 g is the acceleration of gravity, 9.8 m/s², and one milli-g (mg) is a thousandth of that. We’ll use ±2 g, and the sensor’s normal resolution mode, which gives 10 valid bits per reading.
The sensitivity is the size of one step of the output: how much acceleration one least significant bit stands for. From the range and the bit count, compute it, in milli-g per step. This is the same calculation we did for the ADC (ChapterĀ 6): the full range, divided into \(2^{bits}\) bins.
Figure 12.3.18. The sensor-characteristics table’s sensitivity and zero-g offset rows (LSM303AGR datasheet §2.1, Table 3, pp. 13–14). Top: the full-scale range rows. Middle: one sensitivity row per range and resolution mode (high-resolution is 12 bits, normal 10, low-power 8). At ±2 g in normal mode the table prints 3.9 mg/LSB, milli-g per least significant bit, the size of one step: the number we derived as 4 g / 2¹⁰ = 3.90625 mg (the ±2 g range spans 4 g, from āˆ’2 g to +2 g). Bottom: the zero-g offset row. A sensor lying perfectly flat reads typically ±40 mg away from the true value, and the table’s Min and Max columns allow ±80.
The table in FigureĀ 12.3.18 confirms the arithmetic. The three modes trade resolution against speed: fewer bits means bigger steps, and low-power mode runs at rates the other two cannot. The zero-g offset row is below it: lying perfectly flat, the sensor reads typically ±40 mg away from the true value, and the datasheet’s Min and Max columns allow ±80. 40 mg would be ten of our steps, 80 mg would be twenty, and a significant amount of error.
The breakout board carries the parts the chip needs: the I2C pull-up resistors and a voltage regulator (FigureĀ 12.3.20).
Figure 12.3.20. The breakout board’s schematic (partial). The board carries what the chip needs: pull-up resistors on SDA and SCL, and a regulator to supply the chip. The 6-pin header brings power, ground, SCL, SDA and the magnetometer interrupt out to the breadboard.