tmp1075.c 725 B

1234567891011121314151617181920212223242526272829
  1. #include "src/peripherals/temp/tmp1075.h"
  2. #include "src/interfaces/i2c_controller.h"
  3. #include <stdio.h>
  4. /**
  5. * Read Temperature
  6. * of a former initalized TMP1075 sensor
  7. */
  8. uint16_t read_temperature(uint8_t slot) {
  9. controllerRxPackage.len = 3;
  10. controllerRxPackage.count = 0;
  11. controllerRxPackage.complete = false;
  12. i2c_hal.read(TMP1075_BASE_ADDRESS + slot);
  13. while(!controllerRxPackage.complete);
  14. uint16_t byte1 = controllerRxPackage.packet[0];
  15. uint8_t byte2 = controllerRxPackage.packet[1];
  16. uint16_t temp = ((byte1 << 4) | (byte2 >> 4)) * 62.5;
  17. #ifdef DEBUG_TEMPERATURE
  18. printf("Temperatur von slot %d: 0x%02X 0x%02X -> %d \n", slot, byte1, byte2, temp);
  19. #endif
  20. return temp;
  21. }