Changeset - 0fb8009f1a0a
[Not reviewed]
default
0 3 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-02-28 17:00:49
mkroening@CL-ENS241-07.cedarville.edu
EEPROM testing
3 files changed with 5 insertions and 12 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -3,92 +3,85 @@
 
 *
 
 * Created: 11/7/2012 7:17:52 PM
 
 *  Author: kripperger
 
 */ 
 
 
#include <avr/io.h>
 
#include "../config.h"
 
#include "inputOutput.h"
 
#include "led.h"
 
#include "sensors.h"
 
 
int8_t	moduleID;	// Slave Module ID from rotary dip switch (or EEPROM)
 
 
 void io_configure()
 
 {
 
	// Configure ports/pins
 
	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
 
	//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. 
 
	moduleID = 0;
 
	
 
	/*
 
	// This method is temporary as the next release will read the module ID from EEPROM
 
	PORTC |= (1 << PC2);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC3);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC4);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC5);	// Pull pins on rotary dip high
 
	
 
	moduleID = ((PINC & 0b00011100) >> 2);		// Read Dip Encoder
 
	moduleID = ~moduleID;						//Invert Dip reading
 
	moduleID = (moduleID & 0b0111);				//Mask bits
 
	*/
 
 
	/*
 
	while(moduleID==0)
 
	{
 
		moduleID = i2c_read(EEPROM_ADDR, 0x05);
 
	}
 
	*/
 
	
 
	//moduleID = i2c_read(EEPROM_ADDR, 0x05);
 
 
 
 }
 
 
 
 
 
 uint8_t io_getModuleId()
 
 {
 
	return moduleID;
 
 }
 
 
 
 
 
 void io_heaterOn()
 
 {		
 
	PORTB |= (1 << PB4);	//ON
 
 }
 
 
 
 void io_heaterOff()
 
 {
 
	PORTB &= ~(1 << PB4);	//OFF
 
 }
 
 
 
 uint8_t io_heaterStatus()
 
 {
 
	 uint8_t state;
 
	 state = 0;
 
	 
slave/slave/lib/sensors.h
Show inline comments
 
/*
 
 * sensors.h
 
 *
 
 * Created: 11/19/2012 9:24:50 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef SENSORS_H_
 
#define SENSORS_H_
 
 
 
void sensors_setupPressure(void);	// Reads pressure calibration values
 
void sensors_readSpiTemp(void);		// Reads spi temperature
 
void sensors_readBoardTemp(void);	// Reads board temperature
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLux(void);			// Reads lux
 
void sensors_readBatt(void);
 
void sensors_readBatt(void);		// Reads battery voltage from ADC
 
 
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
 
uint32_t sensors_getLux(void);		// Gets lux from variable
 
uint16_t sensors_getBatt(void);		// Gets battery voltage from variable
 
uint32_t sensors_getAltitude(void);	// Gets altitude from variable
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/slave.c
Show inline comments
 
@@ -26,49 +26,49 @@
 
#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)
 
{
 
	// 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
 
	//i2c_write(EEPROM_ADDR, 0x05, 0x01);
 
	//i2c_write(EEPROM_ADDR, 0x05, 0x03);
 
		
 
	// 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
 

	
 
	
 
	// Serial output //DEBUG
 
	char buff[128];						//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");	//DEBUG
 
			
 
    while(1)
 
    {	
 
		
 
		// Master communication
 
		masterComm_checkParser();	//Checks parser for data requests from master
 
		
 
		
0 comments (0 inline, 0 general)