FOSSASAT-1B
pin_interface.cpp
1 #include "pin_interface.h"
2 
3 void Pin_Interface_Set_Temp_Resolution(uint8_t sensorAddr, uint8_t res) {
4  // set resolution
5  Wire.beginTransmission(sensorAddr);
6  Wire.write(TEMP_SENSOR_REG_CONFIG);
7  Wire.write(res);
8  Wire.endTransmission();
9 
10  // set mode back to temperature reading
11  Wire.beginTransmission(sensorAddr);
12  Wire.write((uint8_t)0x00);
13  Wire.endTransmission();
14 }
15 
16 float Pin_Interface_Read_Temperature(uint8_t sensorAddr) {
17  // read data from I2C sensor
18  Wire.requestFrom(sensorAddr, (uint8_t)2);
19  uint8_t msb = Wire.read();
20  uint8_t lsb = Wire.read();
21 
22  // convert raw data to temperature
23  int16_t tempRaw = ((msb << 8) | lsb) >> 4;
24  float temp = tempRaw * 0.0625f;
25  return(temp);
26 }
27 
29  // select temperature sensor and reference
30  ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
31  // start AD conversion
32  ADCSRA |= _BV(ADEN) | _BV(ADSC);
33  // Detect end-of-conversion
34  while (bit_is_set(ADCSRA, ADSC));
35  // get raw data
36  uint16_t raw = ADCL | (ADCH << 8);
37 
38  // convert to real temperature
39  int8_t temp = (int8_t)(((float)raw - MCU_TEMP_OFFSET) / MCU_TEMP_COEFFICIENT);
40  return(temp);
41 }
42 
43 float Pin_Interface_Read_Voltage(uint8_t pin) {
44  // map ADC value to voltage
45  return((analogRead(pin) * 3.3) / 1023.0);
46 }
47 
48 void Pin_Interface_Watchdog_Heartbeat(bool manageBattery) {
49  // toggle watchdog pin
51 
52  // check voltage
53  if(manageBattery) {
55  }
56 }
57 
59  FOSSASAT_DEBUG_PRINTLN(F("Rst"));
60 
61  // do not pet watchdog for more than 30 seconds to restart
62  for(uint8_t i = 0; i < WATCHDOG_RESET_NUM_SLEEP_CYCLES; i++) {
63  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
64  }
65 }
void Pin_Interface_Set_Temp_Resolution(uint8_t sensorAddr, uint8_t res)
This function sets the resolution of the TMP100.
#define MCU_TEMP_COEFFICIENT
#define DIGITAL_OUT_WATCHDOG_HEARTBEAT
#define TEMP_SENSOR_REG_CONFIG
bool Power_Control_Check_Battery_Limit()
Checks whether battery voltage is below low power limit. Will enable low power mode if that is the ca...
void Pin_Interface_Watchdog_Heartbeat(bool manageBattery=false)
This function toggles the signal to the watchdog and writes it to the pin.
float Pin_Interface_Read_Temperature(uint8_t sensorAddr)
This function reads the TMP100&#39;s value from its wire address.
#define WATCHDOG_RESET_NUM_SLEEP_CYCLES
Definition: configuration.h:76
float Pin_Interface_Read_Voltage(uint8_t pin)
Read the voltage of a given pin.
#define MCU_TEMP_OFFSET
This module controls access to the components connect to via pins.
void Pin_Interface_Watchdog_Restart()
Restarts the watchdog.
int8_t Pin_Interface_Read_Temperature_Internal()
This function reads the MCU&#39;s internal temperature.