Changeset - f04abd553284
[Not reviewed]
Merge default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-18 16:50:38
ethanzonca@CL-ENS241-08.cedarville.edu
Merge
6 files changed with 53 insertions and 29 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -34,9 +34,9 @@
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
 
 #define PRESSURE_ADDR 0xEF		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x27		// Read 0x27 - Write 0x26
 
 #define LIGHT_ADDR 0x95		// Read 0x95 - Write 0x94
 
 #define PRESSURE_ADDR 0xEE		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x26		// Read 0x27 - Write 0x26
 
 #define LIGHT_ADDR 0x94		// Read 0x95 - Write 0x94
 
 #define RTC_ADDR 0xB2			//DEBUG [Used for testing]      // Read 0xA3 - Write 0xA2
 
 
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -90,10 +90,10 @@ void masterComm_modules()
 
	masterComm_packetSend_signed(0,sensors_getBoardTemp());
 
 
	// Send Heater Status (Common for all modules)
 
	masterComm_packetSend_unsigned(1,/*Heater Status Get Function Here */0);
 
	masterComm_packetSend_unsigned(1,io_heaterStatus());
 
	
 
	// Send Battery Level (Common for all modules)
 
	masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */0);
 
	masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */999);
 
	
 
	
 
	// Send module specific sensor readings
 
@@ -111,16 +111,16 @@ void masterComm_modules()
 
			masterComm_packetSend_unsigned(3,sensors_getSpiTemp());
 
			
 
			// Send Ambient Light (Needs to be formatted)
 
			masterComm_packetSend_unsigned(4,/*Ambient Light Get Function Here */123);
 
			masterComm_packetSend_unsigned(4,sensors_getLux());
 
			
 
			// Send Humidity
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */456);		
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */999);		
 
			
 
			// Send Pressure 
 
			masterComm_packetSend_unsigned(6,/*Pressure Get Function Here */7890);			
 
			masterComm_packetSend_unsigned(6,sensors_getPressure());			
 
			
 
			// Send Altitude
 
			masterComm_packetSend_unsigned(7,/*Altitude Get Function Here */456789);
 
			masterComm_packetSend_unsigned(7,sensors_getAltitude());
 
			break;
 
			
 
		case 2:
slave/slave/lib/sensors.c
Show inline comments
 
@@ -7,6 +7,7 @@
 
 
 
#include <inttypes.h>
 
#include <math.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
@@ -21,7 +22,11 @@ int8_t	boardTemp;	// Board Temperature (
 
int32_t ut;			// Temperature from BMP085 (from i2c)
 
int32_t up;			// Pressure from BMP085 (from i2c)
 
uint16_t humid;		// Humidity (from i2c)
 
uint8_t light;		// Lux reading (from i2c)
 
uint8_t lightH;		// Higher byte from light sensor (from i2c)
 
uint8_t lightL;		// Lower byte from light sensor
 
uint8_t exponent;	// Exponent for Lux
 
uint8_t mantissa;	// Mantissa for Lux
 
uint32_t lux;		// Calculated Lux value
 
int8_t batt;		// Read battery voltage from ADC
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
@@ -46,6 +51,7 @@ int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t pressure;
 
uint32_t altitude;
 
 
 
 
@@ -132,13 +138,13 @@ void sensors_readBoardTemp()
 
 
void sensors_readPressure()
 
{
 
	i2c_write(0xEE, 0xF4, 0x2E);				//write 0x2E (temp) into 0xF4 (control register), (write is 0xEE)
 
	i2c_write(PRESSURE_ADDR, 0xF4, 0x2E);				//write 0x2E (temp) into 0xF4 (control register), (write is 0xEE)
 
	_delay_us(4500);							//wait 4.5 ms
 
	ut = i2c_read(PRESSURE_ADDR, 0xF6);
 
	ut = ut << 8;
 
	ut = ut | i2c_read(PRESSURE_ADDR, 0xF7);	//ut = MSB<<8 + LSB
 
	
 
	i2c_write(0xEE, 0xF4, 0x34);				//write 0x34 (pressure) into 0xF4 (control register), (write is 0xEE)
 
	i2c_write(PRESSURE_ADDR, 0xF4, 0x34);				//write 0x34 (pressure) into 0xF4 (control register), (write is 0xEE)
 
	_delay_us(4500);							//wait 4.5 ms
 
	up = i2c_read(PRESSURE_ADDR, 0xF6);
 
	up = up << 8;
 
@@ -179,6 +185,9 @@ void sensors_readPressure()
 
	x1 = (x1 * 3038) >> 16;
 
	x2 = (-7357 * pressure) >> 16;
 
	pressure += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
	
 
	//altitude = 44330 * (1 - pow((pressure / 101325), (1 / 5.255)));
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));
 
}
 
 
void sensors_readHumid()
 
@@ -189,14 +198,23 @@ void sensors_readHumid()
 
	humid = (humid / 16383) * 100;
 
}
 
 
void sensors_readLight()
 
void sensors_readLux()
 
{
 
	// FOR FIRST BYTE:
 
	light = i2c_read(LIGHT_ADDR, 0x03);
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 8xM7 + 4xM6 + 2xM5 + M4
 
	// light = 2^(exponent)*mantissa*0.72
 
 
	lightH = i2c_read(LIGHT_ADDR, 0x03);
 
	lightL = i2c_read(LIGHT_ADDR, 0x04);
 
	
 
	exponent = lightH;
 
	exponent = exponent >> 4;
 
	
 
	lightH = lightH << 4;
 
	mantissa = lightH | lightL;
 
	//mantissa = mantissa << 4;
 
	//mantissa = mantissa >> 4;
 
	
 
	//lux = (pow(2, exponent) * (float)(mantissa * 0.045));
 
	lux = (float)(pow(2,exponent) * mantissa) * 0.045;
 
	
 
	// FOR BOTH BYTES:
 
	// light = light << 4;
 
	// light = light | (0x0F & i2c_read(LIGHT_ADDR, 0x04));  //  This can be used to read in the 4 LSBs from the second register
 
@@ -230,13 +248,18 @@ uint16_t sensors_getHumid(void)			// Get
 
	return humid;
 
}
 
 
uint8_t sensors_getLight(void)		// Gets light from variable
 
uint32_t sensors_getLux(void)		// Gets light from variable
 
{
 
	return light;
 
	return lux;
 
}
 
 
//possibly uint8_t
 
int8_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
@@ -15,14 +15,15 @@ void sensors_readSpiTemp(void);		// Read
 
void sensors_readBoardTemp(void);	// Reads board temperature
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLight(void);		// Reads lux
 
void sensors_readLux(void);		// Reads lux
 
void sensors_readBatt(void);
 
 
int16_t sensors_getSpiTemp(void);	// Gets spi temperature from variable
 
int8_t sensors_getBoardTemp(void);	// Gets board temperature from variable
 
int32_t sensors_getPressure(void);	// Gets pressure from variable
 
uint16_t sensors_getHumid(void);	// Gets humidity from variable
 
uint8_t sensors_getLight(void);		// Gets lux from variable
 
uint32_t sensors_getLux(void);		// Gets lux from variable
 
int8_t sensors_getBatt(void);		// Gets battery voltage from variable
 
uint32_t sensors_getAltitude(void);		// Gets altitude from variable
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -123,10 +123,10 @@
 
	// Gathers data and performs functions for sensor daughter board
 
	sensors_readBoardTemp();		//Data Read
 
	sensors_readSpiTemp();			//Data Read
 
	//sensors_readPressure();			//Data Read
 
	//sensors_readHumid();				//Data Read
 
	//sensors_readLight();				//Data Read
 
	sensors_readBatt();
 
	sensors_readPressure();			//Data Read
 
	//sensors_readHumid();			//Data Read
 
	sensors_readLux();				//Data Read
 
	sensors_readBatt();				//Data Read
 
	 
 
 }
 
  
slave/slave/slave.c
Show inline comments
 
@@ -62,7 +62,7 @@ int main(void)
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	char buff[128];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");
 
			
 
    while(1)
 
@@ -82,8 +82,8 @@ int main(void)
 
			
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			//snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |SpiTemp: %i\r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getSpiTemp()); //DEBUG
 
			//serial0_sendString(buff); //DEBUG
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Heater: %u |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu \r\n",io_getModuleId(),sensors_getBoardTemp(),io_heaterStatus(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude()); //DEBUG
 
			serial0_sendString(buff); //DEBUG
 

	
 
			_delay_ms(2);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			led_off(0);
0 comments (0 inline, 0 general)