non-fifo reading examples
This commit is contained in:
parent
ba64cc64ae
commit
79001b810d
@ -23,6 +23,8 @@ The FIFO "engine" samples/appends another set of [x y z] values at 1/ODR. The ma
|
||||
|
||||
Note: FIFO will not trigger a watermark interrupt (`pin1.wtm`) if the FIFO size is default (32; maximum size). To use the watermark interrupt, the FIFO size has to be between [1-31]. An overrun interrupt (`pin1.overrun`) will always trigger when the FIFO is full, regardless of programmed capacity.
|
||||
|
||||
Note: to sample data faster than 200 Hz, it is necessary to use the regular data polling functionality using `lis3dh_read()` with the appropriate configuration. See files `simple.c` and `fast.c` for examples.
|
||||
|
||||
### file: single-click.c
|
||||
|
||||
Set up single-click detection (no latching interrupt possible)
|
||||
|
53
example/fast.c
Normal file
53
example/fast.c
Normal file
@ -0,0 +1,53 @@
|
||||
#define _GNU_SOURCE /* usleep() */
|
||||
#include <unistd.h> /* usleep() */
|
||||
#include <stdio.h>
|
||||
#include "lis3dh.h"
|
||||
#include "i2c.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lis3dh_t lis;
|
||||
|
||||
lis.dev.init = i2c_init;
|
||||
lis.dev.read = i2c_read;
|
||||
lis.dev.write = i2c_write;
|
||||
lis.dev.sleep = usleep;
|
||||
lis.dev.deinit = i2c_deinit;
|
||||
|
||||
/* initialise struct and check device id */
|
||||
if (lis3dh_init(&lis)) {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
/* reset just in case*/
|
||||
if (lis3dh_reset(&lis)) {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
lis.cfg.mode = LIS3DH_MODE_LP; /* Low-power mode */
|
||||
lis.cfg.range = LIS3DH_FS_2G;
|
||||
lis.cfg.rate = LIS3DH_ODR_LP_5376_HZ; /* 5 KHz ODR, only available in low-power mode */
|
||||
|
||||
/* write cfg to device */
|
||||
if (lis3dh_configure(&lis)) {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
/* read accelerometer and store results at struct lis.acc */
|
||||
if (lis3dh_read(&lis)) {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
/* print data .. */
|
||||
printf("x: %4.4d mg, y: %4.4d mg, z: %4.4d mg\n", lis.acc.x, lis.acc.y, lis.acc.z);
|
||||
}
|
||||
|
||||
/* deinitalise device */
|
||||
if (lis3dh_deinit(&lis)) {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -26,7 +26,7 @@ int main() {
|
||||
|
||||
lis.cfg.mode = LIS3DH_MODE_HR;
|
||||
lis.cfg.range = LIS3DH_FS_4G;
|
||||
lis.cfg.rate = LIS3DH_ODR_100_HZ;
|
||||
lis.cfg.rate = LIS3DH_ODR_400_HZ;
|
||||
|
||||
/* write device config */
|
||||
if (lis3dh_configure(&lis)) {
|
||||
|
Loading…
Reference in New Issue
Block a user