Rust challenge 61/100 - reading the generic node's accleration sensor
Table of content
What is this
The rules of the game are explained in my original.
61st Challenge
Challenge
Now lets read the next sensor, the accleration sensor :)
Solution
Lets start from a template again, same folder as yesterday.
The sensor looks as follows on the generic node. Its on the same i2c bus so powering the bus and initalizing the bus will be the same. The slave address is however 0x33
now and we have to read the datasheet to see how we can talk to this little guy. The little guy, LIS2DH12, is an ST chip and described as MEMS digital output motion sensor: ultra-low-power high-performance 3-axis "femto" accelerometer
I want to just read out the accleration values in all directions, I’m hopeing the default configuration will allow for it. The following is an extract from the register map I’m going to read.
If the MSb
of the SUB
field is 1
, the SUB
(register address) is automatically increased to allow multiple data read/writes. We will not do this, so we will just leave the Msb
at 0
.
So first guess is we send 0x33,0xF
to get the WHO_AM_I
register value. However, trying this, yields a NAK. Reading the application notes shows we have to do the following start up sequence.
The address is actually supposed to be 0x19
to upper 7bits only when communicating and and 0x33 / 0x32 includes the LSB bit which defines if it is a read or write.
When compiling and running DEFMT_LOG=info cargo test -p testsuite --target thumbv7em-none-eabi --bin gn_i2c
we get the temperature and the humidity and additionality also the WHO_AM_I
response
Check out my fork of the original repos for the new additonal test of the generic node.