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
 
@@ -25,14 +25,14 @@
 
#define DATATYPES_GENERIC 3
 
#define DATATYPES_SENSOR 8
 
#define DATATYPES_GEIGER 4
 
#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
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
 
 #define PRESSURE_ADDR 0xEE		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x26		// Read 0x27 - Write 0x26
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -93,14 +93,14 @@ int8_t	moduleID;	// Slave Module ID from
 
  void io_regulateTemp()
 
  {
 
	  // Gets board temperature and enables heater if below threshold
 
	  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
 
@@ -3,24 +3,27 @@
 
 *
 
 * Created: 1/22/2013 3:40:53 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <stdio.h>
 
#include "../config.h"
 
#include "masterComm.h"
 
#include "serial.h"
 
#include "serparser.h"
 
#include "inputOutput.h"
 
#include "sensors.h"
 
#include "geiger.h"
 
#include "led.h"
 
#include "loopTimer.h"
 
 
uint8_t dataTypes;
 
volatile uint32_t lastRX;
 
char buff2[64];
 
 
 
char masterComm_checksum(const char* stringPtr)
 
{
 
	char sum = 0;
 
@@ -157,18 +160,24 @@ void masterComm_send()
 
	masterComm_modules();	// Send sensor data
 
}
 
 
 
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
 
@@ -25,12 +25,13 @@ uint8_t lightH;		// Higher byte from lig
 
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
 
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;
 
int16_t ac3;
 
uint16_t ac4;
 
uint16_t ac5;
 
@@ -214,12 +215,13 @@ void sensors_readLux()
 
void sensors_readBatt()
 
{
 
	battL = ADCL;					// Read low battery byte from ADC (all 8 bits)
 
	batt = ADCH;					// Read high battery byte from ADC (only two LSBs)
 
	batt = batt << 8;
 
	batt |= battL;
 
	vBatt = (batt * 10.0) / 67.4;
 
}
 
 
 
 
 
 
@@ -250,13 +252,13 @@ uint32_t sensors_getLux(void)		// Gets l
 
{
 
	return lux;
 
}
 
 
uint16_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
	return vBatt;
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/serial.c
Show inline comments
 
@@ -36,28 +36,25 @@ void serial0_setup() {
 
	
 
	//UCSR0A |= (1<<RXC0);
 
}
 
 
 
 
 
 
 
void serial1_setup() {
 
//PROVEN in test project
 
 
	/* Enable receiver and transmitter */
 
	UCSR1B |= (1<<RXEN1)|(1<<TXEN1); // Enable rx/tx
 
	/* Set frame format: 8data, 1stop bit */
 
	UCSR1C |= (1 << UCSZ10) | (1 << UCSZ11); // - 1 stop bit
 
	
 
	/* Set baud rate */
 
	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() {
 
	UCSR1B |= (1<<RXEN1); // Enable rx
 
	UCSR1B |= (1 << RXCIE1); // Enable interrupt
 
}
slave/slave/slave.c
Show inline comments
 
@@ -17,12 +17,13 @@
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#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"
 
#include "lib/led.h"
 
#include "lib/inputOutput.h"
 
#include "lib/i2c.h"
 
@@ -35,69 +36,69 @@
 
#include "lib/watchdog.h"
 

	
 

	
 
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();
 
		}
 

	
 
    }
 
	
 
	return 0;
 
}
0 comments (0 inline, 0 general)