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
 
@@ -29,7 +29,7 @@
 
 
//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
 
slave/slave/lib/i2c.c
Show inline comments
 
@@ -5,6 +5,7 @@
 
 *  Author: kripperger
 
 */ 
 
 
#include <util/delay.h>
 
#include <inttypes.h>
 
#include <compat/twi.h>
 
#include "loopTimer.h"
 
@@ -44,14 +45,14 @@ unsigned char i2c_start(unsigned char ad
 
	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;
 
@@ -62,14 +63,14 @@ unsigned char i2c_start(unsigned char ad
 
	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;
 
@@ -177,13 +178,13 @@ void i2c_stop(void)
 
	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 */
 
@@ -281,8 +282,8 @@ unsigned char i2c_readNak(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 */
 
@@ -317,7 +318,7 @@ uint16_t i2c_read16(unsigned char addr)
 
	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();
 
@@ -328,4 +329,31 @@ uint16_t i2c_read16(unsigned char addr)
 
	
 
	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
 
@@ -62,4 +62,6 @@ unsigned char i2c_read(unsigned char add
 
/////////////////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
 
@@ -98,7 +98,7 @@ int8_t	moduleID;	// Slave Module ID from
 
		  io_heaterOn();
 
		  led_on(3);
 
	  } 
 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5))
 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 4))
 
	  {
 
		  io_heaterOff();
 
		  led_off(3);
slave/slave/lib/sensors.c
Show inline comments
 
@@ -192,8 +192,11 @@ void sensors_readPressure()
 
 
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;
 
}
slave/slave/modules.c
Show inline comments
 
@@ -131,7 +131,7 @@
 
 {
 
	// 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
 
@@ -94,7 +94,7 @@ int main(void)
 
			
 
			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);
0 comments (0 inline, 0 general)