CLEON  Version 1
Cloud-Offloaded GPS Receiver
sys_sensors.h File Reference

Sensors related functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sensors_s
 
union  cleon_sensor_data_u
 

Macros

#define SIZE_OF_SENSOR_DATA_IN_BYTE   8
 
#define SHT11_SDA_SET_TO_OUTPUT_PIN()   (SENSOR_SHT11_PORT(DIR) |= BV(SENSOR_SHT11_SDA_PIN)) /* SDA Output=0 */
 
#define SHT11_SDA_SET_TO_INPUT_PIN()   (SENSOR_SHT11_PORT(DIR) &= ~BV(SENSOR_SHT11_SDA_PIN)) /* SDA Input */
 
#define SHT11_IS_SDA_HIGH   (SENSOR_SHT11_PORT(IN) & BV(SENSOR_SHT11_SDA_PIN))
 
#define SHT11_SCL_LOW()   (SENSOR_SHT11_PORT(OUT) &= ~BV(SENSOR_SHT11_SCL_PIN)) /* SCL Output=0 */
 
#define SHT11_SCL_HIGH()   (SENSOR_SHT11_PORT(OUT) |= BV(SENSOR_SHT11_SCL_PIN)) /* SCL Output=1 */
 
#define SHT11_TIMING_DELAY(n)
 
#define STATUS_REG_W   0x06
 
#define STATUS_REG_R   0x07
 
#define MEASURE_TEMP   0x03
 
#define MEASURE_HUMI   0x05
 
#define RESET   0x1E
 

Functions

void SYS_SENSORS_Init (void)
 Initializing sensors.
 
void SYS_SENSORS_SHT11_Init (void)
 Initializing SHT11 (Humidity & Temperature sensor)
 
void SYS_SENSORS_SHT11_On (void)
 Turn SHT11 on.
 
void SYS_SENSORS_SHT11_Off (void)
 Turn SHT11 off.
 
unsigned int SYS_SENSORS_SHT11_ReadTemperature (void)
 Read SHT11 temperature.
 
unsigned int SYS_SENSORS_SHT11_ReadHumidity (void)
 Read SHT11 humidity.
 
unsigned int SYS_SENSORS_SHT11_Command (unsigned char ucCommand)
 Transmit command to SHT11.
 
void SYS_SENSORS_S1087_Init (void)
 Initializing light sensor S1087 (PAR)
 
unsigned int SYS_SENSORS_S1087_Read (void)
 Read sensor value of S1087 (PAR)
 
void SYS_SENSORS_S108701_Init (void)
 Initializing light sensor S1087-01 (TSR)
 
unsigned int SYS_SENSORS_S108701_Read (void)
 Read sensor value of S1087-01 (TSR)
 

Detailed Description

Sensors related functions.

Definition in file sys_sensors.h.

Macro Definition Documentation

#define MEASURE_HUMI   0x05

Definition at line 34 of file sys_sensors.h.

#define MEASURE_TEMP   0x03

Definition at line 33 of file sys_sensors.h.

#define RESET   0x1E

Definition at line 35 of file sys_sensors.h.

#define SHT11_IS_SDA_HIGH   (SENSOR_SHT11_PORT(IN) & BV(SENSOR_SHT11_SDA_PIN))

Definition at line 18 of file sys_sensors.h.

#define SHT11_SCL_HIGH ( )    (SENSOR_SHT11_PORT(OUT) |= BV(SENSOR_SHT11_SCL_PIN)) /* SCL Output=1 */

Definition at line 21 of file sys_sensors.h.

#define SHT11_SCL_LOW ( )    (SENSOR_SHT11_PORT(OUT) &= ~BV(SENSOR_SHT11_SCL_PIN)) /* SCL Output=0 */

Definition at line 20 of file sys_sensors.h.

#define SHT11_SDA_SET_TO_INPUT_PIN ( )    (SENSOR_SHT11_PORT(DIR) &= ~BV(SENSOR_SHT11_SDA_PIN)) /* SDA Input */

Definition at line 17 of file sys_sensors.h.

#define SHT11_SDA_SET_TO_OUTPUT_PIN ( )    (SENSOR_SHT11_PORT(DIR) |= BV(SENSOR_SHT11_SDA_PIN)) /* SDA Output=0 */

Definition at line 16 of file sys_sensors.h.

#define SHT11_TIMING_DELAY (   n)
Value:
do{ \
for(int z = 0 ; z < n ; z++){ \
__delay_cycles(12000); \
} \
}while(0)

Definition at line 24 of file sys_sensors.h.

#define SIZE_OF_SENSOR_DATA_IN_BYTE   8

Definition at line 10 of file sys_sensors.h.

#define STATUS_REG_R   0x07

Definition at line 32 of file sys_sensors.h.

#define STATUS_REG_W   0x06

Definition at line 31 of file sys_sensors.h.

Function Documentation

void SYS_SENSORS_Init ( void  )

Initializing sensors.

Returns
void
Parameters
void

Definition at line 126 of file sys_sensors.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void SYS_SENSORS_S108701_Init ( void  )

Initializing light sensor S1087-01 (TSR)

Returns
void
Parameters
void

Definition at line 73 of file sys_sensors.c.

Here is the caller graph for this function:

unsigned int SYS_SENSORS_S108701_Read ( void  )

Read sensor value of S1087-01 (TSR)

Returns
void
Parameters
void

Definition at line 88 of file sys_sensors.c.

{
double dLight = 0;
// Sensor value (in 12-bit ADC-representation)
dLight = (double) ADC12MEM1;
// Voltage difference (in 12-bit ADC-representation) 3890
dLight = 4096 - dLight;
// For S1087-01, it gives 10nA upon sensing 1 lux
// It means that 5mV appears across 500k resistor
// Therefore, light intensity (lux) = Vsense (V) * 1 (lux) / 5m (V)
// That is, Vsense * 200;
dLight = dLight / 4096 * 2.88 * 200;
// Manually found calibration factor
dLight = dLight * 8;
#if (DEBUG_MODE) && (DUMP_SENSOR_VALUE_VIA_USB)
SYS_USB_Printf("Light2(TSR): %.4d \r\n", (unsigned int)dLight);
#endif
return (unsigned int) dLight;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SYS_SENSORS_S1087_Init ( void  )

Initializing light sensor S1087 (PAR)

Returns
void
Parameters
void

Definition at line 24 of file sys_sensors.c.

Here is the caller graph for this function:

unsigned int SYS_SENSORS_S1087_Read ( void  )

Read sensor value of S1087 (PAR)

Returns
void
Parameters
void

Definition at line 39 of file sys_sensors.c.

{
double dLight = 0;
// Sensor value (in 12-bit ADC-representation)
dLight = (double) ADC12MEM0;
// Voltage difference (in 12-bit ADC-representation)
dLight = 4096 - dLight;
// For S1087, it gives 1nA upon sensing 1 lux
// It means that 0.5mV appears across 500k resistor
// Therefore, light intensity (lux) = Vsense (V) * 1 (lux) / 0.5m (V)
// That is, Vsense * 2000;
dLight = dLight / 4096 * 2.88 * 2000;
#if (DEBUG_MODE) && (DUMP_SENSOR_VALUE_VIA_USB)
SYS_USB_Printf("Light1(PAR): %.4d \r\n", (unsigned int) dLight);
#endif
return (unsigned int) dLight;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int SYS_SENSORS_SHT11_Command ( unsigned char  ucCommand)

Transmit command to SHT11.

Returns
uiReceivedData - data received from SHT11 or FAIL if command is unsuccessful
Parameters
ucCommand- command to be transmitted

Definition at line 352 of file sys_sensors.c.

{
unsigned long n;
if(!SYS_SENSORS_SHT11_Write(ucCommand)) {
return _FAIL_;
}else{
for(n = 0; n < 250000; n++) {
#pragma diag_suppress = Pe550
unsigned char t0, t1, rcrc;
return (t0 << 8) | t1;
}
}
}
#pragma diag_suppress = Pe940
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SYS_SENSORS_SHT11_Init ( void  )

Initializing SHT11 (Humidity & Temperature sensor)

      - SHT11 requires 11ms after power on
Returns
void
Parameters
void

Definition at line 142 of file sys_sensors.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void SYS_SENSORS_SHT11_Off ( void  )

Turn SHT11 off.

Returns
void
Parameters
void

Definition at line 217 of file sys_sensors.c.

Here is the caller graph for this function:

void SYS_SENSORS_SHT11_On ( void  )

Turn SHT11 on.

Returns
void
Parameters
void

Definition at line 200 of file sys_sensors.c.

{
SENSOR_SHT11_PORT(OUT) &= ~(BV(SENSOR_SHT11_SDA_PIN) | BV(SENSOR_SHT11_SCL_PIN)); // Set pull-up register for DATA and SCK pins
SENSOR_SHT11_PORT(DIR) |= BV(SENSOR_SHT11_PWR_PIN) | BV(SENSOR_SHT11_SCL_PIN); // SHT11 power on & Set SCK pin as output
SHT11_TIMING_DELAY(20); // wait about 20ms for SHT11 stabilization
}

Here is the caller graph for this function:

unsigned int SYS_SENSORS_SHT11_ReadHumidity ( void  )

Read SHT11 humidity.

Returns
void
Parameters
void

Definition at line 177 of file sys_sensors.c.

{
unsigned int uiRelativeHumidity = 0;
unsigned int uiHumidity = 0;
uiRelativeHumidity = SYS_SENSORS_SHT11_Command(MEASURE_HUMI);
uiHumidity = (unsigned int)( -4 + 0.0405 * uiRelativeHumidity - 2.8e-6 * (uiRelativeHumidity * uiRelativeHumidity));
#if (DEBUG_MODE) && (DUMP_SENSOR_VALUE_VIA_USB)
SYS_USB_Printf("Humidity : %.4d \r\n", (unsigned int) uiHumidity);
#endif
return uiHumidity;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int SYS_SENSORS_SHT11_ReadTemperature ( void  )

Read SHT11 temperature.

Returns
void
Parameters
void

Definition at line 155 of file sys_sensors.c.

{
unsigned int uiTemp = 0;
// Read temperature in Fahrenheit
uiTemp = (unsigned int) (-40.00 + 0.018 * SYS_SENSORS_SHT11_Command(MEASURE_TEMP));
#if (DEBUG_MODE) && (DUMP_SENSOR_VALUE_VIA_USB)
SYS_USB_Printf("Temp(F) : %.4d \r\n", (unsigned int) uiTemp);
#endif
return uiTemp;
}

Here is the call graph for this function:

Here is the caller graph for this function: