Changeset - 0af57b79c256
[Not reviewed]
Merge default
0 4 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-26 15:05:31
ethanzonca@CL-ENS241-08.cedarville.edu
Merge
4 files changed with 40 insertions and 33 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -16,35 +16,31 @@ int8_t	moduleID;	// Slave Module ID from
 
 void io_configure()
 
 {
 
	// Configure ports/pins
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
 
	
 
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
 
	
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK (on SPI bus) to operate)
 
 
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip
 
	
 
	DDRA &= ~(1 << DDA7);		// Set PA7 to input for battery voltage divider
 
	
 
 
	//ADC register configurations for battery level detection on PA7
 
	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 << 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 &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));	// Set ADC auto trigger source to free running mode
 
		//ADCSRA |= (1 << ADIF);								// 
 
		//ADCSRA |= (1 << ADIE);								// ADC interrupt enable set
 
	ADCSRB &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));// Set ADC auto trigger source to free running mode
 
	ADCSRA |= (1 << ADEN);									// Enable ADC
 
	ADCSRA |= (1 << ADSC);									// Start ADC measurements.  ADC should now continuously run conversions, which are stored in ADCH 0x79
 
	
 
 
 }
 
 
 
 
 
 
   
 
 
 
 
 
  
 
 void io_readModuleId()
 
 {
 
	// Get ID from rotary dip and return it. 
 
@@ -64,9 +60,10 @@ int8_t	moduleID;	// Slave Module ID from
 
/*
 
	while(moduleID==0)
 
	{
 
		moduleID = i2c_read(EEPROM_ADDR, 0x04);
 
		moduleID = i2c_read(EEPROM_ADDR, 0x05);
 
	}
 
*/
 
 //moduleID = i2c_read(EEPROM_ADDR, 0x05);
 
 
 
 }
slave/slave/lib/sensors.c
Show inline comments
 
@@ -219,6 +219,13 @@ void sensors_readBatt()
 
	batt |= battL;
 
}
 
 
 
 
 
 
 
 
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
slave/slave/modules.c
Show inline comments
 
@@ -44,7 +44,6 @@
 
 
 
 void modules_run(uint8_t id)
 
 {
 
	 sensors_readBatt();				//Data Read
 
	switch(id)
 
	{
 
		case 0:
slave/slave/slave.c
Show inline comments
 
@@ -45,6 +45,10 @@ void micro_setup()
 

	
 
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
 

	
 
		
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
@@ -54,40 +58,40 @@ int main(void)
 
	serial0_setup();		// Config serial port
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());				// Run setup functions for specific module
 
	modules_setup(io_getModuleId());	// Run setup functions for specific module
 

	
 
	
 
	//uint8_t test;		//Debug
 
	//uint8_t test2;	//Debug	
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[128];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");
 
	char buff[128];						//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");	//DEBUG
 
			
 
    while(1)
 
    {	
 
		
 
		// Master communication
 
		masterComm_checkParser();
 
			
 
		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
 
		{
 
			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)
 
			
 
			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)
 
			
 
			i2c_write(EEPROM_ADDR, 0x05, 0x01);
 
			
 
			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
 
			//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(2);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			_delay_ms(1);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			led_off(0);
 
			led_off(2);
 
			led_output(i2c_read(EEPROM_ADDR, 0x05));
 
		}
 

	
 
    }
0 comments (0 inline, 0 general)