From b092f954bb6e6bbee175405b612f0a8dfb7f3fc3 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Tue, 11 Jun 2024 11:21:09 +0200 Subject: [PATCH] tests/drivers: add max31855 test application --- tests/drivers/max31855/Makefile | 6 +++ tests/drivers/max31855/Makefile.ci | 3 ++ tests/drivers/max31855/main.c | 79 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tests/drivers/max31855/Makefile create mode 100644 tests/drivers/max31855/Makefile.ci create mode 100644 tests/drivers/max31855/main.c diff --git a/tests/drivers/max31855/Makefile b/tests/drivers/max31855/Makefile new file mode 100644 index 0000000000..4d48fc706a --- /dev/null +++ b/tests/drivers/max31855/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.drivers_common + +USEMODULE += max31855 +USEMODULE += ztimer_sec + +include $(RIOTBASE)/Makefile.include diff --git a/tests/drivers/max31855/Makefile.ci b/tests/drivers/max31855/Makefile.ci new file mode 100644 index 0000000000..72db76ccb5 --- /dev/null +++ b/tests/drivers/max31855/Makefile.ci @@ -0,0 +1,3 @@ +BOARD_INSUFFICIENT_MEMORY := \ + atmega8 \ + # diff --git a/tests/drivers/max31855/main.c b/tests/drivers/max31855/main.c new file mode 100644 index 0000000000..9d3cf0b10f --- /dev/null +++ b/tests/drivers/max31855/main.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2024 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 max31855 thermocouple-to-digital converter driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include +#include + +#include "max31855.h" +#include "max31855_params.h" +#include "ztimer.h" + +#define DELAY (2) + +int main(void) +{ + max31855_t dev; + max31855_data_t data; + + puts("MAX31855 Thermocouple-to-Digital converter test application\n"); + + /* initialize first configured sensor */ + printf("Initializing MAX31855 converter...\t"); + if (max31855_init(&dev, &max31855_params[0]) == 0) { + puts("[OK]\n"); + } + else { + puts("[Failed]"); + return 1; + } + + /* periodically convert temperature values */ + while (1) { + ztimer_sleep(ZTIMER_SEC, DELAY); + max31855_read(&dev, &data); + + if (data.fault != MAX31855_FAULT_NO_FAULT) { + switch (data.fault) { + case MAX31855_FAULT_GND_SHORT: + puts("Fault: Short to GND"); + break; + case MAX31855_FAULT_VCC_SHORT: + puts("Fault: Short to VCC"); + break; + case MAX31855_FAULT_OPEN_CIRCUIT: + puts("Fault: Open circuit"); + break; + default: + puts("Fault: Unknown"); + break; + } + + continue; + } + + printf("Thermocouple temperature: %" PRIi32 ".%"PRId32 "°C\n", + data.thermocouple_temperature/100, data.thermocouple_temperature%100); + + printf("Internal temperature: %" PRIi32 ".%" PRId32 "°C\n", + data.internal_temperature/100, data.internal_temperature%100); + } + + return 0; +}