Changeset - 021932f9f264
[Not reviewed]
default
0 7 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-03-28 23:23:44
kripperger@CL-SEC241-09.cedarville.edu
Attempts to fix Humidity sensor
7 files changed with 62 insertions and 29 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -26,13 +26,13 @@
 
#define DATATYPES_SENSOR 8
 
#define DATATYPES_GEIGER 4
 
#define DATATYPES_CAMERA 3
 
 
//Sensors and IO
 
#define SENSOR_LOOP 200				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 0			// Temperature threshold in Fahrenheit where heater is activated
 
#define HEATER_THRESHOLD 77			// Temperature threshold in Fahrenheit where heater is activated
 
#define CAMERA_FREQ 10000		// Camera pulse frequency (Should be 30000 for 30 Secs)
 
#define CAMERA_PULSE 500			// Camera pulse duration
 
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
slave/slave/lib/i2c.c
Show inline comments
 
@@ -2,12 +2,13 @@
 
 * i2c.c
 
 *
 
 * Created: 11/7/2012 7:18:23 PM
 
 *  Author: kripperger
 
 */ 
 
 
#include <util/delay.h>
 
#include <inttypes.h>
 
#include <compat/twi.h>
 
#include "loopTimer.h"
 
#include "../config.h"
 
#include "i2c.h"
 
 
@@ -41,38 +42,38 @@ unsigned char i2c_start(unsigned char ad
 
    uint8_t   twst;
 
 
	// send START condition
 
	TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
 
 
	// wait until transmission completed
 
	startTime = time_millis();
 
//	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}
 
//	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
//			break;	// Timeout Reached!
 
//		}
 
//	}
 
 
	// check value of TWI Status Register. Mask prescaler bits.
 
	twst = TW_STATUS & 0xF8;
 
	if ( (twst != TW_START) && (twst != TW_REP_START)) return 1;
 
 
	// send device address
 
	TWDR = address;
 
	TWCR = (1<<TWINT) | (1<<TWEN);
 
 
	// wail until transmission completed and ACK/NACK has been received
 
	startTime = time_millis();
 
//	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}
 
//	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
//			break;	// Timeout Reached!
 
//		}
 
//	}
 
 
	// check value of TWI Status Register. Mask prescaler bits.
 
	twst = TW_STATUS & 0xF8;
 
	if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return 1;
 
 
	return 0;
 
@@ -174,19 +175,19 @@ unsigned char i2c_rep_start(unsigned cha
 
void i2c_stop(void)
 
{
 
    /* send stop condition */
 
	TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
 
	
 
	// wait until stop condition is executed and bus released
 
	startTime = time_millis();
 
//	startTime = time_millis();
 
	while(TWCR & (1<<TWSTO))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
//			break;	// Timeout Reached!
 
//		}
 
	}
 
 
}/* i2c_stop */
 
 
 
 
@@ -278,14 +279,14 @@ unsigned char i2c_readNak(void)
 
 
 
 Return:  void
 
*************************************************************************/
 
void i2c_write(unsigned char addr, unsigned char reg, unsigned char data)
 
{
 
	i2c_start_wait(addr+I2C_WRITE);     // set device address and write mode
 
	i2c_writeX(reg);                     // write register address
 
	i2c_writeX(data);                    // write value data to register
 
	i2c_writeX(reg);                    // write register address
 
	i2c_writeX(data);                   // write value data to register
 
	i2c_stop();                         // set stop condition = release bus
 
 
}/* i2c_write */
 
 
 
 
@@ -314,18 +315,45 @@ uint8_t i2c_read(unsigned char addr, uns
 
uint16_t i2c_read16(unsigned char addr)
 
{
 
	uint16_t   data;
 
	uint8_t   dataL;
 
	
 
	i2c_start_wait(addr+I2C_WRITE);		// set device address and write mode
 
	
 
 
	i2c_rep_start(addr+I2C_READ);   // set device address and read mode
 
	data = i2c_readAck();               // read one byte
 
	dataL = i2c_readNak();
 
	i2c_stop();
 
	
 
	data = data << 8;
 
	data = data | dataL;
 
	
 
	return data;
 
 
}/* i2c_read16 */
 
\ No newline at end of file
 
}/* i2c_read16 */
 
 
uint16_t i2c_humidRead()
 
{
 
	uint16_t   data;
 
	uint8_t   dataL;
 
	
 
	//i2c_start_wait(HUMID_ADDR+I2C_WRITE);	// set device address and write mode
 
	//i2c_rep_start(HUMID_ADDR+I2C_READ);   // set device address and read mode
 
	
 
	i2c_start(HUMID_ADDR+I2C_WRITE);	// Measurement Request
 
	i2c_stop();					// Stop
 
	
 
	
 
	i2c_start(HUMID_ADDR+I2C_READ);		// Measurement Request	
 
 
	i2c_readAck();               // read one byte
 
	i2c_readNak();
 
	data = i2c_readAck();               // read one byte
 
	dataL = i2c_readAck();	
 
	i2c_stop();
 
	
 
	data = data << 8;
 
	data = data | dataL;
 
	
 
	return data;
 
 
}
 
\ No newline at end of file
slave/slave/lib/i2c.h
Show inline comments
 
@@ -59,7 +59,9 @@ void i2c_write(unsigned char addr, unsig
 
 
unsigned char i2c_read(unsigned char addr, unsigned char reg);
 
 
/////////////////added for humidity
 
uint16_t i2c_read16(unsigned char addr);
 
 
uint16_t i2c_humidRead(void);
 
 
#endif /* I2C_H_ */
 
\ No newline at end of file
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -95,12 +95,12 @@ int8_t	moduleID;	// Slave Module ID from
 
	  // Gets board temperature and enables heater if below threshold
 
	  if (sensors_getBoardTemp() <= HEATER_THRESHOLD)
 
	  {
 
		  io_heaterOn();
 
		  led_on(3);
 
	  } 
 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5))
 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 4))
 
	  {
 
		  io_heaterOff();
 
		  led_off(3);
 
	  }
 
  }
 
\ No newline at end of file
slave/slave/lib/sensors.c
Show inline comments
 
@@ -189,14 +189,17 @@ void sensors_readPressure()
 
	
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));
 
}
 
 
void sensors_readHumid()
 
{
 
	humid = i2c_read16(HUMID_ADDR);
 
	
 
	//i2c_write(HUMID_ADDR, 0x00, 0x00);		//Measurement Request
 
	//humid = i2c_read16(HUMID_ADDR);
 
 
	humid = i2c_humidRead();
 
 
	//calculations to relative humidity: humid = (humid/((2^14) - 1))*100%       >> is divide by power, << is multiply by power, 2^14-1 = 16383
 
	 //humid = (humid / 16383) * 100;
 
}
 
 
void sensors_readLux()
 
{
slave/slave/modules.c
Show inline comments
 
@@ -128,13 +128,13 @@
 
 }
 
  
 
 void modules_sensors()
 
 {
 
	// Gathers data and performs functions for sensor daughter board
 
	sensors_readBoardTemp();		//Data Read
 
	sensors_readSpiTemp();			//Data Read
 
	sensors_readSpiTemp();			//Data Read	
 
	sensors_readPressure();			//Data Read
 
	sensors_readHumid();			//Data Read
 
	sensors_readLux();				//Data Read
 
	 
 
 }
 
  
slave/slave/slave.c
Show inline comments
 
@@ -91,13 +91,13 @@ int main(void)
 
			sensors_readBatt();				// Read Battery level
 
			sensors_readBoardTemp();		// Read board temperature sensor (Common on all slaves) (Data Read)
 
			modules_run(io_getModuleId());	// Runs specific module functions (like data reading)
 
			
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %u |Humidity: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt(),sensors_getHumid()); //DEBUG
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Press: %lu |Altitude: %lu |Batt: %u |Humidity: %u |spiTemp: %i \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt(),sensors_getHumid(),sensors_getSpiTemp()); //DEBUG
 
			serial1_sendString(buff); //DEBUG
 
			
 
			led_off(0);
 
			lastLoop = time_millis();
 
			
 
// Writes ID to EEPROM, change for all modules and delete after programming
0 comments (0 inline, 0 general)