Index: branches/encoders/code/projects/template/main.c
===================================================================
--- branches/encoders/code/projects/template/main.c	(revision 366)
+++ branches/encoders/code/projects/template/main.c	(revision 367)
@@ -1,84 +1,31 @@
 #include <dragonfly_lib.h>
+#include "spi.h"
 
+#define MODE 1
 
-void a1()
-{
-	usb_puts("a\n");
+void recv_func(char c) {
+	usb_puts("Received: ");
+	usb_putc(c);
+	usb_puts("\r\n");
+	return;
 }
 
-void a2()
-{
-	usb_puts("b\n");
-}
 
-void a3()
-{
-	usb_puts("c\n");
-}
 
-void a4()
-{
-	usb_puts("4\n");
-}
-
-void a5()
-{
-	usb_puts("5\n");
-}
-
-void a6()
-{
-	usb_puts("6\n");
-}
-
-void a7()
-{
-	usb_puts("7\n");
-}
-
-void a8()
-{
-	usb_puts("8\n");
-}
-
-void a9()
-{
-	usb_puts("9\n");
-}
-
-void a10()
-{
-	usb_puts("A");
-}
-
 int main(void)
 {
 	dragonfly_init(ALL_ON);
-	void (*functions[])(void) = {a1};
-	void (*allF[])(void) = {a1,a2,a3,a4,a5,a6,a7,a8,a9,a10};
-	int test[] = {20};
+	spi_init(MODE, recv_func);
+	usb_puts("Init done\r\n");
+	while(1) {
+	//usb_puts("loop\r\n");
+		if (MODE) {
 	
-	rtc_multi_init(test, functions, 1);
-	
-	while(1){
-		if(button1_click() == 1)
-		{
-			int time = rtc_get_function_count();
-			usb_puts("number of functions: ");
-			usb_puti(rtc_add_function(allF[time], time*10));
-			usb_puts("\n");
+				spi_send("b", 1);
+				delay_ms(1000);
 		}
-		if(button2_click() == 1)
-		{
-			int time = rtc_get_function_count();
-			if(time > 0)
-			{
-				usb_puts("number of functions: ");
-				usb_puti(rtc_remove_function(allF[time-1]));
-				usb_puts("\n");
-			}
-		}
-	};
+		
+	}
 	
 	return 0;
 	
Index: branches/encoders/code/projects/template/Makefile
===================================================================
--- branches/encoders/code/projects/template/Makefile	(revision 366)
+++ branches/encoders/code/projects/template/Makefile	(revision 367)
@@ -116,11 +116,8 @@
 endif
 
 # Place -I, -L options here
-CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly 
-CINCS += -L$(COLONYROOT)/code/lib/bin
-ifdef USE_WIRELESS
-	CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
-endif
+CINCS = -I../libdragonfly 
+CINCS += -L../libdragonfly
 
 #---------------- Compiler Options ----------------
 #  -g*:          generate debugging information
Index: branches/encoders/code/projects/libdragonfly/dragonfly_lib.h
===================================================================
--- branches/encoders/code/projects/libdragonfly/dragonfly_lib.h	(revision 366)
+++ branches/encoders/code/projects/libdragonfly/dragonfly_lib.h	(revision 367)
@@ -65,6 +65,7 @@
 #include <bom.h>
 #include <move.h>
 #include <reset.h>
+//#include "spi.h"
 #include <math.h>
 
 #endif
Index: branches/encoders/code/projects/libdragonfly/spi.c
===================================================================
--- branches/encoders/code/projects/libdragonfly/spi.c	(revision 366)
+++ branches/encoders/code/projects/libdragonfly/spi.c	(revision 367)
@@ -27,19 +27,22 @@
 
 RING_BUFFER_NEW(spi_buffer, 16, char, spi_send_buff, spi_rec_buff);
 volatile char spi_status;
+char spi_mode;
 static spi_fun_recv_t  spi_recv_function;
-static spi_fun_send_t  spi_send_function;
+//static spi_fun_send_t  spi_send_function;
 
 
-int spi_init(char mode, spi_fun_send_t send_func, spi_fun_recv_t recv_func) {
+void spi_init(char mode, spi_fun_recv_t recv_func) {
     usb_puts("spi_init: start\n");
 
+	spi_mode = mode;
+
 	//cli();
 	RING_BUFFER_CLEAR(spi_send_buff);
 	RING_BUFFER_CLEAR(spi_rec_buff);
 
 	spi_recv_function = recv_func;
-	spi_send_function = send_func;
+	//spi_send_function = send_func;
 
     /* Enables the SPI module
      * Enable Interrupt, Enable SPI Module, LSB First, Master Mode, Clock div = 64
@@ -55,6 +58,7 @@
 	if(mode == MASTER) {
 	    DDRB |= MOSI | SCLK | SS;
 	    DDRB &= ~MISO;
+		PORTB |= SS;	//Keep SS High until transmit
 	/* Set SCLK, SS, MOSI as inputs. MISO as output */
 	} else {
 	    DDRB &= ~MOSI & ~SCLK & ~SS;
@@ -89,34 +93,52 @@
     sei();
     
     spi_status = SPI_SENDING;
+	
+	if (spi_mode == MASTER ){
+		PORTB &= ~SS;	//Select slave
+	}
     SPDR = *data;
 	
 	usb_puts("spi_send: end\n");
 	//sei();
+	
+	return 1;
 }
 
+void spi_master_recv_on() {
+	spi_status = SPI_VOID;
+	PORTB &= ~SS;
+}
+
+void spi_master_recv_off() {
+	spi_status = SPI_VOID;
+	PORTB |= SS;
+}
+
 ISR(SIG_SPI) {
     usb_puts("ISR: start\n\r");
-	char c = SPDR;
+	char c;
 
-	usb_putc('['); usb_puti(c);usb_putc(',');usb_puti(spi_status);usb_puts("]\n\r");
+	//usb_putc('['); usb_puti(c);usb_putc(',');usb_puti(spi_status);usb_puts("]\n\r");
 	switch(spi_status){
 		case SPI_SENDING:
 			if(!RING_BUFFER_EMPTY(spi_send_buff)) {
 				RING_BUFFER_REMOVE(spi_send_buff, c);
-				usb_puts("SPDR=["); usb_puti(c);usb_putc(',');usb_puti(spi_status);usb_puts("]\n\r");
+				//usb_puts("SPDR=["); usb_puti(c);usb_putc(',');usb_puti(spi_status);usb_puts("]\n\r");
 				SPDR = c;
-				c = SPDR;
-				usb_puts("c=["); usb_puti(c);usb_putc(',');usb_puti(spi_status);usb_puts("]\n");
+				//c = SPDR;
+				//usb_puts("c=["); usb_puti(c);usb_putc(',');usb_puti(spi_status);usb_puts("]\n");
 				
 			} else {
+				if (spi_mode == MASTER)
+					PORTB |= SS;		//Turn off Slave select
 				spi_status = SPI_VOID;
 			}
 			break;
 		case SPI_VOID:
-			spi_recv_function(c);
+			spi_recv_function(SPDR);
 			break;
 	}
-		SPSR ^= (1 << SPIF);
+
 	usb_puts("ISR: end\n");
 }		
Index: branches/encoders/code/projects/libdragonfly/spi.h
===================================================================
--- branches/encoders/code/projects/libdragonfly/spi.h	(revision 366)
+++ branches/encoders/code/projects/libdragonfly/spi.h	(revision 367)
@@ -6,6 +6,7 @@
 #define SLAVE 0
 #define SPI_SENDING 1
 #define SPI_VOID 0
+#define SPI_MASTER_RECV 2
 
 /* Pin Defines */
 #define MOSI _BV(PB2)
@@ -16,6 +17,7 @@
 #define size_t int
 typedef void (*spi_fun_recv_t)(char);
 typedef void (*spi_fun_send_t)(char);
-int spi_init(char mode, spi_fun_send_t send_func, spi_fun_recv_t recv_func);
+void spi_init(char mode, spi_fun_recv_t recv_func);
 int spi_send(char *data, size_t bytes);
-
+void spi_master_recv_on(void);
+void spi_master_recv_off(void);
