Project

General

Profile

Revision 565

Added by Kevin Woo over 14 years ago

More testing. Transmission is messed up.

View differences:

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