Index: firmware/FSC/src/FSC.c
===================================================================
--- firmware/FSC/src/FSC.c	(revision 10108)
+++ firmware/FSC/src/FSC.c	(revision 10109)
@@ -2,7 +2,7 @@
 #include "typedefs.h"
 #include "application.h"
-#include "spare_outs.h"
 #include "spi_master.h"
-#include "ad7719_adc.h"    
+#include "ad7719_adc.h"
+#include "atmega_adc.h"    
 #include "usart.h"
 #include "macros.h"
@@ -13,52 +13,227 @@
 #include <stdlib.h>
 
-#include "tests.h"
+
 //-----------------------------------------------------------------------------
-
+// definition of some functions:
+// these function are implemented below the main()
+// here in FSC.c
+//
+// sooner or later, they will be moved into more apropriate files.
+U08	increase_adc (U08 channel);
+U08	increase_ad7719 (U08 channel);
+void Set_V_Muxer (U08 channel);
+void Set_T_Muxer(U08 channel);
+void talk(void);// never used up to now.
+void ad7719_output(U08 channel, U32 data);
+void adc_output(U08 channel, U08 data);
+void adc_output_all();
+void parse(); //doesn't do anything at the moment
+void check_if_measured_all() ;
+// end of function definition:
+//-----------------------------------------------------------------------------
+
+// MAIN WORKFLOW GLOBAL VARIABLES
+	bool verbose;
+	bool heartbeat_enable;
+
+// USART global variables
+	U08 usart_rx_buffer[USART_RX_BUFFER_SIZE];
+	U08 usart_tx_buffer[USART_TX_BUFFER_SIZE];
+	U08 usart_rx_buffer_index = 0;
+	U08 usart_tx_buffer_index = 0;
+  	U08 usart_last_char; 					// last received char
+
+// USART FLAGS
+	bool usart_tx_buffer_overflow = false;	// true if usart_tx_buffer was full.
+	bool usart_rx_ready = false;			// EOL was received, parser needs to be called
+	
+// TIMER global variable
+	volatile U32 local_ms = 0;
+
+// AD7719 global variables
+	#define TEMP_CHANNELS 64
+	#define CHANNEL_BITMAP 8
+	#define AD7719_READINGS_UNTIL_SETTLED 1 // bei3:480ms
+	U32 ad7719_values[TEMP_CHANNELS];
+	U08 ad7719_enables[CHANNEL_BITMAP];
+	U08 ad7719_channels_ready[CHANNEL_BITMAP];
+	U08 ad7719_readings_since_last_muxing = 0;
+	U08 ad7719_current_channel = 0;
+	U32 ad7719_current_reading = 0;
+	bool ad7719_measured_all = false;
+	
+// ATMEGA ADC global variables
+	#define V_CHANNELS 40
+	#define I_CHANNELS 40
+	#define H_CHANNELS 4
+	#define V_BITMAP 5
+	#define I_BITMAP 5
+	#define H_BITMAP 1
+	#define ADC_READINGS_UNTIL_SETTLED 1
+	U32 adc_values[V_CHANNELS + I_CHANNELS + H_CHANNELS]; // stores measured voltage in steps of 16mV
+	U08 adc_enables[V_BITMAP + I_BITMAP + H_BITMAP];
+	U08 adc_channels_ready[V_BITMAP + I_BITMAP + H_BITMAP];
+	U08 adc_readings_since_last_muxing = 0;
+	U08 adc_current_channel = 0;
+	U08 adc_current_reading = 0;
+	bool adc_measured_all = false;
+
+//-----------------------------------------------------------------------------
+//   M A I N    ---   M A I N    ---   M A I N    ---   M A I N    ---  M A I N    
+//-----------------------------------------------------------------------------
 int main(void)
 {
-// U08 IDN_STR[] = "16ch Pt1000 logger; firmware version of 07.11.10. DN"; // Identity string
-
-	spare_outs_init(); //set spare out pin I/O modes
-    app_init();		  // Setup software modules
-    usart_init();		// Initialize serial interface   
+	app_init();		  // Setup: Watchdog and I/Os
+	usart_init();		// Initialize serial interface   
 	spi_init(); 		// Initialize SPI interface as master
-	adc_init(); 		// Initialize AD7719 ADC as SPI slave 
-	//  usart_write_crlf();
-	//  usart_writeln_flash_str(IDN_STR); // Write string to USART interface
-	//  usart_write_crlf();
+	ad7719_init(); 		// Initialize AD7719 ADC as SPI slave 
+	atmega_adc_init();
+
+// TIMER2 is used as local clock:
+// configure timer 2
+	TCCR2 = (1<<WGM21); // CTC Modus
+	TCCR2 |= (1<<CS21) | (1<<CS20); // Prescaler 64 --> counts up every 8us
+	OCR2 = 125-1; 					// --> output compare interrupt occurs every 125 x 8us = 1ms
+	// Compare Interrupt erlauben
+	TIMSK |= (1<<OCIE2);
 
   //  Enable interrupts
   sei();              
- 
-
-	// temperature muxer pins init:
-	// SA - pins
-	DDRA |= 0x3F; // set all SA-pins as outputs
-	
-
-	// voltage, current, humidity - muxer pins:
-	// SB - pins
-	DDRC |= 0x7F; // set all SB - pins as outputs
-	
-	// SB - muxer test
-//	DDRA |= 1<<PA6 ; // set D0-0 lina as output. for tests only !!!
-//	PORTA |= 1<<PA6; // set D0-0 line high. for tests only !!!
-DDRA &= ~(1<<PA6);
-
-//ADC einschalten
-  ADMUX = 0x26;  //0010.0110     // interne Referenzspannung nutzen
-  ADCSRA = (1<<ADPS1) | (1<<ADPS0);     // Frequenzvorteiler
-  ADCSRA |= (1<<ADEN);                  // ADC aktivieren
-  ADCSRA |= (1<<ADSC);
-
-
-
-// Main loop
-//float temperature;
+
+for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) {
+	ad7719_enables[i]=0xFF;
+	ad7719_channels_ready[i]=0;
+	}
+for ( U08 i=0; i<V_BITMAP + I_BITMAP + H_BITMAP; ++i ) {
+	adc_enables[i]=0xFF;
+	adc_channels_ready[i]=0;
+}
+	static U08 welcome[]="\n\nwelcome to FACT FSC commandline interface v0.1\nready?";
+	usart_write_str(welcome);
+
+
+//MAIN LOOP
+while (1)
+{
+	if (heartbeat_enable) PORTB ^= (1<<PB3); // toggle Out2_spare --> heartbeat
+//----------------------------------------------------------------------------
+	//IF we need to send away one byte, and ready to send
+
+	if ( (usart_tx_buffer_index > 0) && (UCSRA & (1<<UDRE)) ) { 
+		UDR = usart_tx_buffer[0];
+		// THis is shit
+		for (U08 i=0 ; i < USART_TX_BUFFER_SIZE; ++i) {
+			usart_tx_buffer[i] = usart_tx_buffer[i+1];
+		}
+		usart_tx_buffer_index--;
+	}
+//----------------------------------------------------------------------------
+
+	//IF we just received one byte, and there is enough space in the RX_buffer
+	if ( (UCSRA & (1<<RXC)) && (usart_rx_buffer_index < USART_RX_BUFFER_SIZE) ){
+		usart_last_char = UDR;
+		if (usart_last_char == '\n'){ // if EOL was received
+			usart_rx_ready = true;
+		}else {
+		usart_rx_buffer[usart_rx_buffer_index] = usart_last_char;
+		usart_rx_buffer_index++;
+		}
+		// here is still something strange .... better send an enter automatically
+	} else if (UCSRA & (1<<RXC)) { // if there is no scace in the buffer; read anyway.
+		usart_last_char = UDR;
+		usart_rx_buffer_index =0;
+	}
+//----------------------------------------------------------------------------
+
+	//IF USART DOR bit is set, PC is sending data to fast!!!
+	if ( UCSRA & (1<<DOR) ){
+		// flush TX_buffer and write warning message in
+		// maybe even switch off every measurement. ?
+	}
+//----------------------------------------------------------------------------
+
+	//IF TX_BUFFER was overrun.	
+	if (usart_tx_buffer_overflow) {
+		// flash TX_buffer and write warning message in
+		// maybe even switch off every measurement. ?
+		//
+		// this should only happen, in verbose mode and with low baudrates.
+	}
+//----------------------------------------------------------------------------
+	
+	//IF one command was received. 
+	//	-It is not allowed to send more than one command between two '\n'
+	if (usart_rx_ready){ 
+		parse();
+		usart_rx_buffer_index = 0;
+		usart_rx_ready = false;
+	}
+//----------------------------------------------------------------------------
+
+	//IF ATmega internal ADC did finish a conversion --every 200us
+	if ( (ADCSRA & (1<<ADIF)) && !adc_measured_all) {
+		adc_current_reading = ADCH;
+		if (adc_readings_since_last_muxing == ADC_READINGS_UNTIL_SETTLED) {
+			adc_values[adc_current_channel] = adc_current_reading;
+			adc_readings_since_last_muxing=0;
+			// note that this channel is ready, now and 
+			adc_output(adc_current_channel, adc_current_reading);
+			// proceed to the next enabled channel.
+			adc_channels_ready[adc_current_channel/8] |= (1<<(adc_current_channel%8));
+			adc_current_channel = increase_adc (adc_current_channel);
+			Set_V_Muxer(adc_current_channel);
+		} else { // the ADC did not settle yet, we discard the reading
+			++adc_readings_since_last_muxing;
+			// current reading is not used for anything else
+		}
+	}
+//----------------------------------------------------------------------------
+
+	//IF AD7719 ADC just finished a conversion -- every 60ms
+	
+	if (AD7719_IS_READY()) {
+			ad7719_current_reading = read_adc(); // --takes at 4MHz SCLK speed about 6us
+		// AD7719 is only read out if settled. saves time.	
+		if (ad7719_readings_since_last_muxing == AD7719_READINGS_UNTIL_SETTLED) {
+			ad7719_values[ad7719_current_channel] = ad7719_current_reading;
+			ad7719_readings_since_last_muxing=0;
+			// now prepare the data to be send away via USART.
+			//ad7719_output(ad7719_current_channel, ad7719_current_reading);
+			// note that this channel is ready, now and 
+			// proceed to the next enabled channel.
+			ad7719_channels_ready[ad7719_current_channel/8] |= (1<<(ad7719_current_channel%8));
+			ad7719_current_channel = increase_ad7719 (ad7719_current_channel);
+			Set_T_Muxer(ad7719_current_channel);
+		} else { // the AD7719 did not settle yet, we discard the reading
+			++ad7719_readings_since_last_muxing;
+
+			// current reading is not used for anything else
+		}
+	}
+//----------------------------------------------------------------------------
+	//IF one of the ADC measured all channels, we wanted to know.
+	check_if_measured_all();
+	
+	if (ad7719_measured_all && adc_measured_all)
+		adc_output_all();
+
+//----------------------------------------------------------------------------
+/*
+	if (verbose == true)
+		// talk() was just defined so the 
+		// code is not at this place ... look down.
+		talk();
+*/
+
+} // end of MAIN LOOP
+//-----------------------------------------------------------------------------
+//    E N D     E N D     E N D     E N D     E N D     E N D     E N D     
+//-----------------------------------------------------------------------------
+
+
+
 float resistance;
-BOOL heartbeat_enable = TRUE;
-
-U08 SA_mux_val = 0x16;
+
+U08 SA_mux_val = 0x00;
 U08 SB_mux_val = 0x00;
 
@@ -69,8 +244,5 @@
 while (TRUE)
 	 {
-	 	// this heartbeat shows how long one single run of this while loop takes
-		// measure with a scope.
-		if (heartbeat_enable) PORTB ^= (1<<PB3); // toggle Out2_spare --> heartbeat
-		adc_init(); 
+
 
   ++Res_or_Volt;
@@ -121,8 +293,8 @@
 
 
-		startconv();
-
-	
-		while (!ADC_IS_READY())
+		startconv(0);
+
+	
+		while (!AD7719_IS_READY())
 		{
 		// just wait until ADC is redy -- really bad code here!
@@ -141,7 +313,7 @@
 		//_delay_ms(200);
 
-		startconv();
-
-		while (!ADC_IS_READY())
+		startconv(0);
+
+		while (!AD7719_IS_READY())
 		{
 		// just wait until ADC is redy -- really bad code here!
@@ -255,5 +427,4 @@
 
 for (U08 counter = 0; counter < 1; ++counter) {
-	ADCSRA |= (1<<ADSC);
 	while (ADCSRA & (1<<ADSC) );    // wait until internal ADC is ready
 	float voltage;
@@ -362,3 +533,288 @@
 
 
-
+ISR (TIMER2_COMP_vect)
+{
+ ++local_ms;
+}
+
+
+U08	increase_adc (U08 channel){
+bool valid_ch_found = false;
+	while (!valid_ch_found){
+	
+		// just increase 'channel' or turnover to zero.
+		++channel;
+		if (channel == V_CHANNELS + I_CHANNELS + H_CHANNELS)
+			channel = 0;
+	
+		// check if this channel is enabled in the bitmap
+		if (adc_enables[channel/8] & (1<<channel%8))
+			valid_ch_found = true;
+	} // end of while loop
+	return channel;
+} // end if increase_adc;
+
+U08	increase_ad7719 (U08 channel){
+bool valid_ch_found = false;
+	while (!valid_ch_found){
+	
+		// just increase 'channel' or turnover to zero.
+		++channel;
+		if (channel == TEMP_CHANNELS)
+			channel = 0;
+	
+		// check if this channel is enabled in the bitmap
+		if (ad7719_enables[channel/8] & (1<<channel%8))
+			valid_ch_found = true;
+	} // end of while loop
+	return channel;
+} // end if increase_adc;
+
+
+// Sets voltage Muxer to current channel
+// this is a Muxing, and therefor the adc might need some time to settle.
+// Since there are:
+//	- 40 voltage monitor channels
+// 	- 40 current monitor channels
+// 	- 4 humidity monitor channels
+// the muxer is set as follows.
+// channel 00..39 --> looking at the voltage channels
+// channel 40..79 --> looking at the current channels
+// channel 80..83 --> looking at the humidities
+void Set_V_Muxer (U08 channel){
+U08 SB = 0;
+	// voltages
+	if (channel < 40) {
+		if (channel < 36)
+			SB = channel*2;
+		else
+			SB = (channel+1)*2;
+	}
+	// currents
+	else if (channel < 80) {
+		channel -= 40;
+		if (channel < 36)
+			SB = channel*2+1;
+		else
+			SB = (channel+1)*2+1;
+	}
+	// humidities
+	else if (channel < 84) {
+		channel -= 80;
+		switch (channel) {
+			case 0:
+				SB = 0x48; //0100.1000
+				break;
+			case 1:
+				SB = 0x49; //0100.1001
+				break;
+			case 2:
+				SB = 0x58; //0101.0010
+				break;
+			case 3:
+				SB = 0x58; //0101.0011
+				break;
+		} // end of switch-case
+	} // end of if (channel < some_number)
+
+	PORTC = (PORTC & 0x80) | (0x7F & SB); // Here the muxer is switched.
+}
+
+void Set_T_Muxer(U08 channel) {
+U08 SA = 0x00;
+
+	switch (channel/16) {
+		case 0:
+			SA |= 1<<4; // 0001.0000
+			break;
+		case 1:
+			break;		// 0000.0000
+		case 2:
+			SA |= (1<<4)|(1<<5); // 0011.0000
+			break;
+		case 3:
+			SA |= 1<<5;  // 0010.0000
+			break;
+	}
+	
+	SA =  SA | (channel%16);
+	
+	PORTA = (PORTA & 0xC0) | (0x3F & SA); // Here the muxer is switched.
+}
+
+void talk(void){
+
+/*
+// makes no sense to declare the 'new_measurement' vars here
+// but maybe the whole function will be deleted, anyway ...
+// I'm thinking about it.
+bool ad7719_new_measurement;
+bool atmega_adc_new_measurement;
+	if (verbose == true) { 
+		// somebody wants to read every new measured value, even if it is trash!
+			// do not actually send away data !
+			// just prepare the data to be send away.
+		if ( ad7719_new_measurement  == true ) {
+			add_str_to_output_stream("ad7719: reading:");
+			add_dec_to_output_stream(reading_since_last_muxer_switch,1);
+			add_str_to_output_stream(" temperature channel:");
+			add_dec_to_output_stream(current_temperature_channel,2);
+			add_str_to_output_stream(" = ");
+			add_float_to_output_stream(current_ad7719_value,4,3);
+			add_str_to_output_stream("\n");
+		}
+		if (atmega_adc_new_measurement == true) {
+			add_str_to_output_stream("atmega_adc: reading:");
+			add_dec_to_output_stream(reading_since_last_muxer_switch,1);
+			add_str_to_output_stream(" voltage channel:");
+			add_dec_to_output_stream(current_voltage_channel,2);
+			add_str_to_output_stream(" = ");
+			add_float_to_output_stream(current_atmega_adc_value,4,3);
+			add_str_to_output_stream("\n");
+		}
+	} // end of: if verbose
+*/
+} // end of talk()
+
+// this function generates some output.
+void ad7719_output(U08 channel, U32 data) {
+	usart_write_str((pU08)"R:"); //R for resistance
+	usart_write_char('A'+channel/8); // Letters A,B,C,D,E,F,G,H
+	usart_write_char(' '); 
+	usart_write_U08(channel%8+1,1); // Numbers 1...8
+	usart_write_char(':'); 
+	usart_write_U32_hex(data); //data
+	usart_write_char('\n');
+}
+
+void adc_output(U08 channel, U08 data) {
+
+	if (channel < 40) 
+		usart_write_str((pU08)"V:"); //V for Vendetta
+	else if (channel < 80)
+		usart_write_str((pU08)"I:"); //I for Irregular verbs
+	else if (channel < 84)
+		usart_write_str((pU08)"H:"); //H for Huurrray!!!
+
+	switch (channel/16) {
+		case 0:
+			usart_write_char('A'); //V for Vendetta
+		case 1:
+			usart_write_char('B'); //V for Vendetta
+		case 2:
+			usart_write_char('D'); //V for Vendetta
+		case 3:
+			usart_write_char('C'); //V for Vendetta
+		case 4:
+			usart_write_char('EF'); //V for Vendetta
+	}
+	usart_write_char(' '); 
+	usart_write_U08((channel/2)%8+1,1); // Numbers 1...8
+	usart_write_char(':'); 
+	usart_write_U16((U16)data*16,5); //data
+	usart_write_char('\n');
+
+
+}
+
+
+void adc_output_all() {
+	// output all values, which are enabled
+	for (U08 i=0 ; i<40; ++i){
+		if (i==0) usart_write_str((pU08)"voltages:(in units of 16mV)\n");
+		if (i==40) usart_write_str((pU08)"currents:\n");
+		if (i==80) usart_write_str((pU08)"humidities:\n");
+		if (adc_enables[i/8] & i%8){
+			usart_write_U08(adc_values[i],3);
+			usart_write_char('\t');
+		}
+		if (i%8==7) usart_write_char('\n');
+		if (i==83) usart_write_char('\n');
+	}
+}
+
+
+// this method parses the data, 
+// which came in via USART
+// later it might as well parse the data from ethernet.
+void parse() {
+U08 command = usart_rx_buffer[0];
+// look at first byte
+// I hope, I can manage to use one byte commands
+	usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0;
+	usart_write_str((pU08)"got:");
+	usart_write_str(usart_rx_buffer);
+	
+	
+
+	switch (command) {
+		case 'E': 			// AD7719 enable bitmaps may be set
+			for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) {
+				ad7719_enables[i]=usart_rx_buffer[i+1];
+				ad7719_channels_ready[i]=0;
+			}
+			break;
+		case 'e':			// ATmega internal ADC enable bitmaps may be set
+			for ( U08 i=0; i<V_BITMAP + I_BITMAP + H_BITMAP; ++i ) {
+				adc_enables[i]=usart_rx_buffer[i+1];
+				adc_channels_ready[i]=0;
+			}
+			break;
+		case 'h':
+			usart_write_str((pU08)"\nheartbeat ");
+			heartbeat_enable = true;
+			if (usart_rx_buffer[1] == '0'){
+				heartbeat_enable = false;
+				usart_write_str((pU08)"off\n");
+			} else {
+				usart_write_str((pU08)"on\n");
+			}
+			break;
+		case 'G': 			// GET the Temperature channels, which are enabled
+			for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) {
+				ad7719_channels_ready[i]=0;
+			}
+			break;
+		case 'g':			// GET the voltage/current/humidity channels, which are enabled
+			for ( U08 i=0; i<V_BITMAP + I_BITMAP + H_BITMAP; ++i ) {
+				adc_channels_ready[i]=0;
+			}
+			break;
+		case 's':
+			usart_write_char('\n');
+			for (U08 i=0; i< CHANNEL_BITMAP;++i) {
+				usart_write_U08_bin(ad7719_enables[i]);
+				usart_write_char('\t');
+			}
+			usart_write_char('\n');
+			for (U08 i=0; i< CHANNEL_BITMAP;++i){
+				usart_write_U08_bin(ad7719_channels_ready[i]);
+				usart_write_char('\t');
+			}
+			usart_write_char('\n');
+				usart_write_U32_hex(local_ms);
+			break;			
+	}
+	usart_write_str((pU08)"\nready?");
+	for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i)
+		usart_rx_buffer[i] = 0;
+}
+
+void check_if_measured_all() {
+	adc_measured_all = true;
+	for ( U08 i=0; i<V_BITMAP + I_BITMAP + H_BITMAP; ++i ) {
+		if ((adc_enables[i] ^ adc_channels_ready[i]) != 0x00) {
+			adc_measured_all = false;
+			break;
+		}
+	}
+	ad7719_measured_all = true;
+	for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) {
+		if ((ad7719_enables[i] ^ ad7719_channels_ready[i]) != 0x00) {
+			ad7719_measured_all = false;
+			break;
+		}
+	}
+
+
+}
Index: firmware/FSC/src/ad7719_adc.c
===================================================================
--- firmware/FSC/src/ad7719_adc.c	(revision 10108)
+++ firmware/FSC/src/ad7719_adc.c	(revision 10109)
@@ -6,31 +6,6 @@
 //-----------------------------------------------------------------------------
 
-void adc_init(void)
+void ad7719_init(void)
 {
-
-  SET_BIT(ADC_DDR,DDD4);		// ADC_RST is uP Output
-  CLR_BIT(ADC_PRT,ADC_RST);		// Reset ADC (active low) 	
-  SET_BIT(ADC_PRT,ADC_RST);		// Stop Reset ADC
-
-
-	//Init Configure and Initialize AD7719
-	//http://designtools.analog.com/dt/adc/codegen/ad7719.html 
-
-  U8  IOCON1 = 0xC3;	// power switches P1 and P2 switch to PWRGND. I-sources I1 and I2 are switched on.
-  U8  IOCON2 = 0x08;	// 0x08 makes no sense... P4 is set HIGH, but is no output.
-//  U8  FILTER = 0x45;	//0x45 global use 50Hz = -66dB and 60Hz = -117dB Rejectjon
-  U8  FILTER = 0x52;	//0x52 euro use 50Hz = -171dB and 60Hz = -58dB Rejectjon Updaterate = 4Hz
-
-  U8  AD1CON = 0x51;	
-	// ARN bit is set->AUS ADC range is: +-REFIN2
-	// ACHo and ACH2 are set --> not defined. ???
-	// AD1EN is not set. so aux ADC is not enabled anyway.
-
-  U8  AD0CON = 0x8E;
-  	// AD0EN is set. main ADC operates according to content of mode register
-	// U/#B is set. unipolar encoding. zero is 0x000000. both full scales will be 0xFFFFFF
-	// RN2..0 = 1 ,1 ,0 --> multiplication factor 8, maybe ??
-
-  U8  MODE   = 0x02;	// single conversion
 
 	// ADC communiaction works like this:
@@ -46,86 +21,137 @@
 	// A3-A0 denote the address of the next register.
 
-  const U8 WR_TO_IOCON = 0x07;
-  const U8 WR_TO_FILTER = 0x04;
-  const U8 WR_TO_AD1CON = 0x03;
-  const U8 WR_TO_AD0CON = 0x02;
-  const U8 WR_TO_MODE = 0x01;
-  const U8 RD_FROM_FILTER = 0x44;
+  
+  CLR_BIT(ADC_PRT,ADC_RST);		// Reset ADC (active low) 	
+  SET_BIT(ADC_PRT,ADC_RST);		// Stop Reset ADC
+
+
+  CLR_BIT(PORTD,SPI_AD_CS);  			// Set CS low
+  spi_transfer_byte(FILTER_RD); // Next Operation is write to IOCON
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);  			// Set CS low
+  spi_transfer_byte(0); // Next Operation is write to IOCON
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);  			// Set CS low
+  spi_transfer_byte(IOCON_WR); // Next Operation is write to IOCON
+  SET_BIT(PORTD,SPI_AD_CS);
+  
+  _delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);
+  spi_transfer_byte(IOCON_INIT_HIGH);  	// Write to IOCON1 
+  SET_BIT(PORTD,SPI_AD_CS);
+_delay_us(50);
+  CLR_BIT(PORTD,SPI_AD_CS);
+  spi_transfer_byte(IOCON_INIT_LOWBYTE);  	// Write to IOCON2 
+  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
+
+_delay_us(50);
 
   CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(RD_FROM_FILTER);     	// Next Operation is write to IOCON1 and IOCON2  Start SPI
-  spi_transfer_byte(0xFF);     	// Next Operation is write to IOCON1 and IOCON2  Start SPI
+  spi_transfer_byte(FILTER_WR);     	// Next Operation is write to FILTER  Start SPI
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+  CLR_BIT(PORTD,SPI_AD_CS);
+
+  spi_transfer_byte(FILTER_INIT);  	// Write to FILTER 
+  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
+_delay_us(50);
+  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
+  spi_transfer_byte(AD1CON_WR);     	// Next Operation is write to AD1CON  Start SPI
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);
+  spi_transfer_byte(AD1CON_INIT);  	// Write to AD1CON
   SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
 
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
+  spi_transfer_byte(AD0CON_WR);     	// Next Operation is write to AD0CON  Start SPI
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);
+  spi_transfer_byte(AD0CON_INIT);  	// Write to AD0CON
+  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
+  spi_transfer_byte(MODE_WR);     	// Next Operation is write to MODE Start SPI
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);
+  spi_transfer_byte(MODE_CONT);  	// Write to MODE
+  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);  			// Set CS low
+  spi_transfer_byte(FILTER_RD); // Next Operation is write to IOCON
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
+
+  CLR_BIT(PORTD,SPI_AD_CS);  			// Set CS low
+  spi_transfer_byte(0); // Next Operation is write to IOCON
+  SET_BIT(PORTD,SPI_AD_CS);
+
+_delay_us(50);
 
 
-
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(WR_TO_IOCON);     	// Next Operation is write to IOCON1 and IOCON2  Start SPI
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
-
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(IOCON1);  	// Write to IOCON1 
-  spi_transfer_byte(IOCON2);  	// Write to IOCON2 
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
-
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(WR_TO_FILTER);     	// Next Operation is write to FILTER  Start SPI
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
- 
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(FILTER);  	// Write to FILTER 
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
-
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(WR_TO_AD1CON);     	// Next Operation is write to AD1CON  Start SPI
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
- 
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(AD1CON);  	// Write to AD1CON
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
-
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(WR_TO_AD0CON);     	// Next Operation is write to AD0CON  Start SPI
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
- 
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(AD0CON);  	// Write to AD0CON
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
-
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(WR_TO_MODE);     	// Next Operation is write to MODE Start SPI
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
- 
-  CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-  spi_transfer_byte(MODE);  	// Write to MODE
-  SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
 } 
           
- void startconv(void)
-  {
-    U8 COM = 0x01;
-	U8 SERIAL = 0x02;
+void startconv(U08 continuous)
+{
 	CLR_BIT(PORTD,SPI_AD_CS);       // Set CS low
-	spi_transfer_byte(COM);        // Next Operation is write to Mode Register
-	spi_transfer_byte(SERIAL);	 // Start new A/D conversion
+	spi_transfer_byte(MODE_WR);        // Next Operation is write to Mode Register
+  SET_BIT(PORTD,SPI_AD_CS);
+  CLR_BIT(PORTD,SPI_AD_CS);
+	if (continuous)	spi_transfer_byte(MODE_SINGLE);	 // Start new A/D conversion
+	else spi_transfer_byte(MODE_CONT);	 // Start continous conversion mode
 	SET_BIT(PORTD,SPI_AD_CS);  
-	COM = 0x45;
+}
+
+void stopconv(void)
+{
 	CLR_BIT(PORTD,SPI_AD_CS);       // Set CS low
-	spi_transfer_byte(COM);        // Next Operation is read from Main ADC Data Register
-	SET_BIT(PORTD,SPI_AD_CS);        // Set CS high
-  }
+	spi_transfer_byte(MODE_WR);        // Next Operation is write to Mode Register
+    SET_BIT(PORTD,SPI_AD_CS);
+    CLR_BIT(PORTD,SPI_AD_CS);
+	spi_transfer_byte(MODE_IDLE);
+	SET_BIT(PORTD,SPI_AD_CS);  
+}
 
- U32 read_adc(void)
- { CLR_BIT(PORTD,SPI_AD_CS);  	// Set CS low
-   U32 value=0; 					// actually a 24bit value is returned
-   value |= spi_transfer_byte(0) ;
-   value =value<<8;
-   value |= spi_transfer_byte(0) ;
-   value =value<<8;
-   value |= spi_transfer_byte(0) ;
-   SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
-   return value;                                                                                                 
- }   
+
+U32 read_adc(void)
+{ 
+	CLR_BIT(PORTD,SPI_AD_CS);       // Set CS low
+	spi_transfer_byte(AD0DAT_RD);   // Next Operation is read from Main ADC Data Register
+    SET_BIT(PORTD,SPI_AD_CS);
+	_delay_us(50);
+
+    CLR_BIT(PORTD,SPI_AD_CS);
+	U32 value=0; 					// actually a 24bit value is returned
+	value |= spi_transfer_byte(0) ;
+	value =value<<8;
+	value |= spi_transfer_byte(0) ;
+	value =value<<8;
+	value |= spi_transfer_byte(0) ;
+	SET_BIT(PORTD,SPI_AD_CS);	// Set CS high
+	return value;                                                                                                 
+}   
   
   
Index: firmware/FSC/src/ad7719_adc.h
===================================================================
--- firmware/FSC/src/ad7719_adc.h	(revision 10108)
+++ firmware/FSC/src/ad7719_adc.h	(revision 10109)
@@ -10,5 +10,5 @@
 #define ADC_RDY PD6
 #define ADC_RST PD7
-#define ADC_IS_READY() !(PIND & (1<<PD6)) // TRUE if PD6=0 AD_RDY is inverted logic.
+#define AD7719_IS_READY() (!(PIND & (1<<PD6))) // TRUE if PD6=0 AD_RDY is inverted logic.
 
 // Port Definitions
@@ -17,6 +17,78 @@
 #define ADC_PIN PIND
 
-void adc_init(void);
-void startconv(void);
+
+// ON CHIP REGISTER ADDRESSES
+#define STATUS_RD 0x40
+
+#define MODE_WR 0x01
+#define MODE_RD 0x41
+
+#define AD0CON_WR 0x02
+#define AD0CON_RD 0x42
+
+#define AD1CON_WR 0x03
+#define AD1CON_RD 0x43
+
+#define FILTER_WR 0x04
+#define FILTER_RD 0x44
+
+#define AD0DAT_RD 0x45
+#define AD1DAT_RD 0x46
+
+#define IOCON_WR 0x07
+#define IOCON_RD 0x47
+
+#define AD0OFS_WR 0x08
+#define AD0OFS_RD 0x48
+
+#define AD1OFS_WR 0x09
+#define AD1OFS_RD 0x49
+
+#define AD0GAIN_WR 0x0A
+#define AD0GAIN_RD 0x4A
+
+#define AD1GAIN_WR 0x0B
+#define AD1GAIN_RD 0x4B
+
+#define ID_RD 0x4F
+
+// REGISTER INIT VALUES
+
+	//Init Configure and Initialize AD7719
+	//http://designtools.analog.com/dt/adc/codegen/ad7719.html 
+
+#define IOCON_INIT_HIGH 0x03	//0000.0011 // I-sources I1 and I2 are switched on, thats all
+#define IOCON_INIT_LOWBYTE 0x00
+
+#define FILTER_INIT 0x52	//0x52 euro use 50Hz = -171dB and 60Hz = -58dB Rejectjon Updaterate = 4Hz
+											// 0x52=82 decimal. f_ADC=16.6Hz; t_ADC=60ms; t_settle = 120ms
+
+#define AD1CON_INIT 0x31	//0011.0001  	
+	// AD1EN is set --> AUX ADc is used for Temp measurement.
+	// ACH = 011 --> Tempsensor
+	// U/#B = 0 --> bipolar, but i'm not entirely sure if this is correct.
+	// ARN = 1 --> input range is REFIN2 , but when tempsensor is chosen, internal ref is used ... 
+
+#define AD0CON_INIT 0x8E // 1000.1110
+	// AD0EN is set
+	// WL is cleared --> 24bit
+	// CH = 00 --> AIN1 , AIN2 used 
+	// U/#B = 1 --> unipolar
+	// RN=110 --> input range = +-1.28V --> whatever this means in ratiometric measurements.
+
+
+#define MODE_IDLE 0x01
+#define MODE_SINGLE 0x02
+#define MODE_CONT 0x03
+#define MODE_INTERNAL_ZERO_CAL 0x04		// not tested
+#define MODE_INTERNAL_FULL_CAL 0x05		// not tested
+
+// since the ADC is chopped, one should wait 3 conversions
+// after the muxer was switched, until the reading is okay.
+#define READINGS_UNTIL_AD7719_SETTLED 3
+
+void ad7719_init(void);
+void startconv(U08 continuous);
+void stopconv(void);
 U32 read_adc(void);
 //-----------------------------------------------------------------------------
Index: firmware/FSC/src/application.c
===================================================================
--- firmware/FSC/src/application.c	(revision 10108)
+++ firmware/FSC/src/application.c	(revision 10109)
@@ -4,5 +4,4 @@
  #include <avr/wdt.h> 
 
-// 
 
 //-----------------------------------------------------------------------------
@@ -16,125 +15,64 @@
   MCUSR = 0x00; // Clear reset source for next reset cycle
 
+
+	// Dangerous here: I still do not know much about the watchdog.
+	// This code is still from Udo Juerss. 
+
   // The watchdog timer is disabled by default ("startup.asm")
-#ifdef USE_WATCHDOG
- WDTCSR = WDTOE | (1 << WDE); // Enable watchdog reset (~16ms)
-#endif
-  
-#ifndef F_CPU
-#define F_CPU 8000000UL	//cpu frequency
-#endif
+	#ifdef USE_WATCHDOG
+	 WDTCSR = WDTOE | (1 << WDE); // Enable watchdog reset (~16ms)
+	#endif
 
-//#ifdef (F_CPU == 16000000UL)
-/*#else
-  #warning *** Compiling for _MCU_CLOCK_FREQUENCY_ Hz
-  #error *** Invalid clock selected! ***
-#endif*/
- // Tell the user the operating frequency
-//#warning *** Compiling for DF_CPU Hz
-/*
-  // Set selected CPU clock
-#if (_MCU_CLOCK_FREQUENCY_ == 16000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 0; // Set clock prescaler to division by 1 (16MHz clock with 16MHz crystal)
-#elif (_MCU_CLOCK_FREQUENCY_ == 8000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 1; // Set clock prescaler to division by 2 (8MHz clock with 16MHz crystal)
-#elif (_MCU_CLOCK_FREQUENCY_ == 4000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 2; // Set clock prescaler to division by 4 (4MHz clock with 16MHz crystal)
-#elif (_MCU_CLOCK_FREQUENCY_ == 2000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 3; // Set clock prescaler to division by 8 (2MHz clock with 16MHz crystal)
-#elif (_MCU_CLOCK_FREQUENCY_ == 1000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 4; // Set clock prescaler to division by 16 (1MHz clock with 16MHz crystal)
-#else
-  #warning *** Compiling for _MCU_CLOCK_FREQUENCY_ Hz
-  #error *** Invalid clock selected! ***
-#endif
+	// define PORTS
+	// USART
+	DDRD &= ~(1<<PD0);				// PD0 = RXD is input
+	DDRD |= 1<<PD1; 					// PD1 = TXD is output
+	
 
-  // Tell the user the operating frequency
-#warning *** Compiling for _MCU_CLOCK_FREQUENCY_ Hz
+	// SPARE OUT/-INPUTS
+	DDRB |= (1<<PB2) | (1<<PB3); 	// set Out1_spare & out2_spare as outputs
+	DDRA &= ~(1<<PA7);				// set In1_spare as input
+	DDRC &= ~(1<<PC7);				// set In2_spare as input
+	PORTA |= (1<<PA7); 				// swtich on pullup on In1_spare
+	PORTC |= (1<<PC7); 				// swtich on pullup on In2_spare
 
-*/ 
+	// ATmega internal ADC input 
+	DDRA &= ~(1<<PA6);
 
-/* (ATmega32 has no prescaler)
-  // Set selected CPU clock
-#if (F_CPU == 16000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 0; // Set clock prescaler to division by 1 (16MHz clock with 16MHz crystal)
-#elif (F_CPU == 8000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 1; // Set clock prescaler to division by 2 (8MHz clock with 16MHz crystal)
-#elif (F_CPU == 4000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 2; // Set clock prescaler to division by 4 (4MHz clock with 16MHz crystal)
-#elif (F_CPU == 2000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 3; // Set clock prescaler to division by 8 (2MHz clock with 16MHz crystal)
-#elif (F_CPU == 1000000)
-  CLKPR = CLKPCE; // Enable clock prescaler by writing 0x80 to CLKPR
-  CLKPR = 4; // Set clock prescaler to division by 16 (1MHz clock with 16MHz crystal)
-#else
-  #warning *** Compiling for F_CPU Hz
-  #error *** Invalid clock selected! ***
-#endif
+	// MUXER ADDRESS OUTs
+	DDRA |= 0x3F; // SA-pins -> output
+	DDRC |= 0x7F; // SB-pins -> output
+
+	// SPI
+	// set all CS's: output
+	DDRB |= (1 << SPI_E_CS);
+	DDRD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS);
+
+	// set all Chips selects HIGH
+	PORTB |= (1 << SPI_E_CS);
+	PORTD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS);
+
+	// set MOSI and SCK: output & // set MISO: input
+	SPI_DDR |= (1 << SPI_MOSI);
+	SPI_DDR |= (1 << SPI_SCLK);
+	SPI_DDR &= ~(1 << SPI_MISO);
+
+	// set MOSI, SCK: HIGH. MISO leave alone.
+	SPI_PRT |= (1 << SPI_MOSI);
+	SPI_PRT |= (1 << SPI_SCLK);
+	SPI_PRT |= (1 << SPI_MISO);
+
+	// ADC 
+	DDRD &= ~(1<<PD6);					// PD6 is AD_READY input
+	DDRD |= 1<<PD7;							// PD7 is AD_RESET output
+
+	// ACCELEROMETER
+	DDRD &= ~(1<<PD2);					// PD2 is ACC_READY input
+
+	//MAX6662   <--- not assembled anymore
+	// DDRB &= ~(1<<PB0); 			// PB0 is over temperature alert input
+	// DDRB &= ~(1<<PB1);				// PB1 is general temperature altert input
 
 
-
-  // Tell the user the operating frequency
-#warning *** Compiling for F_CPU Hz
-
- 
-  // Turn off unused modules for this application
-  PRR =
-  (
-#ifndef USE_TWI
-    TWEN // I2C module
-  #warning *** Module "TWI" not enabled!
-#endif
-
- (ATmega32 Can't disable TIMER modules)
-#ifndef USE_TIMER2
-    | PRTIM2 // Timer2
-  #warning *** Module "TIMER2" not enabled!
-#endif
-#ifndef USE_TIMER1
-    | PRTIM1 // Timer1
-  #warning *** Module "TIMER1" not enabled!
-#endif
-#ifndef USE_TIMER0
-    | PRTIM0 // Timer0
-  #warning *** Module "TIMER0" not enabled!
-#endif
-
-#ifndef USE_USART0
-    | PRUSART0 // USART0
-  #warning *** Module "USART0" not enabled!
-#endif
-
-#ifndef USE_SPI
-    | SPE // SPI
-  #warning *** Module "SPI" not enabled!
-#endif
-
-#ifndef USE_ADC
-    | ADEN // ADC
-  #warning *** Module "ADC" not enabled!
-#endif
-  );
-
-#ifndef USE_ACO // Analog comparator
-  ACSR = ACME;
-  #warning *** Module "ACO" not enabled!
-#endif
-
-  PORTC |= PC6; // Enable pullup for PC6_RESET
-
-  // Initialize switches S1, S2 and S3
-  //S1_INIT(); // Set S1 pin to input
-  //S2_INIT(); // Set S2 pin to input
-  //S3_INIT(); // Set S3 pin to input
-*/
 }
 
Index: firmware/FSC/src/application.h
===================================================================
--- firmware/FSC/src/application.h	(revision 10108)
+++ firmware/FSC/src/application.h	(revision 10109)
@@ -6,34 +6,33 @@
 //-----------------------------------------------------------------------------
 
-//#define F_CPU (_MCU_CLOCK_FREQUENCY_)
-#define F_CPU_KHZ (F_CPU / 1000)
-#define F_CPU_MHZ (F_CPU_KHZ / 1000)
-//-----------------------------------------------------------------------------
-
-// Definitions of hardware modules used by application
-// Comment out all unused hardware modules
-
-//#define USE_TWI // I2C module used?
-//#define USE_TIMER2 // Timer2 used?
-//#define USE_TIMER1 // Timer1 used?
-//#define USE_TIMER0 // Timer0 used?
-//#define USE_SPI // SPI used?
-//#define USE_USART // USART0 used?
-//#define USE_ADC // ADC used?
-//#define USE_ACO // Analog Comparator used?
-//#define USE_WATCHDOG // Comment out to disable watchdog timer
-//-----------------------------------------------------------------------------
-
-// USART0 definitions
-#define USART_RX_BUFFER_SIZE 64 // Receive buffer size
+#define USART_RX_BUFFER_SIZE 32 // Receive buffer size
+#define USART_TX_BUFFER_SIZE 255 // Receive buffer size. MUST not be larger 255
 
 #define USART_BAUDRATE 9600 // USART baudrate original
-
 #define USART_USE_TX // Transmitter used?
 #define USART_USE_RX // Receiver used?
-#define USART_USE_RX_IRQ // RX interrupt used?
+//#define USART_USE_RX_IRQ // RX interrupt used?
 #define USART_USE_UPPERCASE // Convert received chars to uppercase?
 //-----------------------------------------------------------------------------
 
+// SPI DEFINITIONS
+// Port Definitions
+#define SPI_PRT PORTB
+#define SPI_DDR DDRB
+
+// Bit Definitions
+#define SPI_SCLK PB7
+#define SPI_MOSI PB5
+#define SPI_MISO PB6
+
+#define SPI_E_CS PB4 		
+#define SPI_AD_CS PD3 		
+#define SPI_M_CS PD4		
+#define SPI_A_CS PD5		
+
+
+
+
+//-----------------------------------------------------------------------------
 extern volatile U08 app_reset_source;
 //-----------------------------------------------------------------------------
Index: firmware/FSC/src/atmega_adc.c
===================================================================
--- firmware/FSC/src/atmega_adc.c	(revision 10109)
+++ firmware/FSC/src/atmega_adc.c	(revision 10109)
@@ -0,0 +1,22 @@
+#include "atmega_adc.h"
+#include "typedefs.h"
+
+void atmega_adc_init(void)
+{
+//ADC einschalten
+	ADCSRA |= (1<<ADPS2) | (1<<ADPS1);     // ADC_clk = 125kHz
+	ADCSRA &= ~(1<<ADPS0);
+		// normal conversion takes: 13 adc_clk cycles = 104us
+		// 1st conversion takes longer: 25 clk cycles = 200us
+	ADCSRA |= 1<<ADATE; // autotrigger enable
+	SFIOR &= ~(0xE0);		//ADTS=000 --> free running mode 
+	ADCSRA |= (1<<ADEN);                  // ADC aktivieren
+
+	ADMUX &= ~(1<<REFS0); 
+	ADMUX &= ~(1<<REFS1); 	//REFS = 00 --> use external reference voltage.
+	ADMUX |= 1<<ADLAR;		//ADLAR =1 	--> left adjust ac result in ADCH register --> 8bit resolution only.				
+	ADMUX |= (0x1F & 0x06); //MUX = 0x06 --> Pin ADC6 = PA6 is used as ADC input pin.
+	
+	ADCSRA |= (1<<ADSC); 	// start 1st conversion
+
+}
Index: firmware/FSC/src/atmega_adc.h
===================================================================
--- firmware/FSC/src/atmega_adc.h	(revision 10109)
+++ firmware/FSC/src/atmega_adc.h	(revision 10109)
@@ -0,0 +1,6 @@
+#ifndef __ATMEGA_ADC_H
+#define __ATMEGA_ADC_H
+
+
+void atmega_adc_init(void);
+#endif
Index: firmware/FSC/src/spare_outs.c
===================================================================
--- firmware/FSC/src/spare_outs.c	(revision 10108)
+++ firmware/FSC/src/spare_outs.c	(revision 10109)
@@ -1,13 +1,0 @@
-#include "spare_outs.h"
-#include <avr/io.h>
-
-void spare_outs_init(void)
-{
-	DDRB |= (1<<PB2) | (1<<PB3); 	// set Out1_spare & out2_spare as outputs
-
-	DDRA &= ~(1<<PA7);				// set In1_spare as input
-	DDRC &= ~(1<<PC7);				// set In2_spare as input
-	PORTA |= (1<<PA7); 				// swtich on pullup on In1_spare
-	PORTC |= (1<<PC7); 				// swtich on pullup on In2_spare
-
-}
Index: firmware/FSC/src/spare_outs.h
===================================================================
--- firmware/FSC/src/spare_outs.h	(revision 10108)
+++ firmware/FSC/src/spare_outs.h	(revision 10109)
@@ -1,6 +1,0 @@
-#ifndef __SPARE_OUTS_H
-#define __SPARE_OUTS_H
-
-void spare_outs_init(void);
-
-#endif //__SPARE_OUTS_H
Index: firmware/FSC/src/spi_master.c
===================================================================
--- firmware/FSC/src/spi_master.c	(revision 10108)
+++ firmware/FSC/src/spi_master.c	(revision 10109)
@@ -20,29 +20,39 @@
 void spi_init(void)
 {
-
-// set all CS's: output
-DDRB |= (1 << SPI_E_CS);
-DDRD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS);
-
-// set all Chips selects HIGH
-PORTB |= (1 << SPI_E_CS);
-PORTD |= (1 << SPI_AD_CS) |(1 << SPI_M_CS) |(1 << SPI_A_CS);
-
-// set MOSI and SCK: output & // set MISO: input
-SPI_DDR |= (1 << SPI_MOSI);
-SPI_DDR |= (1 << SPI_SCLK);
-SPI_DDR &= ~(1 << SPI_MISO);
-
-// set MOSI, SCK: HIGH. MISO leave alone.
-SPI_PRT |= (1 << SPI_MOSI);
-SPI_PRT |= (1 << SPI_SCLK);
-SPI_PRT |= (1 << SPI_MISO);
-
-
-
-  spi_clock_index = 4;  // Set Clockindex for lowest clock speed (F_CPU / 128)
-  spi_dord = 0;					// Data Order MSB first dord = 0
-  spi_cpol = 1;			
-  spi_cpha = 1;					// mode=3 needed by ADC ... lets see whats next.
+  // there are a total of 4 devices on the SPI bus:
+	// 1.) Ethernet Modul WIZ812MJ 
+	// 2.) AD7719 24bit ADC
+	// 3.) LIS3LV accelerometer
+	// 4.) MAX6662 temp sensor <---- not assembled!
+
+	// We check if they all can live with the same SPI settings:
+	// 1.) Ethernet modul:
+	// supports spi mode=0 or mode=3 --> eighther cpol=cpha=0 or cpol=cpha=1
+	// MSB first
+	// SCLK time 70ns minimum --> 14.2MHz maximum
+	//
+	// 2.) AD7719
+	// supports mode=3 --> cpol=cpha=1
+	// MSB first
+	// SCLK time 200ns minimum --> 5MHz maximum
+	//
+	// 3.) LIS3LV
+	// SPI CLK idles high 				--> cpol=1
+	// data valid at rising edge. --> cpha=1 as well 
+	// ==> mode 3 is supported only.
+	// MSB first, but take take at multi byte transfers. LSbyte first
+	// SCLK time - is not mentioned in the datasheet
+	//
+	// 4.) MAX6662 Tempsensor
+	// since it is not assembled, this information is not necessary.
+
+	// fastes SPI CLK frequency can be 					--> F_CPU/2 	= 4MHz
+	// slowest can be 													--> F_CPU/128	= 62.5KHz
+	
+	// Lets try with the fastest!
+	spi_clock_index = 0;  // Set Clockindex for lowest clock speed (F_CPU / 128)
+
+  spi_dord = 0;					// Data Order MSB first dord = 0  --> good for all devices
+  spi_cpol = 1;	spi_cpha = 1;					// SPI mode=3 			--> good for all devices
   spi_setup(); 					// Setup SPI bits and clock speed
 
Index: firmware/FSC/src/spi_master.h
===================================================================
--- firmware/FSC/src/spi_master.h	(revision 10108)
+++ firmware/FSC/src/spi_master.h	(revision 10109)
@@ -7,27 +7,10 @@
 #include "usart.h"
 //-----------------------------------------------------------------------------
-
-// Port Definitions
-#define SPI_PRT PORTB
-#define SPI_DDR DDRB
-
-// Bit Definitions
-#define SPI_SCLK PB7
-#define SPI_MOSI PB5
-#define SPI_MISO PB6
-// #define SPI_SS 	 PB4  // not in this application!!! danger
-#define SPI_E_CS PB4 		//device 0
-#define SPI_AD_CS PD3 		//device 1
-#define SPI_M_CS PD4		//device 2
-#define SPI_A_CS PD5		//device 3
-
 #define SPI_READ_BUFFER_SIZE 16
 #define SPI_WRITE_BUFFER_SIZE 16
 
-#define SPI_MAX_SLAVE_INDEX 2
-#define SPI_MAX_CLOCK_INDEX 6
-
+#define SPI_MAX_SLAVE_INDEX 2 //?
+#define SPI_MAX_CLOCK_INDEX 6 //?
 //-----------------------------------------------------------------------------
-
 extern volatile U08 spi_clock_index;
 extern volatile U08 spi_cpol;
Index: firmware/FSC/src/typedefs.h
===================================================================
--- firmware/FSC/src/typedefs.h	(revision 10108)
+++ firmware/FSC/src/typedefs.h	(revision 10109)
@@ -93,4 +93,5 @@
 typedef U08 BOOL;
 typedef BOOL *pBOOL;
+typedef U08 bool;
 
 //typedef U08 __flash *fpU08; //geht nicht mit gcc
Index: firmware/FSC/src/usart.c
===================================================================
--- firmware/FSC/src/usart.c	(revision 10108)
+++ firmware/FSC/src/usart.c	(revision 10109)
@@ -2,5 +2,4 @@
 
 #include "usart.h"
-
 #include <avr/interrupt.h>
 //-----------------------------------------------------------------------------
@@ -46,7 +45,13 @@
 void usart_write_char(U08 data)
 {
-  while (!(UCSRA & (1 << UDRE))) ; // Wait until tx register is empty
-
-  UDR = data;
+//  while (!(UCSRA & (1 << UDRE))) ; // Wait until tx register is empty
+//  UDR = data;
+
+	if ( usart_tx_buffer_index < USART_TX_BUFFER_SIZE-1){
+		usart_tx_buffer[usart_tx_buffer_index] = data;
+		++usart_tx_buffer_index;
+	} else {
+		usart_tx_buffer_overflow = true;
+	}
 }
 //-----------------------------------------------------------------------------
@@ -167,5 +172,5 @@
 ISR(SIG_USART_RECV)
 {
-	if (ISR_toggle_out) PORTB ^= (1<<PB3); // toggle Out2_spare when starting ISR
+  if (ISR_toggle_out) PORTB ^= (1<<PB3); // toggle Out2_spare when starting ISR
 
   usart_receive_char = UDR;
@@ -227,5 +232,5 @@
     usart_writeln_str(usart_rx_buffer);
   }
-#endif 
+
   //usart_write_char(usart_rx_buffer[usart_rx_buffer_index]);
  //usart_writeln_str(usart_rx_buffer);
@@ -235,5 +240,5 @@
  //usart_write_char(usart_rx_buffer);
 }  
-
+#endif 
 /*
 #define uart_maxstrlen 64
Index: firmware/FSC/src/usart.h
===================================================================
--- firmware/FSC/src/usart.h	(revision 10108)
+++ firmware/FSC/src/usart.h	(revision 10109)
@@ -20,9 +20,13 @@
                                 ((U32)br * 16) - 1))
 //-----------------------------------------------------------------------------
-
+/*
 extern U08 usart_rx_buffer[];
 extern volatile BOOL usart_rx_ready;
 extern volatile BOOL ISR_toggle_out;
 extern U08 usart_received_chars;
+*/
+extern bool usart_tx_buffer_overflow;
+extern U08 usart_tx_buffer_index;
+extern U08 usart_tx_buffer[USART_TX_BUFFER_SIZE];
 //-----------------------------------------------------------------------------
 
