tests: Add test for AD7746 driver
This commit is contained in:
parent
50dc5b7528
commit
aefdc6550c
6
tests/driver_ad7746/Makefile
Normal file
6
tests/driver_ad7746/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
USEMODULE += ad7746
|
||||||
|
USEMODULE += xtimer
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
11
tests/driver_ad7746/README.md
Normal file
11
tests/driver_ad7746/README.md
Normal file
@ -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.
|
||||||
91
tests/driver_ad7746/main.c
Normal file
91
tests/driver_ad7746/main.c
Normal file
@ -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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user