1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/drivers: add max31855 test application

This commit is contained in:
Leandro Lanzieri 2024-06-11 11:21:09 +02:00
parent ebf64133d7
commit b092f954bb
No known key found for this signature in database
GPG Key ID: F4E9A721761C7593
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,6 @@
include ../Makefile.drivers_common
USEMODULE += max31855
USEMODULE += ztimer_sec
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,3 @@
BOARD_INSUFFICIENT_MEMORY := \
atmega8 \
#

View File

@ -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 <leandro.lanzieri@haw-hamburg.de>
*
* @}
*/
#include <stdio.h>
#include <stdint.h>
#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;
}