Changeset - a52064f7981f
[Not reviewed]
default
0 6 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-02-07 20:11:48
mkroening@CL-ENS241-07.cedarville.edu
Merge
6 files changed with 131 insertions and 109 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -28,7 +28,7 @@
 
#define DATATYPES_CAMERA 3
 
 
//Sensors and IO
 
#define SENSOR_LOOP 200				// Frequency of sensor reads (in ms)
 
#define SENSOR_LOOP 3000				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 40			// Temperature threshold in Fahrenheit where heater is activated
 
 
 //I2C Addresses
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -23,11 +23,22 @@ int8_t	moduleID;	// Slave Module ID from
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
 
	
 
	
 
	DDRA &= ~(1 << DDA7);		// Set PA7 to input for battery voltage divider
 
	// I bit of SREG needs to be set?  Global interrupt.
 
	ADCSRA |= (1 << ADEN);									// Enable ADC
 
	
 
	ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
 
	ADMUX |= (1 << REFS0); 
 
	ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);	// Set prescaler for ADC, 128 gives ADC freq of 125 KHz
 
	ADMUX |= (1 << REFS0);									// Set ADC reference voltage to AVCC
 
	ADMUX |= (1 << ADLAR);									// Sets 10 bit ADC to 8 bit
 
	ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0);		// Select ADC7 as the conversion channel
 
	ADCSRA |= (1 << ADATE);									// Enables auto trigger, determined in ADCSRB bits ADTS
 
	//ADCSRA |= (1 << ADIF);									// 
 
//ADCSRA |= (1 << ADIE);									// ADC interrupt enable set
 
	ADCSRB |= (0 << ADTS2) | (0 << ADTS1) | (0 << ADTS0);	// Set ADC auto trigger source to free running mode
 
	ADCSRA |= (1 << ADSC);									// Start ADC measurements.  ADC should now continuously run conversions, which are stored in ADCH 0x79
 
	
 
 
 }
 
 
 
 
slave/slave/lib/sensors.c
Show inline comments
 
@@ -22,6 +22,7 @@ int32_t ut;			// Temperature from BMP085
 
int32_t up;			// Pressure from BMP085 (from i2c)
 
uint16_t humid;		// Humidity (from i2c)
 
uint8_t light;		// Lux reading (from i2c)
 
int8_t batt;		// Read battery voltage from ADC
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
int16_t ac2;
 
@@ -204,6 +205,11 @@ void sensors_readLight()
 
	// light = 2^(exponent)*mantissa*0.045
 
}
 
 
void sensors_readBatt()
 
{
 
	batt = ADCH;					// Read battery level from ADC
 
}
 
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
@@ -227,4 +233,10 @@ uint16_t sensors_getHumid(void)			// Get
 
uint8_t sensors_getLight(void)		// Gets light from variable
 
{
 
	return light;
 
}
 
 
//possibly uint8_t
 
int8_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
@@ -16,13 +16,13 @@ void sensors_readBoardTemp(void);	// Rea
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLight(void);		// Reads lux
 
//void sensors_readBatt(void);
 
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
 
//int_t sensors_getBatt(void);
 
int8_t sensors_getBatt(void);		// Gets battery voltage from variable
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -79,7 +79,7 @@
 
 {
 
	DESELECT_TEMP;
 
	setup_spi();
 
	//sensors_setupPressure();
 
	sensors_setupPressure();
 
 }
 
  
 
 void modules_geiger_setup()
 
@@ -126,7 +126,7 @@
 
	//sensors_readPressure();			//Data Read
 
	//sensors_readHumid();				//Data Read
 
	//sensors_readLight();				//Data Read
 
	//sensors_readBatt();
 
	sensors_readBatt();
 
	 
 
 }
 
  
slave/slave/slave.c
Show inline comments
 
@@ -8,118 +8,117 @@
 
 * Matthew Kanning
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#include "config.h"
 
 
#include <stdio.h>
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#include <util/delay.h>
 
#include <avr/cpufunc.h>
 
#include <avr/interrupt.h>
 
#include "modules.h"
 
#include "lib/serial.h"
 
#include "lib/serparser.h"
 
#include "lib/led.h"
 
#include "lib/inputOutput.h"
 
#include "lib/i2c.h"
 
#include "lib/spi.h"
 
#include "lib/geiger.h"
 
#include "lib/sensors.h"
 
#include "lib/cameras.h"
 
#include "lib/loopTimer.h"
 
#include "lib/masterComm.h"
 
 
 
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	sei();	// Enable interrupts
 
	
 
}
 
 
 
int main(void)
 
{
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	led_configure();		// Configure ports and registers for LED operation
 
	io_configure();			// Configure IO ports and registers
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());				// Run setup functions for specific module
 
 
	
 
	//uint8_t test;		//Debug
 
	//uint8_t test2;	//Debug	
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");
 
	
 
			
 
    while(1)
 
    {	
 
		
 
 */
 

	
 

	
 
#include "config.h"
 

	
 
#include <stdio.h>
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#include <util/delay.h>
 
#include <avr/cpufunc.h>
 
#include <avr/interrupt.h>
 
#include "modules.h"
 
#include "lib/serial.h"
 
#include "lib/serparser.h"
 
#include "lib/led.h"
 
#include "lib/inputOutput.h"
 
#include "lib/i2c.h"
 
#include "lib/spi.h"
 
#include "lib/geiger.h"
 
#include "lib/sensors.h"
 
#include "lib/cameras.h"
 
#include "lib/loopTimer.h"
 
#include "lib/masterComm.h"
 

	
 

	
 

	
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	sei();	// Enable interrupts
 
	
 
}
 

	
 

	
 
int main(void)
 
{
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	led_configure();		// Configure ports and registers for LED operation
 
	io_configure();			// Configure IO ports and registers
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());				// Run setup functions for specific module
 

	
 
	
 
	//uint8_t test;		//Debug
 
	//uint8_t test2;	//Debug	
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");
 
			
 
    while(1)
 
    {	
 
		
 
		// Master communication
 
		masterComm_checkParser();
 
			
 
		
 
		
 
		// Main slave operations
 
		masterComm_checkParser();
 
			
 
		
 
		
 
		// Main slave operations
 
		if ((time_millis() % SENSOR_LOOP) == 0)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			led_on(0);
 
			sensors_readBoardTemp();	// Read board temperature sensor (Common on all slaves) (Data Read)
 
			modules_run(io_getModuleId());		// Runs specific module functions (like data reading)
 
			modules_run(io_getModuleId());		// Runs specific module functions (like data reading)
 
			
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			//snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Heater: %u\r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),io_heaterStatus()); //DEBUG
 
			//serial0_sendString(buff); //DEBUG
 
			snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Batt: %u\r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getBatt()); //DEBUG
 
			serial0_sendString(buff); //DEBUG
 

	
 
			_delay_ms(2);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			led_off(0);
 
			led_off(2);
 
		}
 
 
    }
 
	
 
	return 0;
 
}
 
 
 
 
 
 
		/********Examples of data reading and getting******************
 
		x = geiger_getCpm();				//Data get
 
		x = sensors_getSpiTemp();			//Data get
 
		x = sensors_getBoardTemp();			//Data get
 
		
 
		sensors_readSpiTemp();				//Data Read
 
		sensors_readBoardTemp();			//Data Read
 
		
 
		led_output(0xFF);					//Output value to LED array
 
		i2c_write(RTC_ADDR, 0x05, 0x3A);	//i2c Write Example
 
		
 
		PORTA &= ~(1 << PA1);	//OFF
 
		PORTA |= (1 << PA1);	//ON
 
		PORTB ^= (1 << PB0);	//Toggle
 
		
 
		sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		serial0_sendString(buff);
 
		
 
		**************************************************************/
 
		
 
		
 
		
 
		}
 

	
 
    }
 
	
 
	return 0;
 
}
 

	
 

	
 

	
 

	
 

	
 
		/********Examples of data reading and getting******************
 
		x = geiger_getCpm();				//Data get
 
		x = sensors_getSpiTemp();			//Data get
 
		x = sensors_getBoardTemp();			//Data get
 
		
 
		sensors_readSpiTemp();				//Data Read
 
		sensors_readBoardTemp();			//Data Read
 
		
 
		led_output(0xFF);					//Output value to LED array
 
		i2c_write(RTC_ADDR, 0x05, 0x3A);	//i2c Write Example
 
		
 
		PORTA &= ~(1 << PA1);	//OFF
 
		PORTA |= (1 << PA1);	//ON
 
		PORTB ^= (1 << PB0);	//Toggle
 
		
 
		sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		serial0_sendString(buff);
 
		
 
		**************************************************************/
 
		
 
		
 
		
 
		
 
\ No newline at end of file
0 comments (0 inline, 0 general)