Revision 844
Added some debug statements which SHOULD BE REMOVED UPON MOVING TO TRUNK
spi.c | ||
---|---|---|
18 | 18 |
void spi_init (spi_fun_recv_t recv_func, spi_fun_recv_complete_t recv_complete_func) |
19 | 19 |
{ |
20 | 20 |
/* Enable Interrupt, Enable SPI Module, MSB First, Master Mode, Clock div = 64 */ |
21 |
SPCR = _BV(SPE) | _BV(SPIE) /*| _BV(DORD)*/ | _BV(MSTR) | _BV(SPR1) | _BV(SPR0); |
|
21 |
SPCR = _BV(SPE) | _BV(SPIE) /*| _BV(DORD)*/ | _BV(MSTR) | _BV(SPR1) | _BV(SPR0);
|
|
22 | 22 |
SPSR = _BV(SPI2X); |
23 | 23 |
|
24 | 24 |
/* Set SCLK, SS, MOSI as outputs. MISO as input */ |
... | ... | |
30 | 30 |
|
31 | 31 |
/* set function to be executed when we receive a byte */ |
32 | 32 |
spi_recv_func = recv_func; |
33 |
spi_recv_complete_func = recv_complete_func;
|
|
33 |
spi_recv_complete_func = recv_complete_func;
|
|
34 | 34 |
spi_bytes = 0; |
35 |
usb_puts("\tspi.c Debug: SPI INITIALIZED\n"); |
|
35 | 36 |
} |
36 | 37 |
|
37 | 38 |
/* Transfer a given byte to slave and receive a byte */ |
... | ... | |
48 | 49 |
/* only handle intterupt when we are expecting data */ |
49 | 50 |
if(spi_bytes > 0){ |
50 | 51 |
/* process byte */ |
51 |
spi_recv_func(SPDR);
|
|
52 |
spi_recv_func(SPDR);
|
|
52 | 53 |
/* if we've read all the bytes, set SS high to end transmission, |
53 | 54 |
* otherwise get the next byte */ |
54 | 55 |
if(--spi_bytes == 0){ |
55 | 56 |
//usb_puts("Read all bytes\r\n"); |
56 |
PORTB |= SS;
|
|
57 |
if(spi_recv_complete_func)
|
|
58 |
spi_recv_complete_func();
|
|
57 |
PORTB |= SS;
|
|
58 |
if(spi_recv_complete_func)
|
|
59 |
spi_recv_complete_func();
|
|
59 | 60 |
}else { |
60 | 61 |
//usb_puts("There are this many bytes left: "); usb_puti(spi_bytes);usb_puts("\r\n"); |
61 |
SPDR = 0xff;
|
|
62 |
}
|
|
62 |
SPDR = 0xff;
|
|
63 |
} |
|
63 | 64 |
} |
64 | 65 |
} |
Also available in: Unified diff