Просмотр исходного кода

Fix im Temperatursensor: Höhere Adressierung für den 2. Controller wird berücksichtigt.

Heinrich Blatt 6 месяцев назад
Родитель
Сommit
9f2622ea19
3 измененных файлов с 10 добавлено и 3 удалено
  1. 2 0
      src/interfaces/i2c_target.c
  2. 6 3
      src/peripherals/temp/tmp1075.c
  3. 2 0
      src/peripherals/temp/tmp1075.h

+ 2 - 0
src/interfaces/i2c_target.c

@@ -12,6 +12,7 @@ https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c
 #include <inttypes.h>
 #include "src/config.h"
 #include "ti_msp_dl_config.h"
+#include "src/peripherals/temp/tmp1075.h"
 
 /**
  * Dynamic addressing function
@@ -24,6 +25,7 @@ void initialize_target_address() {
     uint8_t add = 0;
     if (DL_GPIO_readPins(GPIOS_PORT, GPIOS_ADDR_PIN)) {
         add = 1;
+        addr_offset = 4;
     }
     DL_I2C_setTargetOwnAddress(I2C_target_INST, I2C_TARGET_BASE_ADDRESS+add);
     DL_I2C_enableTargetOwnAddress(I2C_target_INST);

+ 6 - 3
src/peripherals/temp/tmp1075.c

@@ -9,6 +9,9 @@
  * Read Temperature
  * of a former initalized TMP1075 sensor
  */
+
+volatile uint8_t addr_offset = 0;
+
 uint16_t read_temperature(uint8_t slot) {
 
     // Prepare TX Buffer
@@ -16,12 +19,12 @@ uint16_t read_temperature(uint8_t slot) {
     controllerTxPackage.count = 0;
     controllerTxPackage.complete = false;
     controllerTxPackage.packet[0] = 0x00;
-    i2c_hal.write(TMP1075_BASE_ADDRESS + slot);
-    
+    i2c_hal.write(TMP1075_BASE_ADDRESS + slot + addr_offset);
+
     controllerRxPackage.len = 3;
     controllerRxPackage.count = 0;
     controllerRxPackage.complete = false;
-    i2c_hal.read(TMP1075_BASE_ADDRESS + slot);
+    i2c_hal.read(TMP1075_BASE_ADDRESS + slot + addr_offset);
 
     while(!controllerRxPackage.complete);
     uint16_t byte1 = controllerRxPackage.packet[0];

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

@@ -7,4 +7,6 @@
 
 uint16_t read_temperature(uint8_t slot);
 
+extern volatile uint8_t addr_offset;
+
 #endif