Index: firmware/FSC/src/FSC_neu.c
===================================================================
--- firmware/FSC/src/FSC_neu.c	(revision 10667)
+++ firmware/FSC/src/FSC_neu.c	(revision 10667)
@@ -0,0 +1,324 @@
+//-----------------------------------------------------------------------------
+#include "typedefs.h"
+#include "muxer_fsc.h"
+#include "parser.h"
+#include "application.h"
+#include "output.h"
+#include "spi_master.h"
+#include "ad7719_adc.h"
+#include "atmega_adc.h"    
+#include "usart.h"
+#include "macros.h"
+#include "interpol.h"
+#include "w5100_spi_interface.h"
+#include <avr/interrupt.h>
+#include <avr/wdt.h>
+#include <stdlib.h>
+//-----------------------------------------------------------------------------
+
+// MAIN WORKFLOW GLOBAL VARIABLES
+	bool heartbeat_enable = true;
+	bool human_readable_interface_active = true;
+	
+
+// USART global variables
+	U08 usart_rx_buffer[USART_RX_BUFFER_SIZE];
+	U08 usart_tx_buffer[USART_TX_BUFFER_SIZE];
+	U08 usart_received_chars;
+	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
+	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
+	U08 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;
+
+	bool once_told_you = true;
+	bool debug_mode = false;
+
+//-----------------------------------------------------------------------------
+//   M A I N    ---   M A I N    ---   M A I N    ---   M A I N    ---  M A I N    
+//-----------------------------------------------------------------------------
+int main(void)
+{
+	app_init();		  // Setup: Watchdog and I/Os
+	usart_init();		// Initialize serial interface   
+	spi_init(); 		// Initialize SPI interface as master
+	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();              
+
+  PORTB &= ~(1<<PB2);  // PULL PB2 low --> this is #RST of WIZ812MJ --> WIZ812MJ is inactive.
+
+	static U08 welcome[]="\n\nwelcome to FACT FSC commandline interface v0.5\nready?";
+	usart_write_str(welcome);
+
+	
+  
+for ( U08 i=0; i<CHANNEL_BITMAP; ++i ) {
+	ad7719_enables[i]=0x00;
+	ad7719_channels_ready[i]=0;
+	}
+	ad7719_enables[0]=0x08;
+for ( U08 i=0; i<V_BITMAP + I_BITMAP; ++i ) {
+	adc_enables[i]=0xFF;
+	adc_channels_ready[i]=0;
+}
+	adc_enables[V_BITMAP + I_BITMAP + H_BITMAP -1] = 0xF0;
+	adc_channels_ready[V_BITMAP + I_BITMAP + H_BITMAP -1]=0;
+
+
+
+//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
+	// THIS IS NOT USED AT THE MOMENT
+	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 space 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) {
+	
+		// TX BUFFER is not used in this firmware version.
+		
+		// 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_ascii();
+		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);
+			_delay_ms(10);
+		} 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_measured_all) {
+			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;
+			if (debug_mode) {
+				usart_write_U32_hex(ad7719_current_reading);
+				usart_write_char('\n');
+				usart_write_char('\n');
+			}
+			// 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;
+			if (debug_mode) {
+				usart_write_U32_hex(ad7719_current_reading);
+				usart_write_char('\n'); 
+			}
+
+			// current reading is not used for anything else
+		}
+	}
+//----------------------------------------------------------------------------
+	//IF one of the ADC measured all channels, we wanted to know.
+	check_what_measurement_was_finished();
+	
+	if (ad7719_measured_all && adc_measured_all && !once_told_you)
+	{
+		adc_output_all();
+		once_told_you = true;
+	}
+//----------------------------------------------------------------------------
+
+} // 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     
+//-----------------------------------------------------------------------------
+} // end of main() function
+
+
+ISR (TIMER2_COMP_vect)
+{
+ ++local_ms;
+}
+
+
+U08	increase_adc (U08 channel){
+U08 effective_channel;
+	for ( U08 increase = 1 ; increase <= V_CHANNELS + I_CHANNELS + H_CHANNELS; increase++)
+	{
+		effective_channel = (channel + increase) % (V_CHANNELS + I_CHANNELS + H_CHANNELS);
+		if (adc_enables[effective_channel/8] & (1<<effective_channel%8))
+			return effective_channel;
+	}
+	return channel;
+} // end if increase_adc;
+
+U08	increase_ad7719 (U08 channel){
+U08 effective_channel;
+	for ( U08 increase = 1 ; increase <= TEMP_CHANNELS; increase++)
+	{
+		effective_channel = (channel + increase) % (TEMP_CHANNELS);
+		if (ad7719_enables[effective_channel/8] & (1<<effective_channel%8))
+			return effective_channel;
+	}
+	return channel;
+} // end if increase_adc;
+
+void check_what_measurement_was_finished() {
+	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;
+		}
+	}
+
+
+}
+
+
+
+void set_ad7719_enable_register() {
+
+	usart_write_str((pU08)"\n set enable bits of AD7719 Port ");
+	if ((usart_rx_buffer_index>=5) && 
+	(usart_rx_buffer[2] >= 'A' && usart_rx_buffer[2] <= 'H'))
+	{
+	usart_write_char(usart_rx_buffer[2]);
+	usart_write_str((pU08)" to ");
+	usart_write_U08_hex(usart_rx_buffer[4]);
+	usart_write_char('\n');
+		ad7719_enables[usart_rx_buffer[2]-'A']=usart_rx_buffer[4];
+		ad7719_channels_ready[usart_rx_buffer[2]-'A']=0x00;
+	}
+	else if  ((usart_rx_buffer_index=3) && 
+	(usart_rx_buffer[1] >= 'A' && usart_rx_buffer[1] <= 'H'))
+	{
+		usart_write_char(usart_rx_buffer[1]);
+		if (usart_rx_buffer[2]!='0') {
+			usart_write_str((pU08)" to 0xFF\n");
+			ad7719_enables[usart_rx_buffer[1]-'A']=0xFF;
+		} else
+		{
+			usart_write_str((pU08)" to 0x00\n");
+			ad7719_enables[usart_rx_buffer[1]-'A']=0x00;
+		}
+		ad7719_channels_ready[usart_rx_buffer[1]-'A']=0x00;	
+	}
+	else
+	{
+		usart_write_str((pU08)"\n something wrong\n");
+		usart_write_str((pU08)"usart_rx_buffer_index: ");
+		usart_write_U08(usart_rx_buffer_index, 3);
+		usart_write_str((pU08)"\n usart_rx_buffer[2]: ");
+		usart_write_char(usart_rx_buffer[2]);
+		usart_write_str((pU08)"\n usart_rx_buffer[4]: ");
+		usart_write_U08_hex(usart_rx_buffer[4]);
+		usart_write_char('\n');
+	}
+}
+
+void set_adc_enable_register() {
+	// TODO
+	usart_write_str((pU08)"setting of ATmega internal ADC enable registers is not supported. yet.\n");
+}
Index: firmware/FSC/src/FSC_old.c
===================================================================
--- firmware/FSC/src/FSC_old.c	(revision 10667)
+++ firmware/FSC/src/FSC_old.c	(revision 10667)
@@ -0,0 +1,823 @@
+//-----------------------------------------------------------------------------
+#include "typedefs.h"
+#include "application.h"
+#include "spi_master.h"
+#include "ad7719_adc.h"
+#include "atmega_adc.h"    
+#include "usart.h"
+#include "macros.h"
+#include "interpol.h"
+#include "w5100_spi_interface.h"
+#include <avr/interrupt.h>
+#include <avr/wdt.h>
+#include <stdlib.h>
+//-----------------------------------------------------------------------------
+// definition of some functions:
+// these function are implemented in this file, this is not doog coding style.
+// 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)
+{
+	app_init();		  // Setup: Watchdog and I/Os
+	usart_init();		// Initialize serial interface   
+	spi_init(); 		// Initialize SPI interface as master
+	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();              
+
+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;
+
+U08 SA_mux_val = 0x00;
+U08 SB_mux_val = 0x00;
+
+//U08 counter = 0;
+U08 Res_or_Volt = 0x00;
+
+
+while (TRUE)
+	 {
+
+
+  ++Res_or_Volt;
+  if (Res_or_Volt <= 64){
+
+
+		// if USART data arrives. i.e. data via USB
+		// the usart_rx_ready flag is set TRUE
+		// now process the incoming data which is stored in 
+		// U08 usart_rx_buffer[USART_RX_BUFFER_SIZE]
+		// and tell the USART interface, it may receive new data
+		// by setting the usart_rx_ready flag FALSE again
+		++SA_mux_val;
+		if (Res_or_Volt == 1) SB_mux_val = 16;
+		else if (SA_mux_val == 64) SA_mux_val = 32;
+		else if (SA_mux_val == 16) SA_mux_val = 48;
+		else if (SA_mux_val == 32) SA_mux_val = 0;
+		PORTA = (SA_mux_val & 0x3F); 
+				
+//		usart_write_str((pU08)"SA:");
+		usart_write_U08(SA_mux_val,2);
+		usart_write_str((pU08)" Sensor:");
+		usart_write_U08((SA_mux_val % 8)+1,2);
+		usart_write_str((pU08)" an Temperatur_");
+		switch (SA_mux_val / 8)
+		{
+			case 0: usart_write_str((pU08)"C");
+			break;
+			case 1: usart_write_str((pU08)"D");
+			break;
+			case 2: usart_write_str((pU08)"A");
+			break;
+			case 3: usart_write_str((pU08)"B");
+			break;
+			case 4: usart_write_str((pU08)"G");
+			break;
+			case 5: usart_write_str((pU08)"H");
+			break;
+			case 6: usart_write_str((pU08)"E");
+			break;
+			case 7: usart_write_str((pU08)"F");
+			break;
+			default: usart_write_str((pU08)"alarm!");
+			break;
+		}
+//		usart_write_str((pU08)"\n");
+		usart_write_str((pU08)"  ");
+
+
+		startconv(0);
+
+	
+		while (!AD7719_IS_READY())
+		{
+		// just wait until ADC is redy -- really bad code here!
+		}	    			
+ 		
+		resistance = getresistance();
+							//Start a new A/D Conversion
+    	//temp = 	readandsendtemp();
+		//adcword = getadc();
+		
+		//temperature = gettemp();
+		usart_write_str((pU08)"R:");
+		usart_write_float(resistance,3,4);
+		usart_write_str((pU08)"kOhm ");
+		
+		//_delay_ms(200);
+
+		startconv(0);
+
+		while (!AD7719_IS_READY())
+		{
+		// just wait until ADC is redy -- really bad code here!
+		}	    			
+   									//Start a new A/D Conversion
+    	//temp = 	readandsendtemp();
+		//adcword = getadc();
+		resistance = getresistance();
+		//temperature = gettemp();
+		usart_write_str((pU08)"R:");
+		usart_write_float(resistance,3,4);
+		usart_write_str((pU08)"kOhm ");			
+
+//usart_write_str((pU08)"\n");
+switch (SA_mux_val)
+		{
+			case 7: usart_write_str((pU08)"\n\n");
+			break;
+			case 15: usart_write_str((pU08)"\n\n");
+			break;
+			case 23: usart_write_str((pU08)"\n\n");
+			break;
+			case 31: usart_write_str((pU08)"\n\n");
+			break;
+			case 39: usart_write_str((pU08)"\n\n");
+			break;
+			case 47: usart_write_str((pU08)"\n\n");
+			break;
+			case 55: usart_write_str((pU08)"\n\n");
+			break;
+			case 63: usart_write_str((pU08)"\n\n");
+			break;
+			default: usart_write_str((pU08)"\n");
+			break; 
+		}
+SB_mux_val = 0;
+}
+else if (Res_or_Volt == 148) Res_or_Volt = 0;
+else {
+
+
+		++SB_mux_val;		
+		if (SB_mux_val == 84) SB_mux_val = 0;
+		else if (SB_mux_val == 74) SB_mux_val = 82;
+		else if (SB_mux_val == 82) SB_mux_val = 72;
+		else if (SB_mux_val == 72) SB_mux_val = 74;
+		else if (SB_mux_val == 48) SB_mux_val = 64;
+		else if (SB_mux_val == 64) SB_mux_val = 32;
+		else if (SB_mux_val == 32) SB_mux_val = 48;
+		PORTC = (SB_mux_val & 0x7F);
+ 
+
+
+
+usart_write_str((pU08)"8bit-ADC: ");
+
+if (SB_mux_val < 64)
+{
+		switch (SB_mux_val / 16)
+		{
+			case 0: usart_write_str((pU08)"voltage_A: ");
+			break;
+			case 1: usart_write_str((pU08)"voltage_B: ");
+			break;
+			case 2: usart_write_str((pU08)"voltage_D: ");
+			break;
+			case 3: usart_write_str((pU08)"voltage_C: ");
+			break;
+		}
+
+		if (SB_mux_val % 2 == 0) {
+			usart_write_str((pU08)"U");
+			usart_write_U08( (SB_mux_val%16)/2 , 1 );
+		} else {
+			usart_write_str((pU08)"I");
+			usart_write_U08( ((SB_mux_val%16)-1)/2 , 1 );
+		}
+
+
+} else {
+
+
+	if (SB_mux_val < 72)  {
+		usart_write_str((pU08)"voltage_E: ");
+		if (SB_mux_val % 2 == 0) {
+			usart_write_str((pU08)"U");
+			usart_write_U08( (SB_mux_val%8)/2 , 1 );
+		} else {
+			usart_write_str((pU08)"I");
+			usart_write_U08( ((SB_mux_val%8)-1)/2 , 1 );
+		}
+
+	}
+else if (SB_mux_val == 72) usart_write_str((pU08)"humidity_A: H0");
+else if (SB_mux_val == 73) usart_write_str((pU08)"humidity_A: H1");
+
+else if (SB_mux_val < 82) {
+		usart_write_str((pU08)"voltage_F: ");
+		if (SB_mux_val % 2 == 0) {
+			usart_write_str((pU08)"U");
+			usart_write_U08( ((SB_mux_val-2)%8)/2 , 1 );
+		} else {
+			usart_write_str((pU08)"I");
+			usart_write_U08( (((SB_mux_val-2)%8)-1)/2 , 1 );
+		}
+
+	}
+else if (SB_mux_val == 82) usart_write_str((pU08)"humidity_B: H0");
+else if (SB_mux_val == 83) usart_write_str((pU08)"humidity_B: H1");
+}
+
+for (U08 counter = 0; counter < 1; ++counter) {
+	while (ADCSRA & (1<<ADSC) );    // wait until internal ADC is ready
+	float voltage;
+	voltage = ( (float)ADCH ) / 256 * 4.096;
+	usart_write_str((pU08)" ");
+	usart_write_float(voltage,3,4);
+
+
+}
+//usart_write_str((pU08)"\n");
+
+switch (SB_mux_val)
+		{
+			case 15: usart_write_str((pU08)"\n\n");
+			break;
+			case 31: usart_write_str((pU08)"\n\n");
+			break;
+			case 47: usart_write_str((pU08)"\n\n");
+			break;
+			case 63: usart_write_str((pU08)"\n\n");
+			break;
+			case 71: usart_write_str((pU08)"\n\n");
+			break;
+			case 73: usart_write_str((pU08)"\n\n");
+			break;
+			case 81: usart_write_str((pU08)"\n\n");
+			break;
+			case 83: usart_write_str((pU08)"\n\n");
+			break;
+			default: usart_write_str((pU08)"\n");
+			break; 
+		}
+
+SA_mux_val = 15;
+}		
+	/*	
+		if ( usart_rx_ready == TRUE )
+		{
+			//understand what it means and react
+			
+			switch (usart_rx_buffer[0])
+			{
+				
+				case 'h':
+				{
+					// toggle the heartbeat mode on or off.
+					heartbeat_enable = !heartbeat_enable;
+					break;
+				}
+				case 'a':
+				{
+					// conduct adc - AD7719 SPI interface test
+					
+					break;
+				}
+				case 'e':
+				{
+					// conduct ethernet module SPI interface test
+					strtol((char*) usart_rx_buffer+1, NULL, 0);
+					break;
+				}
+
+				default:
+				{
+					usart_write_str((pU08)"? you wrote: ");
+					usart_write_str((pU08)usart_rx_buffer);
+					usart_write_str((pU08)"\n");
+					break;
+				}
+			}
+			
+			heartbeat_enable = !heartbeat_enable;
+			usart_rx_ready = FALSE;
+		}
+*/
+// das ist ein paar schritte zu früh.
+// erstmal müssen die interfaces getestet werden.
+/*
+
+		for (U08 i = 0; i<16; i++)
+	  	{ 
+			
+	   		if((~PIND) & 0x08)  // PD4 is #ADC_RDY input. Inverted logic! if PD4=0 this evaluates to true					
+	    	{		
+				PORTA = (PORTA & 0xF0) | ((i) & 0x0F); 	// switch muxer
+		   		startconv();							//Start a new A/D Conversion
+		    	//temp = 	readandsendtemp();
+				//adcword = getadc();
+				//resistance = getresistance();
+				temperature = gettemp();
+				usart_write_float(temperature,2,4);
+				usart_write_str((pU08)"\t");
+
+			} // end of if adc ready
+			else
+			{
+			i--;
+			}
+		} // end of for loop over 16 channels
+		usart_write_crlf();
+
+*/
+
+ 	}	// end of infinite while loop
+} // end of main()
+
+
+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:"); 
+	else if (channel < 80)
+		usart_write_str((pU08)"I:"); 
+	else if (channel < 84)
+		usart_write_str((pU08)"H:"); 
+
+	switch (channel/16) {
+		case 0:
+			usart_write_char('A'); 
+			break;
+		case 1:
+			usart_write_char('B'); 
+			break;
+		case 2:
+			usart_write_char('D'); 
+			break;
+		case 3:
+			usart_write_char('C'); 
+			break;
+		case 4:
+			usart_write_char('E'); 
+			usart_write_char('E'); 
+			break;
+			
+	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/FSC_test.c
===================================================================
--- firmware/FSC/src/FSC_test.c	(revision 10667)
+++ firmware/FSC/src/FSC_test.c	(revision 10667)
@@ -0,0 +1,367 @@
+//-----------------------------------------------------------------------------
+#include "typedefs.h"
+#include "application.h"
+#include "spi_master.h"
+#include "ad7719_adc.h"
+#include "atmega_adc.h"    
+#include "usart.h"
+#include "macros.h"
+#include "muxer_fsc.h"
+#include "output.h"
+#include "parser.h"
+#include "interpol.h"
+#include "w5100_spi_interface.h"
+#include <avr/interrupt.h>
+#include <avr/wdt.h>
+#include <stdlib.h>
+//-----------------------------------------------------------------------------
+// definition of some functions:
+// these function are implemented in this file, this is not doog coding style.
+// sooner or later, they will be moved into more apropriate files.
+
+void parse(); //doesn't do anything at the moment
+
+// 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.
+	
+// TIMER global variable
+	volatile U32 local_ms = 0;
+
+// AD7719 global variables
+	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
+	U08 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;
+
+	bool once_told_you = true;
+	bool debug_mode = false;
+	
+#ifndef ___MAIN_WORKFLOW_GLOBAL_VARS
+#define ___MAIN_WORKFLOW_GLOBAL_VARS	
+	#define TEMP_CHANNELS 64
+	#define CHANNEL_BITMAP 8
+	#define AD7719_READINGS_UNTIL_SETTLED 1 // bei3:480ms
+	#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
+	
+#endif // ___MAIN_WORKFLOW_GLOBAL_VARS
+
+
+//-----------------------------------------------------------------------------
+//   M A I N    ---   M A I N    ---   M A I N    ---   M A I N    ---  M A I N    
+//-----------------------------------------------------------------------------
+int main(void)
+{
+
+	app_init();		  // Setup: Watchdog and I/Os
+	usart_init();
+	spi_init(); 		// Initialize SPI interface as master
+	
+// 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();              
+
+	usart_write_str((pU08)"Start of test firmware (06.05.11) now:\n");
+	if (local_ms % 10000 == 0) {
+		usart_write_str((pU08)"time: ");
+		usart_write_U32(local_ms/1000,6);
+		usart_write_str((pU08)"sec.\n");
+	}
+	
+	PORTB &= ~(1<<PB2); //#reset = LOW --> W5100 is in reset ... 
+	_delay_ms(50); //reset
+	
+	PORTB |= 1<<PB2; //#reset = HIGH --> W5100 is active
+	_delay_ms(5);		// give it 5ms to accomodate.
+/*	
+	PORTB |= (1<<PB4);
+	usart_write_str((pU08)"PB4 switched HIGH. Please check & hit ENTER.\n");
+	while(!enter_received){
+		if ( UCSRA & (1<<RXC) ) {
+			if (UDR == '\n')
+				enter_received = true;
+		}
+	}
+	enter_received = false;
+*/
+
+	usart_write_str((pU08)"W5300 init begins at:");
+	usart_write_U32(local_ms,10);
+	usart_write_str((pU08)"ms.\n");
+	
+	w5100_init();
+ 
+	usart_write_str((pU08)"W5300 init finished at:");
+	usart_write_U32(local_ms,10);
+	usart_write_str((pU08)"ms.\n");
+
+	usart_write_str((pU08)"Wait for PC to connect to FSC...");
+	while (!w5100_is_established()) {
+		usart_write_str((pU08)"Socket status is:");
+		usart_write_U08_hex(w5100_sock_status());
+		usart_write_char('\n');
+		_delay_ms(333);
+	}
+	
+	usart_write_str((pU08)"connection to PC established at:");
+	usart_write_U32(local_ms/1000,6);
+	usart_write_str((pU08)"sec.\n");
+	
+	usart_write_str((pU08)"Ready to investigate, what's happening next? - HIT ENTER - \n");
+ 	while(!usart_rx_ready){
+		_delay_ms(10);
+	}
+	usart_rx_ready = false;
+	
+	
+	usart_write_str((pU08)"S0_TX_FSR\t|S0_TX_RD\t|S0_TX_WR\t|S0_RX_RSR\t|S0_RX_RD\t| 0x0426 | 0x0427 |\n");
+	while(!usart_rx_ready){
+		
+		usart_write_U16_hex(get_S0_TX_FSR()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_TX_RD()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_TX_WR()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_RX_RSR()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_RX_RD()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U08_hex( w5100_read(0x0426) ); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U08_hex( w5100_read(0x0427) ); usart_write_char('\t'); usart_write_char('|');
+		
+		usart_write_char('\n');
+
+		_delay_ms(400);
+		_delay_ms(400);
+	}
+	usart_rx_ready = false;
+
+	U16 received_bytes;
+	U08 really_downloaded_bytes;
+	while(!usart_rx_ready){
+		received_bytes = get_S0_RX_RSR();
+		
+		usart_write_U16_hex(get_S0_TX_FSR()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_TX_RD()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_TX_WR()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_RX_RSR()); usart_write_char('\t'); usart_write_char('|');
+		usart_write_U16_hex(get_S0_RX_RD()); usart_write_char('\t'); usart_write_char('|');
+		
+	
+		if (get_S0_RX_RSR() != 0) { // we have something to read
+			usart_write_str((pU08)"\nReading ");
+			usart_write_U16(get_S0_RX_RSR(), 6);
+			usart_write_str((pU08)" b from W5100\n");
+		
+			while (received_bytes != 0) {
+				really_downloaded_bytes = w5100_get_RX(16, true);
+				usart_write_char('!');
+				usart_write_U08(really_downloaded_bytes,4);
+				usart_write_char('\n');
+				for (U08 i=0; i<really_downloaded_bytes; i++){
+					usart_write_U08_hex(eth_read_buffer[i]);
+					usart_write_char(' ');
+				}
+				received_bytes -= really_downloaded_bytes;
+			}
+		}
+		usart_write_char('\n');
+		
+		_delay_ms(400);
+		_delay_ms(400);
+		_delay_ms(400);
+		_delay_ms(400);
+	}
+	usart_rx_ready = false;
+	
+	bool quit = false;
+	while (!quit) {
+	usart_write_str((pU08)"Enter the string to send to PC or \"XXX\" in order to quit\n");
+		while(!usart_rx_ready){
+			_delay_ms(100);
+		}
+		usart_rx_ready = false;
+	
+		if ( (usart_rx_buffer[0]=='X') &&  (usart_rx_buffer[1]=='X') && (usart_rx_buffer[2]=='X') )
+			quit = true;
+		else {
+			// copy string to W5100 TX buffer and issue 'SEND' command.
+			for (U08 i =0; i<usart_received_chars; i++){
+				eth_write_buffer[i]=usart_rx_buffer[i];
+			}
+			
+			w5100_set_TX(usart_received_chars);
+			
+		}		
+			
+		
+	}
+	
+} // end of main()	
+	
+/*
+//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     
+//-----------------------------------------------------------------------------
+
+*/
+
+
+
+ISR (TIMER2_COMP_vect)
+{
+ ++local_ms;
+}
+
+
+
+
Index: firmware/FSC/src/FSC_test_electrical_connection.c
===================================================================
--- firmware/FSC/src/FSC_test_electrical_connection.c	(revision 10667)
+++ firmware/FSC/src/FSC_test_electrical_connection.c	(revision 10667)
@@ -0,0 +1,299 @@
+//-----------------------------------------------------------------------------
+#include "typedefs.h"
+#include "application.h"
+#include "spi_master.h"
+#include "ad7719_adc.h"
+#include "atmega_adc.h"    
+#include "usart.h"
+#include "macros.h"
+#include "muxer_fsc.h"
+#include "output.h"
+#include "parser.h"
+#include "interpol.h"
+#include "w5100_spi_interface.h"
+#include <avr/interrupt.h>
+#include <avr/wdt.h>
+#include <stdlib.h>
+//-----------------------------------------------------------------------------
+// definition of some functions:
+// these function are implemented in this file, this is not doog coding style.
+// sooner or later, they will be moved into more apropriate files.
+
+void parse(); //doesn't do anything at the moment
+
+// 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
+	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
+	U08 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;
+
+	bool once_told_you = true;
+	bool debug_mode = false;
+	
+#ifndef ___MAIN_WORKFLOW_GLOBAL_VARS
+#define ___MAIN_WORKFLOW_GLOBAL_VARS	
+	#define TEMP_CHANNELS 64
+	#define CHANNEL_BITMAP 8
+	#define AD7719_READINGS_UNTIL_SETTLED 1 // bei3:480ms
+	#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
+	
+#endif // ___MAIN_WORKFLOW_GLOBAL_VARS
+
+
+//-----------------------------------------------------------------------------
+//   M A I N    ---   M A I N    ---   M A I N    ---   M A I N    ---  M A I N    
+//-----------------------------------------------------------------------------
+int main(void)
+{
+	U08 register_content;
+
+	app_init();		  // Setup: Watchdog and I/Os
+	usart_init();
+
+	spi_init(); 		// Initialize SPI interface as master
+	
+// 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();              
+
+	usart_write_str((pU08)"Start of test firmware (06.05.11) now:\n");
+	if (local_ms % 10000 == 0) {
+		usart_write_str((pU08)"time: ");
+		usart_write_U32(local_ms/1000,6);
+		usart_write_str((pU08)"sec.\n");
+	}
+
+  PORTB &= ~(1<<PB2); //#reset = LOW --> W5100 is in reset ... 
+	_delay_ms(50); //reset
+	
+	PORTB |= 1<<PB2; //#reset = HIGH --> W5100 is active
+	_delay_ms(5);		// give it 5ms to accomodate.
+	
+	
+//	DDRB |= (1 << PB2);  // setze 5tes bit im data direction register von port B
+//	DDRB |= (1 << PB3);  // setze 5tes bit im data direction register von port B
+//	DDRB |= (1 << PB4);  // setze 5tes bit im data direction register von port B
+	
+	while (1)
+	{ 
+		PORTB ^= (1<<PB4);  // toggle zustand vom 5ten bit in Port B
+		PORTB ^= (1<<PB3);  // toggle zustand vom 5ten bit in Port B
+		PORTB ^= (1<<PB2);  // toggle zustand vom 5ten bit in Port B
+		
+	_delay_ms(1); //reset
+		
+	}
+	
+	
+	while (1) {
+	usart_write_str((pU08)"Start to read from W5300 CM_RTR0 register at:");
+	usart_write_U32(local_ms,10);
+	usart_write_str((pU08)"ms.\n");
+	
+	register_content = w5100_read(CM_RTR0); // read something
+	
+	usart_write_str((pU08)"register content of CM_RTR0 retrieved at:");
+	usart_write_U32(local_ms,10);
+	usart_write_str((pU08)"ms.\t");
+	usart_write_str((pU08)"register content is: 0x");
+	usart_write_U08_hex(register_content);
+	usart_write_str((pU08)"\n");
+	
+	
+	_delay_ms(400); //reset
+	_delay_ms(400); //reset
+	_delay_ms(400); //reset
+}
+	
+	
+	usart_write_str((pU08)"W5300 init begins at:");
+	usart_write_U32(local_ms,10);
+	usart_write_str((pU08)"ms.\n");
+	
+	w5100_init();
+ 
+ 
+ 
+ 
+
+	
+} // end of main()	
+	
+/*
+//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     
+//-----------------------------------------------------------------------------
+
+*/
+
+
+
+ISR (TIMER2_COMP_vect)
+{
+ ++local_ms;
+}
+
+
+
+
Index: firmware/FSC/src/application.c
===================================================================
--- firmware/FSC/src/application.c	(revision 10245)
+++ firmware/FSC/src/application.c	(revision 10667)
@@ -2,4 +2,5 @@
 
 #include "application.h"
+#include "usart.h"
 #include <avr/wdt.h> 
 
@@ -10,6 +11,5 @@
 //-----------------------------------------------------------------------------
 
-void app_init(void)
-{
+void app_init(void) {
   app_reset_source = MCUSR; // Save last reset source
   MCUSR = 0x00; // Clear reset source for next reset cycle
@@ -34,6 +34,6 @@
 	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
+	//PORTA |= (1<<PA7); 				// swtich on pullup on In1_spare
+	//PORTC |= (1<<PC7); 				// swtich on pullup on In2_spare
 
 	// ATmega internal ADC input 
@@ -91,2 +91,88 @@
   SREG = sreg_backup; // Restore status register
 }
+
+void set_ad7719_enable_register() {
+
+	usart_write_str((pU08)"\n set enable bits of AD7719 Port ");
+	if ((usart_received_chars>=5) && 
+	(usart_rx_buffer[2] >= 'A' && usart_rx_buffer[2] <= 'H'))
+	{
+	usart_write_char(usart_rx_buffer[2]);
+	usart_write_str((pU08)" to ");
+	usart_write_U08_hex(usart_rx_buffer[4]);
+	usart_write_char('\n');
+		ad7719_enables[usart_rx_buffer[2]-'A']=usart_rx_buffer[4];
+		ad7719_channels_ready[usart_rx_buffer[2]-'A']=0x00;
+	}
+	else if  ((usart_received_chars=3) && 
+	(usart_rx_buffer[1] >= 'A' && usart_rx_buffer[1] <= 'H'))
+	{
+		usart_write_char(usart_rx_buffer[1]);
+		if (usart_rx_buffer[2]!='0') {
+			usart_write_str((pU08)" to 0xFF\n");
+			ad7719_enables[usart_rx_buffer[1]-'A']=0xFF;
+		} else
+		{
+			usart_write_str((pU08)" to 0x00\n");
+			ad7719_enables[usart_rx_buffer[1]-'A']=0x00;
+		}
+		ad7719_channels_ready[usart_rx_buffer[1]-'A']=0x00;	
+	}
+	else
+	{
+		usart_write_str((pU08)"\n something wrong\n");
+		usart_write_str((pU08)"usart_rx_buffer_index: ");
+		usart_write_U08(usart_received_chars, 3);
+		usart_write_str((pU08)"\n usart_rx_buffer[2]: ");
+		usart_write_char(usart_rx_buffer[2]);
+		usart_write_str((pU08)"\n usart_rx_buffer[4]: ");
+		usart_write_U08_hex(usart_rx_buffer[4]);
+		usart_write_char('\n');
+	}
+}
+
+void set_adc_enable_register() {
+	// TODO
+	usart_write_str((pU08)"setting of ATmega internal ADC enable registers is not supported. yet.\n");
+}
+
+U08	increase_adc (U08 channel){
+U08 effective_channel;
+	for ( U08 increase = 1 ; increase <= V_CHANNELS + I_CHANNELS + H_CHANNELS; increase++)
+	{
+		effective_channel = (channel + increase) % (V_CHANNELS + I_CHANNELS + H_CHANNELS);
+		if (adc_enables[effective_channel/8] & (1<<effective_channel%8))
+			return effective_channel;
+	}
+	return channel;
+} // end if increase_adc;
+
+U08	increase_ad7719 (U08 channel){
+U08 effective_channel;
+	for ( U08 increase = 1 ; increase <= TEMP_CHANNELS; increase++)
+	{
+		effective_channel = (channel + increase) % (TEMP_CHANNELS);
+		if (ad7719_enables[effective_channel/8] & (1<<effective_channel%8))
+			return effective_channel;
+	}
+	return channel;
+} // end if increase_adc;
+
+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/application.h
===================================================================
--- firmware/FSC/src/application.h	(revision 10245)
+++ firmware/FSC/src/application.h	(revision 10667)
@@ -6,12 +6,5 @@
 //-----------------------------------------------------------------------------
 
-#define USART_RX_BUFFER_SIZE 32 // Receive buffer size
-#define USART_TX_BUFFER_SIZE 5 // 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_UPPERCASE // Convert received chars to uppercase?
 //-----------------------------------------------------------------------------
 
@@ -31,4 +24,48 @@
 #define SPI_A_CS PD5		
 
+//#ifdef ____WENNICHSWIRKLICHWILL
+#ifndef ___MAIN_WORKFLOW_GLOBAL_VARS
+#define ___MAIN_WORKFLOW_GLOBAL_VARS
+	#define TEMP_CHANNELS 64
+	#define CHANNEL_BITMAP 8
+	#define AD7719_READINGS_UNTIL_SETTLED 3 // bei3:480ms
+	
+	#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
+#endif
+
+// MAIN WORKFLOW GLOBAL VARIABLES
+
+	extern bool heartbeat_enable;
+
+
+	
+// TIMER global variable
+	extern volatile U32 local_ms;
+
+// AD7719 global variables
+	extern U32 ad7719_values[TEMP_CHANNELS];
+	extern U08 ad7719_enables[CHANNEL_BITMAP];
+	extern U08 ad7719_channels_ready[CHANNEL_BITMAP];
+	extern U08 ad7719_readings_since_last_muxing;
+	extern U08 ad7719_current_channel;
+	extern U32 ad7719_current_reading;
+	extern bool ad7719_measured_all;
+// ATMEGA ADC global variables
+	extern U08 adc_values[V_CHANNELS + I_CHANNELS + H_CHANNELS]; // stores measured voltage in steps of 16mV
+	extern U08 adc_enables[V_BITMAP + I_BITMAP + H_BITMAP];
+	extern U08 adc_channels_ready[V_BITMAP + I_BITMAP + H_BITMAP];
+	extern U08 adc_readings_since_last_muxing;
+	extern U08 adc_current_channel;
+	extern U08 adc_current_reading;
+	extern bool adc_measured_all;
+
+	extern bool once_told_you;
+	extern bool debug_mode;
 
 
@@ -40,4 +77,20 @@
 void app_init(void); // Initialize application
 void app_set_watchdog_prescaler(tWDT_PRESCALE wdt_prescale); // Set watchdog prescale
+
+//methods in main ... declared here ... don't ask why ... 
+// definition of some functions:
+// these function are implemented in this file, this is not doog coding style.
+// sooner or later, they will be moved into more apropriate files.
+void set_adc_enable_register();
+void set_ad7719_enable_register();
+U08	increase_adc (U08 channel);
+U08	increase_ad7719 (U08 channel);
+void check_what_measurement_was_finished() ;
+void check_if_measured_all() ;
+// end of function definition:
+//-----------------------------------------------------------------------------
+
+
+
 //-----------------------------------------------------------------------------
 
Index: firmware/FSC/src/output.c
===================================================================
--- firmware/FSC/src/output.c	(revision 10245)
+++ firmware/FSC/src/output.c	(revision 10667)
@@ -1,4 +1,5 @@
 #include "output.h"
 #include "usart.h"
+#include "application.h"
 
 void print_status() {
Index: firmware/FSC/src/output.h
===================================================================
--- firmware/FSC/src/output.h	(revision 10245)
+++ firmware/FSC/src/output.h	(revision 10667)
@@ -9,5 +9,5 @@
 void print_ad7719_nicely();
 void print_adc_nicely();
-
+void print_status() ;
 
 #endif
Index: firmware/FSC/src/parser.c
===================================================================
--- firmware/FSC/src/parser.c	(revision 10245)
+++ firmware/FSC/src/parser.c	(revision 10667)
@@ -1,4 +1,6 @@
 #include "parser.h"
 #include "output.h"
+#include "application.h"
+#include "usart.h"
 // this method parses the data, 
 // which came in via USART
@@ -72,2 +74,33 @@
 		usart_rx_buffer[i] = 0;
 }
+
+void parse_non_human_readable_input() {
+
+
+}
+
+// this guy checks, if an incoming byte is:
+// to be stored, because it belongs to a command
+// to be discarded, because something went wrong, and the bytemade no sense...
+// the end of a commmand, and so the 'real parser' may do his work.
+
+void incoming_byte_parser() {
+	static bool receiving_command = false;
+	U08 current_byte = UDR;
+	
+	if (!receiving_command) { 
+		switch (current_byte) {
+			case 0x01:
+				receiving_command = true;
+				break;
+		}
+	}
+	
+	if (receiving_command)
+	{
+		usart_rx_buffer[usart_received_chars] = usart_last_char;
+		usart_received_chars++;
+	}
+	
+	
+}
Index: firmware/FSC/src/parser.h
===================================================================
--- firmware/FSC/src/parser.h	(revision 10245)
+++ firmware/FSC/src/parser.h	(revision 10667)
@@ -4,3 +4,8 @@
 void parse_ascii(); 
 
+
+// all allowed non readable commands are listed here
+#define SET_ENABLES 0x01 // sets all enables -- needs 8 + 11 bytes of data
+#define SW_TO_HUMAN 0xFF // SWITCH_TO_HUMAN_READABLE_INTERFACE
+
 #endif
Index: firmware/FSC/src/spi_master.c
===================================================================
--- firmware/FSC/src/spi_master.c	(revision 10245)
+++ firmware/FSC/src/spi_master.c	(revision 10667)
@@ -56,5 +56,5 @@
 
   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_cpol = 0;	spi_cpha = 0;					// SPI mode=0 good for ethernet.
   spi_setup(); 					// Setup SPI bits and clock speed
 
Index: firmware/FSC/src/usart.c
===================================================================
--- firmware/FSC/src/usart.c	(revision 10245)
+++ firmware/FSC/src/usart.c	(revision 10667)
@@ -2,6 +2,10 @@
 
 #include "usart.h"
+#include "num_conversion.h"
 #include <avr/interrupt.h>
 //-----------------------------------------------------------------------------
+#ifdef USART_USE_TX_IRQ
+
+#endif
 
 #ifdef USART_USE_RX_IRQ
@@ -13,5 +17,4 @@
   static U08 usart_receive_char;
   static BOOL usart_receive_suspended = false;
-  volatile BOOL ISR_toggle_out = false;
 #endif
 //-----------------------------------------------------------------------------
@@ -172,7 +175,5 @@
 ISR(SIG_USART_RECV)
 {
-  if (ISR_toggle_out) PORTB ^= (1<<PB3); // toggle Out2_spare when starting ISR
-
-  usart_receive_char = UDR;
+	usart_receive_char = UDR;
 
   if (usart_rx_ready) // Exit if ready flag is still set 
@@ -230,5 +231,5 @@
   {
     usart_rx_buffer[usart_rx_buffer_index++] = usart_receive_char;
-    usart_writeln_str(usart_rx_buffer);
+    //usart_writeln_str(usart_rx_buffer);
   }
 
@@ -241,29 +242,22 @@
 }  
 #endif 
-/*
-#define uart_maxstrlen 64
- 
-volatile U8 uart_str_complete=0;
-volatile U8 uart_str_count=0;
-volatile U8 uart_string[uart_maxstrlen+1]="";
-
-ISR(USART_RXC_vect)
-{
-    unsigned char buffer = 64;
-    // Daten aus dem Puffer lesen
-    buffer = UDR;
-	UDR = buffer;
-	if ( uart_str_complete==0 ){	// wenn uart_string gerade in Verwendung, neues Zeichen verwerfen
-		// Daten werden erst in string geschrieben, wenn nicht String-Ende/max Zeichenlänge erreicht ist/string gerade verarbeitet wird
-	  	if (buffer!='\n' && buffer!='\r' && uart_str_count<uart_maxstrlen-1){
-			uart_string[uart_str_count]=buffer;
-			uart_str_count++;
-		} else {
-			uart_string[uart_str_count]='\0';
-			uart_str_count=0;
-			uart_str_complete=1;
-		}
+
+
+#ifdef USART_USE_TX_IRQ
+
+ISR(TRALA_vect)
+{
+
+	// if it is necessary to write something via USART ... then send
+	// if not ... disable this interrupt.
+	if (usart_write_start_index < usart_write_stop_index) // some bytes in the usart_tx_buffer should be send away.
+	{
+		UDR = usart_tx_buffer[usart_write_start_index%USART_TX_BUFFER_SIZE];
 	}
-}
-
-*/
+	else
+	{
+		// disable this interrupt source
+		UCSRB &= ~(1<<UDRIE);
+	}
+}  
+#endif 
Index: firmware/FSC/src/usart.h
===================================================================
--- firmware/FSC/src/usart.h	(revision 10245)
+++ firmware/FSC/src/usart.h	(revision 10667)
@@ -6,4 +6,14 @@
 #include "application.h"
 #include "num_conversion.h"
+
+//-----------------------------------------------------------------------------
+#define USART_RX_BUFFER_SIZE 32 // Receive buffer size
+#define USART_TX_BUFFER_SIZE 5 // 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_UPPERCASE // Convert received chars to uppercase?
 //-----------------------------------------------------------------------------
 
@@ -20,14 +30,29 @@
                                 ((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;
-*/
+
+// USART global variables
+	extern U08 usart_rx_buffer[USART_RX_BUFFER_SIZE];
+	extern U08 usart_tx_buffer[USART_TX_BUFFER_SIZE];
+	extern U08 usart_received_chars;
+
+	extern U08 usart_tx_buffer_index;
+  	extern U08 usart_last_char; 					// last received char
+
+// USART FLAGS
+	extern bool usart_tx_buffer_overflow;	// true if usart_tx_buffer was full.
+
+
+
 extern bool usart_tx_buffer_overflow;
 extern U08 usart_tx_buffer_index;
 extern U08 usart_tx_buffer[USART_TX_BUFFER_SIZE];
-extern U08 usart_received_chars;
+
+#ifdef USART_USE_RX_IRQ
+  extern U08 usart_rx_buffer[];
+  //U08 *usart_rx_buffer_ptr = &usart_rx_buffer[0];
+  extern U08 usart_received_chars;
+  extern volatile BOOL usart_rx_ready;
+#endif
+
 //-----------------------------------------------------------------------------
 
Index: firmware/FSC/src/w5100_spi_interface.c
===================================================================
--- firmware/FSC/src/w5100_spi_interface.c	(revision 10245)
+++ firmware/FSC/src/w5100_spi_interface.c	(revision 10667)
@@ -3,4 +3,5 @@
 #include "w5100_spi_interface.h"       
 #include "spi_master.h"    
+#include "usart.h"
 volatile BOOL sock0_connection_established = false;
 volatile U08 eth_read_buffer[ETH_READ_BUFFER_SIZE];
@@ -34,5 +35,5 @@
 U08 w5100_init (void) 
 {
-U08 sock0_status;
+U08 sock0_status = 0x00;
 
 	// set FSCs MAC Address to value defined in w5100_spi_interface.h
@@ -70,18 +71,22 @@
 	w5100_write ( S0_PORT0, 0x13 ); 	// Port 5000 -> 0x1388 
 	w5100_write ( S0_PORT1, 0x88 ); 
+	usart_write_str((pU08)"Issuing Socket open command. NOW\n");
 	w5100_write ( S0_CR, CR_OPEN );		// issue Socket open command
-	sock0_status = w5100_read(S0_SR); // request socket 0 status
-	if ( sock0_status != SR_SOCK_INIT)
-	{
-		return sock0_status;
-	}
-
+	while (sock0_status != SR_SOCK_INIT) {
+		sock0_status = w5100_read(S0_SR); // request socket 0 status
+		usart_write_str((pU08)"Socket 0 status is:");
+		usart_write_U08_hex(sock0_status);
+		usart_write_char('\n');
+	}
+
+	usart_write_str((pU08)"Issuing Socket LISTEN command. NOW\n");
 	w5100_write ( S0_CR, CR_LISTEN );		// issue Socket listen command
-	sock0_status = w5100_read(S0_SR); // request socket 0 status
-	if ( sock0_status != SR_SOCK_LISTEN)
-	{
-		return sock0_status;
-	}
-
+	
+	while (sock0_status != SR_SOCK_LISTEN) {
+		sock0_status = w5100_read(S0_SR); // request socket 0 status
+		usart_write_str((pU08)"Socket 0 status is:");
+		usart_write_U08_hex(sock0_status);
+		usart_write_char('\n');
+	}
 	return sock0_status;
 }
@@ -113,7 +118,7 @@
 {
 U16 freesize;
-freesize=w5100_read(S0_TX_FSR1);
+freesize=w5100_read(S0_TX_FSR0);
 freesize = freesize << 8;
-freesize += w5100_read(S0_TX_FSR0);
+freesize += w5100_read(S0_TX_FSR1);
 return freesize;
 }
@@ -123,7 +128,7 @@
 {
 U16 readpointer;
-readpointer=w5100_read(S0_TX_RD1);
+readpointer=w5100_read(S0_TX_RD0);
 readpointer = readpointer << 8;
-readpointer += w5100_read(S0_TX_RD0);
+readpointer += w5100_read(S0_TX_RD1);
 return readpointer;
 }
@@ -133,7 +138,7 @@
 {
 U16 writepointer;
-writepointer=w5100_read(S0_TX_WR1);
+writepointer=w5100_read(S0_TX_WR0);
 writepointer = writepointer << 8;
-writepointer += w5100_read(S0_TX_WR0);
+writepointer += w5100_read(S0_TX_WR1);
 return writepointer;
 }
@@ -143,7 +148,7 @@
 {
 U16 received_size;
-received_size=w5100_read(S0_RX_RSR1);
+received_size=w5100_read(S0_RX_RSR0);
 received_size = received_size << 8;
-received_size += w5100_read(S0_RX_RSR0);
+received_size += w5100_read(S0_RX_RSR1);   // S0_RX_RSR1 is the least significant byte ... 
 return received_size;
 }
@@ -153,7 +158,7 @@
 {
 U16 readpointer;
-readpointer=w5100_read(S0_RX_RD1);
+readpointer=w5100_read(S0_RX_RD0);
 readpointer = readpointer << 8;
-readpointer += w5100_read(S0_RX_RD0);
+readpointer += w5100_read(S0_RX_RD1);
 return readpointer;
 }
@@ -164,7 +169,7 @@
 {
 U08 high_byte = (value>>8);
-U08 low_byte = (value<<8)>>8;
-w5100_write(S0_TX_WR1, high_byte);
-w5100_write(S0_TX_WR0, low_byte);
+U08 low_byte = value&0x00FF;
+w5100_write(S0_TX_WR0, high_byte);
+w5100_write(S0_TX_WR1, low_byte);
 }
 
@@ -173,7 +178,8 @@
 {
 U08 high_byte = (value>>8);
-U08 low_byte = (value<<8)>>8;
-w5100_write(S0_TX_RD1, high_byte);
-w5100_write(S0_TX_RD0, low_byte);
+U08 low_byte = value&0x00FF;
+
+w5100_write(S0_RX_RD0, high_byte);
+w5100_write(S0_RX_RD1, low_byte);
 }
 
@@ -200,4 +206,12 @@
 	U16 offset = last_RX_read_pointer & S0_RX_MASK;
 	U16 start_address =  S0_RX_BASE + offset;
+	
+	usart_write_str("last_read_pointer:");
+	usart_write_U16_hex(last_RX_read_pointer);
+	usart_write_str("\noffset:");
+	usart_write_U16_hex(offset);
+	usart_write_str("\nstart_address:");
+	usart_write_U16_hex(start_address);
+	usart_write_char('\n');
 
 	if ((offset + NumBytes) > (S0_RX_MASK + 1) )  // if data is turned over in RX-mem
@@ -224,4 +238,11 @@
 	// inform W5100 about how much data was read out.
 	set_S0_RX_RD(last_RX_read_pointer + NumBytes);
+	w5100_write ( S0_CR, CR_RECV );
+	
+	usart_write_U16_hex(get_S0_TX_FSR()); usart_write_char('\t'); usart_write_char('|');
+	usart_write_U16_hex(get_S0_TX_RD()); usart_write_char('\t'); usart_write_char('|');
+	usart_write_U16_hex(get_S0_TX_WR()); usart_write_char('\t'); usart_write_char('|');
+	usart_write_U16_hex(get_S0_RX_RSR()); usart_write_char('\t'); usart_write_char('|');
+	usart_write_U16_hex(get_S0_RX_RD()); usart_write_char('\t'); usart_write_char('|');
 
 	// if user wishes, W5100 may inform peer about receiption.
@@ -233,5 +254,5 @@
 	if (send_ACK)
 	{
-		w5100_write ( S0_CR, CR_RECV );
+		//w5100_write ( S0_CR, CR_RECV );
 	}
 
@@ -240,14 +261,9 @@
 
 // returns number of words, transmitted into TX - buffer.
-U08 w5100_set_TX(U08 NumBytes)
-{
+U08 w5100_set_TX(U08 NumBytes) {
 	U16 freesize = get_S0_TX_FSR();
 	if (freesize == 0)
 	{
 		return 0;
-	}
-	if (freesize < NumBytes)
-	{
-		NumBytes = freesize;
 	}
 	
@@ -258,7 +274,7 @@
 
 	U16 upper_size, lower_size;
-	if (NumBytes > ETH_READ_BUFFER_SIZE)
-	{
-		NumBytes = ETH_READ_BUFFER_SIZE;
+	if (NumBytes > ETH_WRITE_BUFFER_SIZE)
+	{
+		NumBytes = ETH_WRITE_BUFFER_SIZE;
 	}
 	if (freesize == 0)
@@ -272,5 +288,5 @@
 
 	// now calculate the offset address
-	// calculated according to W5100 datasheet page: 43
+	// calculated according to W5100 datasheet page: 44
 
 	if ((offset + NumBytes) > (S0_RX_MASK + 1) )  // if data is turned over in RX-mem
@@ -280,9 +296,9 @@
 		for (U08 i = 0; i < upper_size; ++i)
 		{
-			eth_read_buffer[i] = w5100_read(start_address + i);
+			w5100_write(start_address + i, eth_write_buffer[i]);
 		}
 		for (U08 i = 0; i < lower_size; ++i)
 		{
-			eth_read_buffer[upper_size + i] = w5100_read(S0_RX_BASE + i);
+			w5100_write(S0_RX_BASE + i, eth_write_buffer[upper_size+i]);
 		}
 	}
@@ -291,12 +307,15 @@
 		for (U08 i = 0; i < NumBytes; ++i)
 		{
-			eth_read_buffer[i] = w5100_read(start_address + i);
+			w5100_write(start_address + i, eth_write_buffer[i]);
 		}
 	}
 
 	// inform W5100 about how much data was read out.
-	set_S0_RX_RD(last_TX_write_pointer + NumBytes);
-
-
+	set_S0_TX_WR(last_TX_write_pointer + NumBytes);
+	
+	// tell it to send now the data away
+	w5100_write( S0_CR, CR_SEND);
+	
 	return NumBytes;
 }
+
Index: firmware/FSC/src/w5100_spi_interface.h
===================================================================
--- firmware/FSC/src/w5100_spi_interface.h	(revision 10245)
+++ firmware/FSC/src/w5100_spi_interface.h	(revision 10667)
@@ -69,6 +69,6 @@
 #define S0_IR		0x0402		// socket 0 interrupt		-- see bit description below
 #define S0_SR		0x0403		// socket 0 status			-- see below
-#define S0_PORT0	0x0404		// socket 0 Port			-- FSC might get port number 0x1F5C = 8028, since we have only one FSC in cam
-#define S0_PORT1	0x0405		// socket 0 Port 			-- 0xF5C1= 62913 is okay as well ... 
+#define S0_PORT0	0x0404		// socket 0 Port MSB			-- FSC might get port number 0x1F5C = 8028, since we have only one FSC in cam
+#define S0_PORT1	0x0405		// socket 0 Port LSB			-- 0xF5C1= 62913 is okay as well ... 
 #define S0_MSSR0	0x0412		// max segment size			--
 #define S0_MSSR1	0x0413		// max segment size			-- reset value is 0xFFFF; is set to other party value, if in TCP passive mode
@@ -143,8 +143,15 @@
 // NETWORK SETTING:
 // set GAR to FSC_GATEWAY_ADDRESS
-#define FSC_GATEWAY_ADDRESS0 0xC0		// 192.33.96.1
+//#define FSC_GATEWAY_ADDRESS0 0xC0		// 192.33.96.1
+//#define FSC_GATEWAY_ADDRESS1 0x21
+//#define FSC_GATEWAY_ADDRESS2 0x60
+//#define FSC_GATEWAY_ADDRESS3 0x01
+
+#define FSC_GATEWAY_ADDRESS0 0xC0		// 192.168.0.1
 #define FSC_GATEWAY_ADDRESS1 0x21
 #define FSC_GATEWAY_ADDRESS2 0x60
 #define FSC_GATEWAY_ADDRESS3 0x01
+
+
 // set SHAR to FSC_MAC_ADDRESS
 #define FSC_MAC_ADDRESS0 0xFA	//FA:C7:0F:AD:22:01
@@ -155,13 +162,17 @@
 #define FSC_MAC_ADDRESS5 0x01
 // set SUBR to FSC_SUBNET_MASK
-#define FSC_SUBNET_MASK0 0xFF	//255.255.248.0
-#define FSC_SUBNET_MASK1 0xFF
-#define FSC_SUBNET_MASK2 0xF8
-#define FSC_SUBNET_MASK3 0x00
+#define FSC_SUBNET_MASK0 255	//255.255.248.0
+#define FSC_SUBNET_MASK1 255
+#define FSC_SUBNET_MASK2 255
+#define FSC_SUBNET_MASK3 0
 // set SIPR to FSC_IP_ADDRESS
-#define FSC_IP_ADDRESS0 0xC0	// 192.33.99.247
-#define FSC_IP_ADDRESS1 0x21
-#define FSC_IP_ADDRESS2 0x63
-#define FSC_IP_ADDRESS3 0xF7
+//#define FSC_IP_ADDRESS0 0xC0	// 192.33.99.247
+//#define FSC_IP_ADDRESS1 0x21
+//#define FSC_IP_ADDRESS2 0x63
+//#define FSC_IP_ADDRESS3 0xF7
+#define FSC_IP_ADDRESS0 192	// 192.168.0.2
+#define FSC_IP_ADDRESS1 168
+#define FSC_IP_ADDRESS2 0
+#define FSC_IP_ADDRESS3 2
 //------------------------------------------------------------------------------
 // MEM SETTINGS:
@@ -196,2 +207,11 @@
 //-----------------------------------------------------------------------------
 #endif //__W5100_SPI_INTERFACE_H
+
+U16 get_S0_TX_FSR();
+U16 get_S0_TX_RD();
+U16 get_S0_TX_WR();
+U16 get_S0_RX_RSR();
+U16 get_S0_RX_RD();
+U08 w5100_get_RX(U08 NumBytes, BOOL send_ACK);
+void w5100_TX(U08 NumBytes, U08 *str);
+U08 w5100_set_TX(U08 NumBytes);
