Changeset - 448ac1359093
[Not reviewed]
default
0 6 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-03-18 21:59:28
kripperger@CL-SEC241-09.cedarville.edu
Enable Serial1, WDT, Battery sense, LED Timers
6 files changed with 38 insertions and 29 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -28,8 +28,8 @@
 
#define DATATYPES_CAMERA 3
 
 
//Sensors and IO
 
#define SENSOR_LOOP 100				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 40			// Temperature threshold in Fahrenheit where heater is activated
 
#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
 
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -96,11 +96,11 @@ int8_t	moduleID;	// Slave Module ID from
 
	  if (sensors_getBoardTemp() <= HEATER_THRESHOLD)
 
	  {
 
		  io_heaterOn();
 
		  led_on(1);
 
		  led_on(3);
 
	  } 
 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5))
 
	  {
 
		  io_heaterOff();
 
		  led_off(1);
 
		  led_off(3);
 
	  }
 
  }
 
\ No newline at end of file
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -6,6 +6,7 @@
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <stdio.h>
 
#include "../config.h"
 
@@ -16,8 +17,10 @@
 
#include "sensors.h"
 
#include "geiger.h"
 
#include "led.h"
 
#include "loopTimer.h"
 
 
uint8_t dataTypes;
 
volatile uint32_t lastRX;
 
char buff2[64];
 
 
 
@@ -160,14 +163,20 @@ void masterComm_send()
 
 
void masterComm_checkParser()
 
{
 
	if ((time_millis() - lastRX) > 200)	// Timer for LED
 
	{
 
		led_off(2);
 
	}
 
	
 
	if (serparser_parse() == PARSERESULT_PARSEOK)
 
	{
 
		if (getPayloadType() == ('@'-0x30))		// Request for data recieved
 
		{
 
			led_on(2);
 
			lastRX = time_millis();
 
			
 
			// Send all data
 
			masterComm_send();
 
			//led_off(2);
 
		}	
 
	}
 
}
slave/slave/lib/sensors.c
Show inline comments
 
@@ -28,6 +28,7 @@ uint8_t mantissa;	// Mantissa for Lux
 
uint32_t lux;		// Calculated Lux value
 
uint8_t battL;		// Low byte of ADC
 
uint16_t batt;		// Read battery voltage from ADC
 
uint16_t vBatt;		// battery voltage
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
int16_t ac2;
 
@@ -217,6 +218,7 @@ void sensors_readBatt()
 
	batt = ADCH;					// Read high battery byte from ADC (only two LSBs)
 
	batt = batt << 8;
 
	batt |= battL;
 
	vBatt = (batt * 10.0) / 67.4;
 
}
 
 
 
@@ -253,7 +255,7 @@ uint32_t sensors_getLux(void)		// Gets l
 
 
uint16_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
	return vBatt;
 
}
 
 
uint32_t sensors_getAltitude(void)
slave/slave/lib/serial.c
Show inline comments
 
@@ -39,9 +39,6 @@ void serial0_setup() {
 
 
 
 
 
 
 
void serial1_setup() {
 
//PROVEN in test project
 
 
@@ -54,7 +51,7 @@ void serial1_setup() {
 
	UBRR1H = (unsigned char)(USART1_BAUD_PRESCALE>>8);
 
	UBRR1L = (unsigned char)USART1_BAUD_PRESCALE;
 
	
 
	UCSR1B |= (1 << RXCIE1); // Enable interrupt
 
	//UCSR1B |= (1 << RXCIE1); // Enable interrupt
 
}
 
 
void serial1_ion() {
slave/slave/slave.c
Show inline comments
 
@@ -20,6 +20,7 @@
 
#include <util/delay.h>
 
#include <avr/cpufunc.h>
 
#include <avr/interrupt.h>
 
#include <avr/wdt.h>
 
#include "modules.h"
 
#include "lib/serial.h"
 
#include "lib/serparser.h"
 
@@ -38,63 +39,63 @@
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	sei();	// Enable interrupts
 
	
 
	sei();			// Enable interrupts
 
	MCUSR = 0;		// Clear reset flags
 
	wdt_disable();	// Disable WDT
 
	_delay_ms(20);	// Power debounce
 
}
 

	
 

	
 

	
 
int main(void)
 
{
 
	// Writes ID to EEPROM, change for all modules and delete after programming
 
	// 0 is for generic setup, 1 is for sensors, 2 is for Geiger, 3 is for cameras
 
	// 0 is for generic setup,	 1 is for sensors,	 2 is for Geiger,	3 is for cameras
 
	//i2c_write(EEPROM_ADDR, 0x05, 0x03);
 
		
 
	// Power debounce
 
	_delay_ms(20);
 
		
 
	// Initialize	
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	//watchdog_setup();		// Setup watchdog timer
 
	watchdog_setup();		// Setup watchdog timer
 
	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
 
	serial0_setup();		// Config serial port 0
 
	serial1_setup();		// Config serial port 1
 
	
 
	_delay_ms(50);	// Setup hold delay
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());	// Run setup functions for specific module
 

	
 
	uint32_t lastLoop = 0;
 
	
 
	// Serial output //DEBUG
 
	char buff[128];						//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");	//DEBUG
 
	serial1_sendString("Starting Slave\r\n");	//DEBUG
 
			
 
    while(1)
 
    {	
 
		wdt_reset();
 
		
 
		// Master communication
 
		masterComm_checkParser();	//Checks parser for data requests from master
 

	
 
		// Main slave operations
 
		if ((time_millis() % SENSOR_LOOP) == 0)	// Uses program timer to run every so often. Time interval defined in config.h
 
		if ((time_millis() - lastLoop) > SENSOR_LOOP)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			led_on(0);
 
			
 
			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 \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //DEBUG
 
//			serial0_sendString(buff); //DEBUG
 

	
 
			_delay_ms(1);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //DEBUG
 
			serial1_sendString(buff); //DEBUG
 
			
 
			led_off(0);
 
			led_off(2);
 
			
 
			//led_output(i2c_read(EEPROM_ADDR, 0x05));	// Debugging, delete
 
			//led_output(io_getModuleId());
 
			lastLoop = time_millis();
 
		}
 

	
 
    }
0 comments (0 inline, 0 general)