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
 
@@ -7,11 +7,25 @@
 
 
 #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
 
@@ -11,10 +11,10 @@
 
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
 
@@ -20,35 +20,35 @@ void setup_spi()
 
	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
 
@@ -85,7 +85,7 @@
 
 void modules_geiger_setup()
 
 {
 
	// Pin setup
 
	DDRA &= ~(1 << DDRA0);	// PA0 is an input
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	
 
	
 
	 
slave/slave/slave.c
Show inline comments
 
@@ -33,7 +33,18 @@ 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//
 
	
 
}
 
 
@@ -46,12 +57,13 @@ int main(void)
 
	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////////////////////////////////////////////////////////////////
 
	
 
@@ -62,10 +74,10 @@ int main(void)
 
    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);
 
@@ -76,7 +88,19 @@ int main(void)
 
        _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
slave/slave/slave.cproj
Show inline comments
 
@@ -5,7 +5,7 @@
 
    <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>
 
@@ -48,7 +48,7 @@
 
      </OverrideVtorValue>
 
      <Channel>
 
        <host>127.0.0.1</host>
 
        <port>55286</port>
 
        <port>52709</port>
 
        <ssl>False</ssl>
 
      </Channel>
 
      <ToolOptions>
 
@@ -56,7 +56,7 @@
 
        <InterfaceProperties>
 
          <JtagDbgClock>249000</JtagDbgClock>
 
          <JtagProgClock>1000000</JtagProgClock>
 
          <IspClock>2010000</IspClock>
 
          <IspClock>250000</IspClock>
 
          <JtagInChain>false</JtagInChain>
 
          <JtagEnableExtResetOnStartSession>false</JtagEnableExtResetOnStartSession>
 
          <JtagDevicesBefore>0</JtagDevicesBefore>
0 comments (0 inline, 0 general)