Changeset - ebc4074e751f
[Not reviewed]
default
0 4 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2012-11-19 17:22:18
kripperger@CL-SEC241-09.cedarville.edu
Timer setup
4 files changed with 34 insertions and 11 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/spi.h
Show inline comments
 
@@ -4,25 +4,25 @@
 
 *
 
 *
 
 *
 
 */
 

	
 

	
 
#ifndef SPI_H_
 
#define SPI_H_
 

	
 
#include <avr/io.h>
 

	
 

	
 
#define SPI_SS_PIN PORTB4		//DEBUG //THIS IS WRONG FOR NOW...
 
#define SPI_SS_PIN PORTA1		//DEBUG 
 
#define SPI_SCK_PIN PORTB7
 
#define SPI_MOSI_PIN PORTB5
 
#define SPI_MISO_PIN PORTB6
 

	
 

	
 
// SPI clock modes
 
#define SPI_MODE_0 0x00 /* Sample (Rising) Setup (Falling) CPOL=0, CPHA=0 */
 
#define SPI_MODE_1 0x01 /* Setup (Rising) Sample (Falling) CPOL=0, CPHA=1 */
 
#define SPI_MODE_2 0x02 /* Sample (Falling) Setup (Rising) CPOL=1, CPHA=0 */
 
#define SPI_MODE_3 0x03 /* Setup (Falling) Sample (Rising) CPOL=1, CPHA=1 */
 

	
 
// data direction
slave/slave/modules.c
Show inline comments
 
/*
 
 * modules.c
 
 *
 
 * Created: 11/9/2012 11:44:22 AM
 
 *  Author: kripperger
 
 */ 
 
 
 #include <inttypes.h>
 
 #include <avr/io.h>
 
 #include "config.h"
 
 #include <util/delay.h>
 
 #include "modules.h"
 
 
 
 
 
 
 
 void modules_setup(uint8_t id)
 
 {
 
 
	switch(id)
 
	{
 
		case 0:
 
			modules_generic_setup();
 
			break;
 
@@ -71,24 +73,30 @@
 
 void modules_generic_setup()
 
 {
 
	  
 
 }
 
  
 
 void modules_sensors_setup()
 
 {
 
	  
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	ASSR = 0x20;    //enable timer2 async mode with an external crystal
 
	_delay_ms(250); //let external 32KHz crystal stabilize
 
	TCCR2B = 0x05;  //set the prescaler to 128: 32.768kHz / 128 = 1Hz overflow
 
	TIFR2 = 0x1;    //reset timer2 overflow interrupt flag
 
	TIMSK2 = 0x01;  //enable interrupt on overflow
 
 
	  
 
 }
 
  
 
 void modules_cameras_setup()
 
 {
 
	  	  
 
 }
 
  
 
 
 
 
 void modules_generic()
slave/slave/slave.c
Show inline comments
 
@@ -6,80 +6,90 @@
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#include "config.h"
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#include <util/delay.h>
 
#include <compat/twi.h>
 
 
#include "modules.h"
 
//#include "lib/serial.h"		//Not made yet
 
#include "lib/led.h"
 
#include "lib/inputOutput.h"
 
#include "lib/i2c.h"
 
#include "lib/spi.h"
 
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	
 
	DDRA=0xFF; //PORTA is output //DEBUG
 
	
 
	
 
	DDRA = 0xFF;		//PORTA is output //DEBUG
 
 
 
 
 
 
}
 
 
ISR(TIMER2_OVF_vect)    //Timer 2 overflow interrupt handler
 
{
 
	// This executes every second.  Update real-time clocks
 
	// Used only in Geiger module
 
 
	
 
	TIFR2 = 0x1;    // Reset timer2 overflow interrupt flag 
 
}
 
 
 
int main(void)
 
{
 
	// Initialize
 
	micro_setup();			// Generic microcontroller config options
 
	led_configure();		//
 
	i2c_init();				// Setup I2C
 
	//serial_setup();		// Config serial ports
 
	
 
	uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch
 
	modules_setup(moduleID);
 
 
	
 
	
 
	uint8_t temp;	//DEBUG
 
	
 
	
 
	
 
	PORTA=0;//DEBUG
 
	temp=0;//DEBUG
 
	
 
    while(1)
 
    {
 
 
 
		modules_run(moduleID);
 
 
 
 
 
 
 
 
 
 
        //serial_SendCommand('0','A',0,0);	//DEBUG: EXAMPLE
 
        
 
        //i2c_write(RTC_ADDR, 0x05, 0x3A);	//DEBUG: EXAMPLE
 
 
        _delay_ms(10);
 
        temp = i2c_read(RTC_ADDR, 0x02);		//DEBUG: EXAMPLE: seconds
 
        //_delay_ms(10);
 
        //temp = i2c_read(RTC_ADDR, 0x02);		//DEBUG: EXAMPLE: seconds
 
        
 
        PORTA = temp;		//DEBUG
 
      //  PORTA = temp;		//DEBUG
 
 
 
 
    }
 
	
 
	return 0;
 
}
 
\ No newline at end of file
slave/slave/slave.cproj
Show inline comments
 
@@ -142,14 +142,19 @@
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="modules.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="slave.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
  </ItemGroup>
 
  <ItemGroup>
 
    <Folder Include="lib" />
 
  </ItemGroup>
 
  <ItemGroup>
 
    <None Include="lib\SPIreadme.txt">
 
      <SubType>compile</SubType>
 
    </None>
 
  </ItemGroup>
 
  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
 
</Project>
 
\ No newline at end of file
0 comments (0 inline, 0 general)