root / branches / encoders / code / projects / template / main.c @ 546
History | View | Annotate | Download (633 Bytes)
1 | 16 | bcoltin | #include <dragonfly_lib.h> |
---|---|---|---|
2 | 367 | kwoo | #include "spi.h" |
3 | 16 | bcoltin | |
4 | 446 | bpoole | #define MODE 0 |
5 | 490 | bpoole | #define TEST 1 |
6 | extern char spi_status; |
||
7 | 257 | ayeager | |
8 | 367 | kwoo | void recv_func(char c) { |
9 | 546 | kwoo | if (c != '\n'); |
10 | 490 | bpoole | if(MODE)
|
11 | usb_puts("MASTER");
|
||
12 | else
|
||
13 | usb_puts("SLAVE");
|
||
14 | 546 | kwoo | |
15 | 490 | bpoole | usb_puts(": received [");usb_putc(c);usb_puts("]\n\r"); |
16 | 367 | kwoo | return;
|
17 | 193 | ayeager | } |
18 | |||
19 | |||
20 | |||
21 | 16 | bcoltin | int main(void) |
22 | { |
||
23 | dragonfly_init(ALL_ON); |
||
24 | 367 | kwoo | spi_init(MODE, recv_func); |
25 | 490 | bpoole | usb_puts("Init done\n\r");
|
26 | 367 | kwoo | while(1) { |
27 | 490 | bpoole | if(TEST){
|
28 | if(MODE){
|
||
29 | 546 | kwoo | spi_read(6);
|
30 | 490 | bpoole | delay_ms(1000);
|
31 | } else {
|
||
32 | 546 | kwoo | //if(!(spi_status & SPI_SEND))
|
33 | spi_send("SLAVE ",6); |
||
34 | //delay_ms(800);
|
||
35 | 490 | bpoole | } |
36 | } else {
|
||
37 | if (MODE) {
|
||
38 | spi_send("MASTER",6); |
||
39 | } |
||
40 | 257 | ayeager | } |
41 | 367 | kwoo | |
42 | } |
||
43 | 257 | ayeager | |
44 | 16 | bcoltin | return 0; |
45 | 193 | ayeager | |
46 | 16 | bcoltin | } |