From 1eaeeef9a0c954056105593c8984cd34839bc066 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Wed, 24 Apr 2024 13:24:15 +0200 Subject: [PATCH] Read temperature over I2C works Has not been tested with thermistor as I didn't have the hardware. Testing with a hardcoded positive number works. --- prosjekt.X/command-handler.c | 11 ++++++++++- prosjekt.X/command-handler.h | 2 ++ prosjekt.X/main.c | 2 ++ prosjekt.X/nbproject/configurations.xml | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/prosjekt.X/command-handler.c b/prosjekt.X/command-handler.c index 8ca971a..8da542d 100644 --- a/prosjekt.X/command-handler.c +++ b/prosjekt.X/command-handler.c @@ -140,7 +140,16 @@ uint8_t route_command(int pos) { case READ_VOLTAGE: return READ_VOLTAGE; case READ_TERMPERATURE: - return READ_TERMPERATURE; + { + uint16_t v_therm = thermistor_voltage_read(); + union { + int16_t temp; + uint8_t bytes[2]; + } temperature; + temperature.temp = (int16_t) ( calculate_thermistor_temp(v_therm) * 1000 ); + return temperature.bytes[pos]; + } + break; case READ_FAN_SPEED: if (context.fan == FAN1) { return fan1_history[0]; diff --git a/prosjekt.X/command-handler.h b/prosjekt.X/command-handler.h index 3956d07..bcd4063 100644 --- a/prosjekt.X/command-handler.h +++ b/prosjekt.X/command-handler.h @@ -16,6 +16,8 @@ extern "C" { #include #include #include +#include "voltage.h" +#include "themistor-temp.h" // Enum of all valid command types typedef enum { diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 2370b1c..e8b06f4 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -29,6 +29,8 @@ volatile uint16_t fan2_history[512] = {2, 3, 4, 5}; int main() { init_uart((uint16_t)9600); + ADC0_init(); + init_led(); init_i2c(); stdout = &USART_stream; diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 12d6430..22bd261 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -29,6 +29,7 @@ voltage.c i2c.c command-handler.c + thermistor-temp.c Makefile