CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
obc_temperature_sensor.c File Reference
#include "main.h"
#include "stdio.h"
#include <stdint.h>
#include "obc_systems/obc_temperature_sensor.h"
Include dependency graph for obc_temperature_sensor.c:

Functions

uint8_t OBC_TEMP_SENSOR_read_temperature (int32_t *result)
 Reads the temperature from the STDS75DS2F and stores it in the provided variable pointer result. Precision can be configured from 9 to 12 bits. Temperature range is -55 to 125 degrees celsius with +/- 3 degrees celsius over the whole range.
 
int32_t OBC_TEMP_SENSOR_convert_raw_to_deg_c (uint8_t raw_bytes[], uint8_t precision_coefficient, Temperature_Sensor_Data_Precision_Insignificant_Bytes_t precision_insignificant_bits, uint16_t precision_scaling_factor)
 Converts the raw bytes provided to a temperature in celsius and multiplied by a scaling factor based on the provided precision. Works on the four MSBs. Reference https://www.st.com/resource/en/datasheet/stds75.pdf page 15 and 18 for information on calculations and format of temperature data.
 
int8_t OBC_TEMP_SENSOR_get_temp_precision ()
 Reads the temperature precision from the config register. Refer to https://www.st.com/resource/en/datasheet/stds75.pdf page 17, table 6 and 7 for more information.
 
uint8_t OBC_TEMP_SENSOR_set_temp_precision (uint8_t arg_precision, uint32_t *temp_precision_conversion_delay_ms, uint32_t *temp_scaling_factor)
 Set the temp temperature precision in the config register.
 
uint8_t OBC_TEMP_SENSOR_configure_precision_values (uint8_t arg_precision, struct Set_Precision_Data *precision_data)
 Configures the precision global variables in preparation for setting the precision.
 
int32_t OBC_TEMP_SENSOR_get_temperature_cC ()
 The simplest and most foolproof way to get the OBC temperature in centi-celsius.
 

Variables

const uint16_t OBC_TEMP_SENSOR_device_addr = 0x48
 
const uint16_t OBC_TEMP_SENSOR_temp_register_addr = 0x00
 
const uint32_t OBC_TEMP_SENSOR_timeout_ms = 50
 
const uint16_t OBC_TEMP_SENSOR_config_register_addr = 0x01
 
const uint8_t OBC_TEMP_SENSOR_precision = 0x01 << 5
 
uint16_t OBC_TEMP_SENSOR_precision_scaling_factor = 100
 
float OBC_TEMP_SENSOR_precision_coefficient = OBC_TEMP_SENSOR_ten_bit_precision_coefficient
 
Temperature_Sensor_Data_Precision_Insignificant_Bytes_t OBC_TEMP_SENSOR_precision_insignificant_bits = OBC_TEMP_SENSOR_TEN_BIT_PRECISION_INSIGNIFICANT_BYTES
 

Function Documentation

◆ OBC_TEMP_SENSOR_configure_precision_values()

uint8_t OBC_TEMP_SENSOR_configure_precision_values ( uint8_t arg_precision,
struct Set_Precision_Data * precision_data )

Configures the precision global variables in preparation for setting the precision.

Parameters
arg_precisionprecision to set the temperature to in decimal (9, 10, 11, 12).
precision_datastruct containing all the values needed in precision calculations.
Returns
0 on success, 1 if user passed in an invalid precision value.
Here is the caller graph for this function:

◆ OBC_TEMP_SENSOR_convert_raw_to_deg_c()

int32_t OBC_TEMP_SENSOR_convert_raw_to_deg_c ( uint8_t raw_bytes[],
uint8_t precision_coefficient,
Temperature_Sensor_Data_Precision_Insignificant_Bytes_t precision_insignificant_bits,
uint16_t precision_scaling_factor )

Converts the raw bytes provided to a temperature in celsius and multiplied by a scaling factor based on the provided precision. Works on the four MSBs. Reference https://www.st.com/resource/en/datasheet/stds75.pdf page 15 and 18 for information on calculations and format of temperature data.

Parameters
raw_bytesBytes to convert to celsius float value
TEMP_SENSOR_data_precision_coefficientCoefficient used to get the temperature in the correct precision.
TEMP_SENSOR_data_precision_insignificant_bitsValue used to remove always zero bits and bits not used the provided precision.
precision_scaling_factorValue used to convert the temperature into a representation with no fractional parts.
Returns
the temperature in celsius after conversion.
Here is the caller graph for this function:

◆ OBC_TEMP_SENSOR_get_temp_precision()

int8_t OBC_TEMP_SENSOR_get_temp_precision ( void )

Reads the temperature precision from the config register. Refer to https://www.st.com/resource/en/datasheet/stds75.pdf page 17, table 6 and 7 for more information.

Parameters
None
Returns
-1 if there is an error otherwise the temperature precision in the least significant two bits as 0x01, 0x02, 0x03, 0x04.

◆ OBC_TEMP_SENSOR_get_temperature_cC()

int32_t OBC_TEMP_SENSOR_get_temperature_cC ( )

The simplest and most foolproof way to get the OBC temperature in centi-celsius.

Returns
The temperature in cC, if successful. 99999 (OBC_TEMP_SENSOR_ERROR_TEMPERATURE_CC) if unsuccessful.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OBC_TEMP_SENSOR_read_temperature()

uint8_t OBC_TEMP_SENSOR_read_temperature ( int32_t * result)

Reads the temperature from the STDS75DS2F and stores it in the provided variable pointer result. Precision can be configured from 9 to 12 bits. Temperature range is -55 to 125 degrees celsius with +/- 3 degrees celsius over the whole range.

Parameters
resultMemory location to store the temperature result (units: degrees celsius).
Returns
0 if successful, 1 if config register error, 2 if temp register error.
Note
You may think this gets you the temperature in cC, but it doesn't!!
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OBC_TEMP_SENSOR_set_temp_precision()

uint8_t OBC_TEMP_SENSOR_set_temp_precision ( uint8_t arg_precision,
uint32_t * temp_precision_conversion_delay_ms,
uint32_t * temp_scaling_factor )

Set the temp temperature precision in the config register.

Parameters
arg_precisionPrecision to set the temperature to in decimal (9, 10, 11, 12).
temp_precision_conversion_delay_msPointer to store the conversion delay.
temp_scaling_factorPointer to store the scaling factor.
Returns
0 on success, 1 on write error, 2 when passed an invalid precision value.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ OBC_TEMP_SENSOR_config_register_addr

const uint16_t OBC_TEMP_SENSOR_config_register_addr = 0x01

◆ OBC_TEMP_SENSOR_device_addr

const uint16_t OBC_TEMP_SENSOR_device_addr = 0x48

◆ OBC_TEMP_SENSOR_precision

const uint8_t OBC_TEMP_SENSOR_precision = 0x01 << 5

◆ OBC_TEMP_SENSOR_precision_coefficient

float OBC_TEMP_SENSOR_precision_coefficient = OBC_TEMP_SENSOR_ten_bit_precision_coefficient

◆ OBC_TEMP_SENSOR_precision_insignificant_bits

◆ OBC_TEMP_SENSOR_precision_scaling_factor

uint16_t OBC_TEMP_SENSOR_precision_scaling_factor = 100

◆ OBC_TEMP_SENSOR_temp_register_addr

const uint16_t OBC_TEMP_SENSOR_temp_register_addr = 0x00

◆ OBC_TEMP_SENSOR_timeout_ms

const uint32_t OBC_TEMP_SENSOR_timeout_ms = 50