Project

General

Profile

Revision 495

Added by Kevin Woo about 16 years ago

Modified the spi module a bit. Didn't test it but this might be better.
Need to talk to Ben about it.

Started the encoders file. Nothing in there because I don't have a
stable SPI interface to work with yet.

View differences:

branches/encoders/code/projects/libdragonfly/spi.c
94 94
	if (spi_mode == MASTER ){
95 95
		PORTB &= ~SS;	//Select slave
96 96
	}
97
	
97 98
    SPDR = *data;
99
    
98 100
	if(spi_mode)
99 101
		usb_puts("MASTER");
100 102
	else
101 103
		usb_puts("SLAVE");
104
		
102 105
	usb_puts(": sending [");usb_putc(*data);usb_puts("]\n\r");
103 106
	
104 107
	//sei();
......
106 109
	return 1;
107 110
}
108 111

  
112
void spi_read(int bytes) {
113
    
114
    cli();
115
    for(i = 1; i < bytes; i++) {
116
        // Fail if the buffer is full
117
	    if(RING_BUFFER_FULL(spi_send_buff)) {
118
	        sei();
119
	        return -1;
120
	    }
121
	
122
	    RING_BUFFER_ADD(spi_send_buff, '\0');
123
    }
124
    
125
    sei();
126

  
127
    spi_status |= SPI_RECV;
128
	
129
	if (spi_mode == MASTER ){
130
		PORTB &= ~SS;	//Select slave
131
	}
132
	
133
    SPDR = *data;
134

  
135
}
136

  
109 137
void spi_read_one(void)
110 138
{
111 139
	PORTB &= ~SS;
......
114 142

  
115 143
ISR(SIG_SPI) {
116 144
	char c;
145
	
117 146
	if(!RING_BUFFER_EMPTY(spi_send_buff)) {//cheap way to test if SPI_SEND
118 147
		RING_BUFFER_REMOVE(spi_send_buff, c);
119 148
		SPDR = c;
149
		
120 150
		if(spi_mode)
121 151
			usb_puts("MASTER");
122 152
		else
123 153
			usb_puts("SLAVE");
154
			
124 155
		usb_puts(": sending [");usb_putc(c);usb_puts("]\n\r");
125
	} else if(spi_status & SPI_SEND) {
156
	
157
	//If we were sending and we are done end the transmission
158
	} else if(spi_status == SPI_SEND) {
126 159
		spi_status ^= SPI_SEND;
127 160
		PORTB |= SS; //Sleep slave
128
	} 
129
	if(spi_status & SPI_RECV){
161

  
162
    //End the transmission if we are not sending or recieving anymore
163
	} else if(spi_mode == MASTER) {
164
	    PORTB |= SS;
165
	}
166
	
167
	//Call the recv function whenver we recieve a byte
168
	if(spi_status == SPI_RECV){
130 169
		spi_recv_function(SPDR);
131
		if(spi_mode == MASTER)
132
			PORTB |= SS;
170
		//if(spi_mode == MASTER)
171
			//PORTB |= SS;
133 172
	}
134 173
}		
135 174

  
branches/encoders/code/projects/libdragonfly/encoders.c
1

  
2
//Dummy file for now.

Also available in: Unified diff