Revision 1638
wireless: fixed API mode 1. Can now enter and exit API mode properly. Can also set and read MY address.
test_xbee.c | ||
---|---|---|
10 | 10 |
* |
11 | 11 |
* |
12 | 12 |
*/ |
13 |
/* |
|
14 |
// test interrupt |
|
15 |
ISR(USART1_RX_vect) { |
|
16 |
WL_DEBUG_PRINT("in interrupt|"); |
|
17 |
char c = UDR1; |
|
18 |
WL_DEBUG_PRINT_HEX(c); |
|
19 |
WL_DEBUG_PRINT("|in interrupt"); |
|
20 |
}*/ |
|
21 |
|
|
22 |
//int8_t xbee_putc(uint8_t c) { |
|
23 | 13 |
|
24 |
// Wait until buffer is clear for sending |
|
25 |
// Then load buffer with your character |
|
26 |
|
|
27 |
|
|
28 |
/*#ifdef FIREFLY |
|
29 |
loop_until_bit_is_set(UCSR0A, UDRE0); |
|
30 |
UDR0 = c; |
|
31 |
#else*/ |
|
32 |
/* loop_until_bit_is_set(UCSR1A, UDRE1); |
|
33 |
UDR1 = c; |
|
34 |
//#endif |
|
35 |
WL_DEBUG_PRINT("xbee_putc:"); |
|
36 |
WL_DEBUG_PRINT_HEX(c); |
|
37 |
WL_DEBUG_PRINT("|\r\n"); |
|
38 |
|
|
39 |
return WL_SUCCESS; |
|
40 |
}*/ |
|
41 |
|
|
42 | 14 |
int testxbee(void) { |
43 | 15 |
|
44 | 16 |
unsigned char buf[100]; |
... | ... | |
47 | 19 |
usb_init(); |
48 | 20 |
usb_puts("usb turned on, test starting:\r\n"); |
49 | 21 |
|
50 |
/*UBRR1H = 0x00; // baud rate |
|
51 |
UBRR1L = 103; // baud rate |
|
52 |
UCSR1A |= (1<<U2X1); // double transmit speed |
|
53 |
//Enable receiver and transmitter on USART1 |
|
54 |
UCSR1B |= (1<<RXEN1)|(1<<TXEN1); |
|
55 |
|
|
56 |
// Set frame format: 8data, 1stop bit, asynchronous normal mode |
|
57 |
//UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11); |
|
58 |
|
|
59 |
//UCSR1C |= (1<<UMSEL1) | (1<<UCSZ10) | (1<<UCSZ11); |
|
60 |
//UCSR1C |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); |
|
61 |
UCSR1B |= (1<<RXCIE1); // enable receive, transmit (1<<RXCIE) |
|
62 |
WL_DEBUG_PRINT("receive interrupt flag="); |
|
63 |
WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1)); |
|
64 |
WL_DEBUG_PRINT("|\r\n"); |
|
65 |
sei(); |
|
66 |
|
|
67 |
|
|
68 |
xbee_putc('+'); |
|
69 |
xbee_putc('+'); |
|
70 |
xbee_putc('+');*/ |
|
71 |
|
|
72 | 22 |
int ret = xbee_init(); |
73 | 23 |
|
74 | 24 |
if (ret != WL_SUCCESS) { |
... | ... | |
80 | 30 |
usb_puts("xbee_init successful\r\n"); |
81 | 31 |
} |
82 | 32 |
|
83 |
|
|
84 | 33 |
usb_puts("\r\n\n"); |
85 | 34 |
delay_ms(1000); |
86 | 35 |
|
... | ... | |
96 | 45 |
WL_DEBUG_PRINT("|\r\ncharacter size2(00)="); |
97 | 46 |
WL_DEBUG_PRINT_HEX((UCSR1B&(1<<UCSZ12))|(0<<UCSZ12)); |
98 | 47 |
WL_DEBUG_PRINT("|\r\n"); |
99 |
|
|
100 |
|
|
48 |
|
|
101 | 49 |
// try getting xbee address |
102 |
/*xbee_send_read_at_command("MY"); |
|
103 |
while(i++ < 10000) { |
|
104 |
if(xbee_get_packet(buf) == 3) { |
|
105 |
usb_puts("got response from xbee\r\n"); |
|
106 |
//usb_puts("packet:"); |
|
107 |
//usb_puts(buf); |
|
108 |
//usb_puts("|end\r\n"); |
|
109 |
break; // got a response |
|
110 |
} |
|
111 |
}*/ |
|
50 |
uint16_t address = xbee_get_address(); |
|
51 |
if(address != WL_ERROR_XBEE_COMMAND_16BIT) { |
|
52 |
usb_puts("MY address:"); |
|
53 |
usb_puth8((uint8_t)(address>>8)); |
|
54 |
usb_puth8((uint8_t)(address&0xFF)); |
|
55 |
usb_puts("\r\n"); |
|
56 |
} else { |
|
57 |
usb_puts("error getting MY address\r\n"); |
|
58 |
} |
|
112 | 59 |
|
113 | 60 |
// try setting channel |
114 | 61 |
/*xbee_set_channel(0x0F); |
... | ... | |
158 | 105 |
}*/ |
159 | 106 |
|
160 | 107 |
// end of tests |
161 |
/*if (xbee_terminate() != 0) {
|
|
108 |
if (xbee_terminate() != 0) { |
|
162 | 109 |
usb_puts("xbee_terminate error\r\n"); |
163 | 110 |
} else { |
164 | 111 |
usb_puts("xbee_terminate success\r\n"); |
165 |
}*/
|
|
112 |
} |
|
166 | 113 |
usb_puts("testxbee done\r\n\r\n"); |
167 | 114 |
|
168 | 115 |
return 0; |
Also available in: Unified diff