Project

General

Profile

Revision 565

Added by Kevin Woo over 14 years ago

More testing. Transmission is messed up.

View differences:

branches/encoders/code/projects/template/main.c
2 2
#include "spi.h"
3 3

  
4 4
#define MODE 0
5
#define TEST 1
5
#define TEST 0
6

  
6 7
extern char spi_status;
7 8

  
8 9
void recv_func(char c) {
9
    if (c != '\n');
10
	if(MODE)
11
		usb_puts("MASTER");
12
	else
13
		usb_puts("SLAVE");
10
    if (c != '0') {
11
	    if(MODE)
12
		    usb_puts("MASTER");
13
	    else
14
		    usb_puts("SLAVE");
14 15
	
15
	usb_puts(": received [");usb_putc(c);usb_puts("]\n\r");
16
	    usb_puts(": received ["); 
17
	    usb_putc(c); 
18
	    usb_puts("]\n\r");
19
    }
20

  
16 21
	return;
17 22
}
18 23

  
......
22 27
{
23 28
	dragonfly_init(ALL_ON);
24 29
	spi_init(MODE, recv_func);
25
	usb_puts("Init done\n\r");
30
	usb_puts("Init done.\n\r");
31
/*
32
    if (TEST) {
33
        if (MODE) {
34
            while (1) {
35
                spi_read(6);
36
                delay_ms(1000);	
37
            }
38
        } else {
39
            spi_send("SLAVE", 5);
40
        }
41
        
42
    
43
    }
44

  
45
    while(1);
46
*/
47

  
26 48
	while(1) {
27 49
		if(TEST){
28 50
			if(MODE){
......
30 52
				delay_ms(1000);
31 53
			} else {
32 54
				//if(!(spi_status & SPI_SEND))
33
				spi_send("SLAVE ",6);
34
				//delay_ms(800);
55
				spi_send("SLAVE", 5);
56
				
57
				
35 58
			}
36 59
		} else {
37 60
			if (MODE) {
......
40 63
		}
41 64
		
42 65
	}
43
	
66
//	*/
44 67
	return 0;
45 68
	
46 69
}
branches/encoders/code/projects/template/Makefile
115 115
endif
116 116

  
117 117
# Place -I, -L options here
118
CINCS = -I../libdragonfly 
119
CINCS += -L../libdragonfly
120

  
118
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
119
CINCS += -L$(COLONYROOT)/code/lib/bin
120
ifdef USE_WIRELESS
121
	CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
122
endif
121 123
#---------------- Compiler Options ----------------
122 124
#  -g*:          generate debugging information
123 125
#  -O*:          optimization level
......
195 197
LDFLAGS += -ldragonfly
196 198

  
197 199

  
198

  
199 200
#---------------- Programming Options (avrdude) ----------------
200 201

  
201 202
# Programming hardware: alf avr910 avrisp bascom bsd 
branches/encoders/code/projects/libdragonfly/spi.c
47 47
     * Enable Interrupt, Enable SPI Module, LSB First, Master Mode, Clock div = 64
48 48
     */
49 49
    SPCR = 0x00;
50
	SPCR = _BV(SPIE) | _BV(SPE) | _BV(DORD) | _BV(MSTR)| _BV(SPR1) | _BV(SPR0);
50
    if (spi_mode == MASTER) {
51
    	SPCR = _BV(SPIE) | _BV(SPE) | _BV(DORD) | _BV(MSTR)| _BV(SPR1) | _BV(SPR0);
52
    } else {
53
    	SPCR = _BV(SPIE) | _BV(SPE) | _BV(DORD) | ~_BV(MSTR)| _BV(SPR1) | _BV(SPR0);
54
    }
55
            
51 56
    SPSR = 0x00;
52 57
	SPSR = _BV(SPI2X); 
53 58
	
54 59
	spi_status = SPI_IDLE;
55 60

  
56 61
    /* Set SCLK, SS, MOSI as outputs. MISO as input */
57
	if(mode == MASTER) {
62
	if(spi_mode == MASTER) {
58 63
	    DDRB |= MOSI | SCLK | SS;
59 64
	    DDRB &= ~MISO;
60 65
		PORTB |= SS;	//Keep SS High until transmit
......
65 70
    }
66 71
	
67 72
	//sei();
68
	usb_puts("spi_init: end\n");
73
	//usb_puts("spi_init: end\n");
69 74
}
70 75

  
71 76
int spi_send(char *data, int bytes) {
......
96 101
	}
97 102
	
98 103
    SPDR = *data;
99
    
104
    /*
100 105
	if(spi_mode)
101 106
		usb_puts("MASTER");
102 107
	else
103 108
		usb_puts("SLAVE");
104 109
		
105 110
	usb_puts(": sending [");usb_putc(*data);usb_puts("]\n\r");
106
	
111
	*/
107 112
	//sei();
108 113
	
109 114
	return 1;
......
119 124
	        return;
120 125
	    }
121 126
	
122
	    RING_BUFFER_ADD(spi_send_buff, '\n');
127
	    RING_BUFFER_ADD(spi_send_buff, '0');
123 128
    }
124 129
    
125 130
    sei();
......
130 135
		PORTB &= ~SS;	//Select slave
131 136
	}
132 137
	
133
    SPDR = '\n';
138
    SPDR = '0';
134 139

  
135 140
}
136 141

  
......
153 158
	//If we're the master and we're done sending, end the transmission
154 159
	} else if (spi_mode == MASTER) {
155 160
	    PORTB |= SS;
161
	} else if (spi_mode == SLAVE) {
162
	    SPDR = '0';
156 163
	}
157 164
	
158 165

  

Also available in: Unified diff