Forráskód Böngészése

Support für Temperatursensoren hinzugefügt

Heinrich Blatt 7 hónapja
szülő
commit
e59f26f85e

+ 3 - 0
src/battery_data/battery.c

@@ -8,6 +8,7 @@
 // we need the itnerface for the ADC_TARGET_BASE_ADDRESS constant
 // refactor this somewhen to a general constants file
 #include "src/peripherals/adc/adc_interface.h"
+#include "src/peripherals/temp/tmp1075.h"
 #include "src/config.h"
 
 BatterySlot battery_slots[NUM_SLOTS];
@@ -115,6 +116,8 @@ static void batteryslots_read_state(uint8_t slot) {
         printf("Slot %d voltage: %d mV and %d mA (pwm shunt) (hi side voltage: %d mV, hi side current: %d mA)\n", slot, battery_slots[slot].measurement.voltage, battery_slots[slot].measurement.current, hi_voltage, shunt_current);
 #endif
     }
+
+    battery_slots[slot].measurement.temperature = read_temperature(slot);
 }
 
 static void batteryslots_adjust_current(uint8_t slot) {

+ 3 - 0
src/config.h

@@ -58,6 +58,9 @@
 // printf target i2c interrupts (where the mcu is the i2c target)
 #define DEBUG_TARGET 1
 
+// debug temperature sensor
+//#define DEBUG_TEMPERATURE
+
 //------------
 // Section for configuring error tresholds
 //------------

+ 1 - 0
src/peripherals/dac/dac.h

@@ -1,4 +1,5 @@
 #ifndef DAC_H_
+#define DAC_H_
 #include "ti/driverlib/dl_i2c.h"
 #include "ti_msp_dl_config.h"
 #include <stdbool.h>

+ 29 - 0
src/peripherals/temp/tmp1075.c

@@ -0,0 +1,29 @@
+
+#include "src/peripherals/temp/tmp1075.h"
+
+#include "src/interfaces/i2c_controller.h"
+
+#include <stdio.h>
+
+/**
+ * Read Temperature
+ * of a former initalized TMP1075 sensor
+ */
+uint16_t read_temperature(uint8_t slot) {
+    controllerRxPackage.len = 3;
+    controllerRxPackage.count = 0;
+    controllerRxPackage.complete = false;
+    i2c_hal.read(TMP1075_BASE_ADDRESS + slot);
+
+    while(!controllerRxPackage.complete);
+    uint16_t byte1 = controllerRxPackage.packet[0];
+    uint8_t byte2 = controllerRxPackage.packet[1];
+    
+    uint16_t temp = ((byte1 << 4) | (byte2 >> 4)) * 62.5;
+
+#ifdef DEBUG_TEMPERATURE
+    printf("Temperatur von slot %d: 0x%02X 0x%02X -> %d \n", slot, byte1, byte2, temp);
+#endif
+
+    return temp;
+}

+ 10 - 0
src/peripherals/temp/tmp1075.h

@@ -0,0 +1,10 @@
+#ifndef TMP1075_H_
+#define TMP1075_H_
+
+#include <stdint.h>
+
+#define TMP1075_BASE_ADDRESS 0x48
+
+uint16_t read_temperature(uint8_t slot);
+
+#endif