diff --git a/tests/driver_ad7746/Makefile b/tests/driver_ad7746/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5210f9f821444db9e5b41a329c1228f5f08b0aec --- /dev/null +++ b/tests/driver_ad7746/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +USEMODULE += ad7746 +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_ad7746/README.md b/tests/driver_ad7746/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c22d9a3ccabcbb557aad1752890bc60d44c87cfd --- /dev/null +++ b/tests/driver_ad7746/README.md @@ -0,0 +1,11 @@ +# About +This is a test application for the AD7746 capacitance-to-digital converter with +temperature and voltage sensors. + +# Usage +This test application will initialize the sensor for measuring capacitance from +the CIN1 input (it can be changed in runtime). It will also initialize the +voltage / temperature channel and show that the mode can be changed in runtime. + +After that it will print measurements of capacitance and internal temperature +on STDOUT. diff --git a/tests/driver_ad7746/main.c b/tests/driver_ad7746/main.c new file mode 100644 index 0000000000000000000000000000000000000000..fd5d0119beb3e79f7a135fe491d8f1d9a8ff7d24 --- /dev/null +++ b/tests/driver_ad7746/main.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2019 HAW Hamburg + * + * 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 AD7746 capacitance-to-digital + * converter with temperature sensor. + * + * @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de> + * @} + */ + +#include <stdio.h> + +#include "xtimer.h" +#include "timex.h" +#include "ad7746.h" +#include "ad7746_params.h" + +#define SLEEP (1000 * US_PER_MS) + +static ad7746_t dev; + +int main(void) +{ + int data; + + puts("AD746 capacitance to digital driver test application\n"); + printf("Initializing AD7746 at I2C_DEV(%i)... ", + ad7746_params->i2c); + + if (ad7746_init(&dev, ad7746_params) == AD7746_OK) { + puts("[OK]\n"); + } + else { + puts("[Failed]"); + return -1; + } + + /* show that if changed mode data may not be available right away */ + if (ad7746_read_voltage_vdd(&dev, &data) == AD7746_OK) { + printf("VDD : %d mV\n", data); + } + else { + printf("No data available for VDD yet\n"); + } + + if (ad7746_read_temperature_int(&dev, &data) == AD7746_OK) { + printf("Internal temperature: %d C\n", data); + } + else { + printf("No data available for internal temperature yet\n"); + } + + while (1) { + int res; + puts("========================="); + puts(" Measuring"); + puts("========================="); + res = ad7746_read_capacitance_1(&dev, &data); + if ( res == AD7746_OK) { + printf("Capacitance %d fF\n", data); + } + else { + printf("Error reading data. err: %d\n", res); + } + + do { + res = ad7746_read_temperature_int(&dev, &data); + } while (res == AD7746_NODATA); + + if (res == AD7746_OK) { + printf("Internal temperature: %d C\n", data); + } + else { + printf("Error reading internal temperature\n"); + } + puts(""); + xtimer_usleep(SLEEP); + } + + return 0; +}