Getting a reading · 07 of 11

It wakes up asleep

Straight after power-up the chip is asleep: its data rate is set to zero, it draws half a microamp, and it measures nothing. One register write wakes it. Two more habits — asking its name first, and reading six registers in one go — make every sketch here work first time.

Registers

The chip is controlled the way most I²C sensors are: through registers, numbered one-byte boxes inside it. Some hold settings you write, some hold results you read. A sketch writes a register by sending its number and then the value; it reads one by sending the number and then asking for bytes back.

Three exchanges are all the first sketch does. Press play:

It wakes up asleep
Chip
asleep
Supply current
0.5 µA
Bus time so far
0.00 ms
Power is on and the power light is lit, and the chip is asleep. It powers up with the data-rate bits of CTRL_REG1 at 0000, which means powered down: it draws 0.5 µA and measures nothing. Nothing on the board says so.

First, its name

Register 0x0F, WHO_AM_I, is read-only and always holds 0x11 on this chip. Reading it first costs a few hundred microseconds and settles two questions at once: that something answered at 0x19, and that it is the part you think it is. A sketch that skips it and goes straight to readings fails later, less clearly.

It is also why libraries written for similar chips refuse this one: each checks WHO_AM_I for the value its own chip returns, and 0x11 is not it.

Then, wake it

Register 0x20, CTRL_REG1, is the one that matters. Its top four bits set the data rate: how many readings a second the chip takes. From the factory they are 0000, which the data sheet calls power-down. The chip draws 0.5 µA, measures nothing, and nothing new ever reaches its output registers.

The sketches write 0x57. In bits that is 0101 0111: 0101 in the top four selects 100 readings a second; the next bit, 0, keeps normal rather than low-power mode; the bottom three switch on Z, Y and X. The chip is taking readings within about a millisecond of that write, and draws 16 µA doing it.

The other write, 0x80 to CTRL_REG4 at 0x23, leaves the range at ±2 g and sets one safety bit: the two bytes of an axis always come from the same reading, never half from one and half from the next.

Then, read six at once

Each axis is two registers, low byte first, and the three axes sit in a row from 0x28 to 0x2D. Asking for them one at a time is six exchanges. Asking once with the top bit of the register number set, 0x28 + 0x80 = 0xA8, tells the chip to step to the next register after each byte, and all six come back in one exchange. That is the reg | 0x80 in the sketch's readRegs.

At the sketches' 100 kHz, one six-byte read is nine bytes on the wire in all — the address and register out, the address again, six bytes back — at nine clocks a byte: 81 clocks, about 0.8 ms. Plenty, at a hundred readings a second.

When it does not work

Every reading is 0.000, or the same number over and over.

The chip is still asleep. CTRL_REG1 (0x20) was never written, or was written with 0 in its top four bits, which is the power-down setting. Check the write returned success and that its value is 0x57, not 0x07.

WHO_AM_I comes back 0x33, not 0x11.

Then the board on the bus is not a TK115: 0x33 is what an ST LIS3DH answers, and it is a common chip on other accelerometer boards. If you have two boards on the bus, check which one answers at 0x19.

Only X changes; Y and Z stay at the first value.

The register address was sent without bit 7 set, so the chip returned OUT_X_L six times over instead of stepping through six registers. The register byte must be 0x28 | 0x80, which is 0xA8.

Can I make it read faster than 100 times a second?

Yes: the top four bits of CTRL_REG1 go up to 4434 readings a second. The shake counter uses 0x77, 400 a second. Past a few hundred, check your sketch can collect them: at 100 kHz each six-byte read takes about a millisecond of bus time.

Where this goes next

Six bytes come back. Here is how two of them become one number, and what the range setting trades.

From counts to g →

Edit this page — content/books/3-axis-accelerometer/it-wakes-up-asleep.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

3-Axis Accelerometer

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →