Changeset - bb9115c5f82c
[Not reviewed]
Merge default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-09 22:12:06
ethanzonca@CL-ENS241-08.cedarville.edu
Merge
6 files changed with 69 insertions and 31 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -4,14 +4,28 @@
 
 * Created: 11/7/2012 7:17:52 PM
 
 *  Author: kripperger
 
 */ 
 
 
 #include <avr/io.h>
 
 
 
 uint8_t io_getModuleId() {
 
 uint8_t io_getModuleId()
 
 {
 
	 
 
	// Get ID from rotary dip and return it. 
 
	uint8_t id;
 
	id = 0; //DEBUG
 
	id = 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
 
	
 
	//while (id == 0)	// Keep reading until valid ID is read
 
	//{	
 
	id = ((PINC & 0b00111100) >> 2);	// Read Dip Encoder
 
	id = ~id;							//Invert Dip reading
 
	id = (id & 0b1111);					//Mask bits
 
	//}
 
 
	return id;
 
 }
 
\ No newline at end of file
slave/slave/lib/led.c
Show inline comments
 
@@ -8,16 +8,16 @@
 
#include <avr/io.h>
 
#include "led.h"
 
 
void led_configure()
 
{
 
	// Configure ports/pins for LEDs
 
	DDRB |= (1 << DDRB0);		// Set PB0 to Output
 
	DDRB |= (1 << DDRB1);		// Set PB1 to Output
 
	DDRB |= (1 << DDRB2);		// Set PB2 to Output
 
	DDRB |= (1 << DDRB3);		// Set PB3 to Output	
 
	DDRB |= (1 << DDB0);		// Set PB0 to Output
 
	DDRB |= (1 << DDB1);		// Set PB1 to Output
 
	DDRB |= (1 << DDB2);		// Set PB2 to Output
 
	DDRB |= (1 << DDB3);		// Set PB3 to Output	
 
	
 
	// Setup PWM
 
		//TODO
 
	
 
}
 
slave/slave/lib/spi.c
Show inline comments
 
@@ -17,38 +17,38 @@ void setup_spi()
 
	DDRB |= (1<<SPI_MOSI_PIN);	// output
 
	DDRB &= ~(1<<SPI_MISO_PIN); // input
 
	DDRB |= (1<<SPI_SCK_PIN);	// output
 
	DDRA |= (1<<SPI_SS_PIN);	// output
 
		
 
	// initialize SPI with lowest frequency; max. 400kHz during identification mode of card
 
	SPCR0 = (0 << SPIE0) | // SPI Interrupt Enable
 
	(1 << SPE0)  | // SPI Enable
 
	(0 << DORD0) | // Data Order: MSB first
 
	(1 << MSTR0) | // Master mode
 
	(0 << CPOL0) | // Clock Polarity: SCK low when idle
 
	(0 << CPHA0) | // Clock Phase: sample on rising SCK edge
 
	(1 << SPR10);   // Clock Frequency: f_OSC / 128
 
	//(1 << SPR00); // commentnig this out means /64, which gives over 100khz as required
 
	SPSR0 &= ~(1 << SPI2X0); // No doubled clock frequency
 
	SPCR = (0 << SPIE) | // SPI Interrupt Enable
 
	(1 << SPE)  | // SPI Enable
 
	(0 << DORD) | // Data Order: MSB first
 
	(1 << MSTR) | // Master mode
 
	(0 << CPOL) | // Clock Polarity: SCK low when idle
 
	(0 << CPHA) | // Clock Phase: sample on rising SCK edge
 
	(1 << SPR1);   // Clock Frequency: f_OSC / 128
 
	//(1 << SPR0); // commentnig this out means /64, which gives over 100khz as required
 
	SPSR &= ~(1 << SPI2X); // No doubled clock frequency
 

	
 

	
 
}
 

	
 
void disable_spi()
 
{
 
  SPCR0 = 0;
 
  SPCR = 0;
 
}
 

	
 
uint8_t send_spi(uint8_t out)
 
{
 
  SPDR0 = out;
 
  while (!(SPSR0 & (1<<SPIF0)));
 
  return SPDR0;
 
  SPDR = out;
 
  while (!(SPSR & (1<<SPIF)));
 
  return SPDR;
 
}
 

	
 
// Used in slave mode
 
uint8_t received_from_spi(uint8_t data)
 
{
 
  SPDR0 = data;
 
  return SPDR0;
 
  SPDR = data;
 
  return SPDR;
 
}
 

	
slave/slave/modules.c
Show inline comments
 
@@ -82,13 +82,13 @@
 
	 setup_spi();
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	// Pin setup
 
	DDRA &= ~(1 << DDRA0);	// PA0 is an input
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	
 
	
 
	 
 
	// Setup for interrupt input on PA0 (PCINT0)
 
	PCMSK0 |= (1 << PCINT0);	// Enable interrupt for PA0
 
	PCICR |= (1 << PCIE0);		// Enable ioc section PCIF0
slave/slave/slave.c
Show inline comments
 
@@ -30,56 +30,80 @@
 
 
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	sei();	// Enable interrupts
 
	DDRB |= (1 << DDRB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
 
	
 
	DDRB |= (1 << DDB0);		// Set PB0 to Output for LED0
 
	DDRB |= (1 << DDB1);		// Set PB1 to Output for LED1
 
	DDRB |= (1 << DDB2);		// Set PB2 to Output for LED2
 
	DDRB |= (1 << DDB3);		// Set PB3 to Output for LED3
 
	
 
	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//
 
	
 
}
 
 
 
int main(void)
 
{
 
	// Initialize
 
	micro_setup();			// Generic microcontroller config options
 
	led_configure();		// Configure ports and registers for LED operation
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch
 
	moduleID=1;	//DEBUG///////////////////////////////////////////////////////////////////////////////////////////
 
	modules_setup(moduleID);	// Run setup functions for specific module
 
	uint8_t moduleID = io_getModuleId();	// Slave Module ID from rotary dip switch
 
	//modules_setup(moduleID);				// Run setup functions for specific module
 
 
	
 
	
 
 
	
 
	//PORTA &= ~(1 << PA1);	//DEBUG////////////////OFF///////////////////////////////////////////////////////////////
 
	//PORTA |= (1 << PA1);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
	
 
	
 
	//char buff[32];	//DEBUG///////////////////////////////////////////////////////////////////////////////////////
 
	//serial0_sendString("Starting\r\n");
 
	
 
    while(1)
 
    {
 
				
 
		modules_run(moduleID);	// Runs specific module functions (like data reading)
 
		//modules_run(moduleID);	// Runs specific module functions (like data reading)
 
								// Use program timer to run every so often. Time interval defined in config.h
 
 
 
//Note to future kyle: Investigate why things lock up in when ID=1 when no node is attached and fix it so that it never frezes.
 
 
 
		//sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		//serial0_sendString(buff);
 
 
        //i2c_write(RTC_ADDR, 0x05, 0x3A);	//DEBUG: EXAMPLE//////////////////////////////////////////////////////
 
		
 
        _delay_ms(10);	//DEBUG
 
		
 
		
 
		//PORTB |= (1 << PB0);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		//PORTB |= (1 << PB1);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		//PORTB |= (1 << PB2);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		//PORTB |= (1 << PB3);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		
 
		//PORTB |= (1 << PB4);	//DEBUG///////////////ON//////HEATER/////////////////////////////////////////////////////	
 
		
 
		
 
		moduleID = io_getModuleId();	//Debug
 
 
		PORTB &= ~(0b1111);				// Clears the bottom 4 bits of PortB	
 
		PORTB |= (moduleID & 0b1111);	// Masks Module ID and assigns it to PortB
 
	
 
		
 
		/********Examples of data reading and getting******************
 
		x = geiger_getCpm();			//Data get
 
		x = sensors_getSpiTemp();		//Data get
 
		x = sensors_getBoardTemp();		//Data get
 
		
slave/slave/slave.cproj
Show inline comments
 
@@ -2,13 +2,13 @@
 
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  <PropertyGroup>
 
    <SchemaVersion>2.0</SchemaVersion>
 
    <ProjectVersion>6.0</ProjectVersion>
 
    <ToolchainName>com.Atmel.AVRGCC8</ToolchainName>
 
    <ProjectGuid>{40d97b6e-7ff4-48e7-9a9e-5e50ba18526b}</ProjectGuid>
 
    <avrdevice>ATmega324P</avrdevice>
 
    <avrdevice>ATmega644PA</avrdevice>
 
    <avrdeviceseries>none</avrdeviceseries>
 
    <OutputType>Executable</OutputType>
 
    <Language>C</Language>
 
    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
 
    <OutputFileExtension>.elf</OutputFileExtension>
 
    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
 
@@ -45,21 +45,21 @@
 
      <KeepTimersRunning>true</KeepTimersRunning>
 
      <OverrideVtor>false</OverrideVtor>
 
      <OverrideVtorValue>
 
      </OverrideVtorValue>
 
      <Channel>
 
        <host>127.0.0.1</host>
 
        <port>55286</port>
 
        <port>52709</port>
 
        <ssl>False</ssl>
 
      </Channel>
 
      <ToolOptions>
 
        <InterfaceName>ISP</InterfaceName>
 
        <InterfaceProperties>
 
          <JtagDbgClock>249000</JtagDbgClock>
 
          <JtagProgClock>1000000</JtagProgClock>
 
          <IspClock>2010000</IspClock>
 
          <IspClock>250000</IspClock>
 
          <JtagInChain>false</JtagInChain>
 
          <JtagEnableExtResetOnStartSession>false</JtagEnableExtResetOnStartSession>
 
          <JtagDevicesBefore>0</JtagDevicesBefore>
 
          <JtagDevicesAfter>0</JtagDevicesAfter>
 
          <JtagInstrBitsBefore>0</JtagInstrBitsBefore>
 
          <JtagInstrBitsAfter>0</JtagInstrBitsAfter>
0 comments (0 inline, 0 general)