diff --git a/tests/driver_mma8652/Makefile b/tests/driver_mma8652/Makefile new file mode 100644 index 000000000000..429d6808afc6 --- /dev/null +++ b/tests/driver_mma8652/Makefile @@ -0,0 +1,36 @@ +APPLICATION = driver_mma8652 +include ../Makefile.tests_common + +FEATURES_REQUIRED = periph_i2c + +USEMODULE += mma8652 +USEMODULE += vtimer + +ifneq (,$(TEST_MMA8652_I2C)) + CFLAGS += -DTEST_MMA8652_I2C=$(TEST_MMA8652_I2C) +else + CFLAGS += -DTEST_MMA8652_I2C=I2C_0 +endif +ifneq (,$(TEST_MMA8652_ADDR)) + CFLAGS += -DTEST_MMA8652_ADDR=$(TEST_MMA8652_ADDR) +else + CFLAGS += -DTEST_MMA8652_ADDR=0x1D +endif + +ifneq (,$(TEST_MMA8652_USER_OFFSET_X)) + CFLAGS += -DTEST_MMA8652_USER_OFFSET_X=$(TEST_MMA8652_USER_OFFSET_X) +else + CFLAGS += -DTEST_MMA8652_USER_OFFSET_X=0 +endif +ifneq (,$(TEST_MMA8652_USER_OFFSET_Y)) + CFLAGS += -DTEST_MMA8652_USER_OFFSET_Y=$(TEST_MMA8652_USER_OFFSET_Y) +else + CFLAGS += -DTEST_MMA8652_USER_OFFSET_Y=0 +endif +ifneq (,$(TEST_MMA8652_USER_OFFSET_Z)) + CFLAGS += -DTEST_MMA8652_USER_OFFSET_Z=$(TEST_MMA8652_USER_OFFSET_Z) +else + CFLAGS += -DTEST_MMA8652_USER_OFFSET_Z=0 +endif + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_mma8652/README.md b/tests/driver_mma8652/README.md new file mode 100644 index 000000000000..12be603b02b5 --- /dev/null +++ b/tests/driver_mma8652/README.md @@ -0,0 +1,10 @@ +# About +This is a manual test application for the MMA8652 accelerometer driver. + +# Usage +This test application will initialize the MMA8652 sensor with the following parameters: + - full scale parameter set to +/-2 g + - 6.25 Hz output data-rate + +After initialization, the sensor reads the x-, y-, z-axis values every 1 s +and prints them to STDOUT. diff --git a/tests/driver_mma8652/main.c b/tests/driver_mma8652/main.c new file mode 100644 index 000000000000..c7c7544be4e2 --- /dev/null +++ b/tests/driver_mma8652/main.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2014 PHYTEC Messtechnik GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test application for the MMA8652 accelerometer driver. + * + * @author Hauke Petersen + * @author Johann Fischer + * + * @} + */ + +#ifndef TEST_MMA8652_I2C +#error "TEST_MMA8652_I2C not defined" +#endif +#ifndef TEST_MMA8652_ADDR +#error "TEST_MMA8652_ADDR not defined" +#endif + +#include + +#include "vtimer.h" +#include "mma8652.h" + +#define SLEEP (1000 * 1000U) + +int main(void) +{ + mma8652_t dev; + int16_t x, y, z; + uint8_t status; + + puts("MMA8652 accelerometer driver test application\n"); + printf("Initializing MMA8652 accelerometer at I2C_%i... ", TEST_MMA8652_I2C); + + if (mma8652_init(&dev, TEST_MMA8652_I2C, TEST_MMA8652_ADDR, + MMA8652_DATARATE_DEFAULT, + MMA8652_FS_RANGE_DEFAULT) == 0) { + puts("[OK]\n"); + } + else { + puts("[Failed]"); + return -1; + } + + if (mma8652_set_user_offset(&dev, TEST_MMA8652_USER_OFFSET_X, + TEST_MMA8652_USER_OFFSET_Y, + TEST_MMA8652_USER_OFFSET_Z)) { + puts("Set user offset correction failed."); + return -1; + } + + if (mma8652_set_active(&dev)) { + puts("Measurement start failed."); + return -1; + } + + while (1) { + mma8652_read(&dev, &x, &y, &z, &status); + printf("Acceleration, raw: X: %d Y: %d Z: %d S: %2x\n", x, y, z, status); + vtimer_usleep(SLEEP); + } + + return 0; +}