Revision 1562
updated baud rate code (it works for 9600 and 115200 now, haven't tested the others)
branches/wireless/code/behaviors/Wireless_Speed_test/xbee.c | ||
---|---|---|
293 | 293 |
WL_DEBUG_PRINT("Entered command mode.\r\n"); |
294 | 294 |
|
295 | 295 |
// reset baud rate |
296 |
usb_puts("Resetting Baud to ");
|
|
297 |
usb_puts(XBEE_BAUD_STR);
|
|
298 |
usb_puts("\r\n");
|
|
296 |
WL_DEBUG_PRINT("Resetting Baud to ");
|
|
297 |
WL_DEBUG_PRINT(XBEE_BAUD_STR);
|
|
298 |
WL_DEBUG_PRINT("\r\n");
|
|
299 | 299 |
|
300 | 300 |
// set baud on xbee |
301 |
//#if (XBEE_BAUD == 250000) |
|
301 | 302 |
#if (XBEE_BAUD == 115200) |
302 |
xbee_send_string("ATBD7\r"); |
|
303 |
#end if |
|
303 |
xbee_send_string("ATBD7\r\n"); |
|
304 |
#elif (XBEE_BAUD == 57600) |
|
305 |
xbee_send_string("ATBD6\r\n"); |
|
306 |
#elif (XBEE_BAUD == 38400) |
|
307 |
xbee_send_string("ATBD5\r\n"); |
|
308 |
#elif (XBEE_BAUD == 19200) |
|
309 |
xbee_send_string("ATBD4\r\n"); |
|
310 |
#elif (XBEE_BAUD == 9600) |
|
311 |
// already at this baud rate |
|
312 |
//xbee_send_string("ATBD3\r\n"); |
|
313 |
#else |
|
314 |
WL_DEBUG_PRINT("undefined baud rate\r\n"); |
|
315 |
#endif |
|
304 | 316 |
// exit command mode |
305 | 317 |
xbee_wait_for_ok(); |
306 |
xbee_send_string("ATCN\r"); |
|
318 |
WL_DEBUG_PRINT("got ok from baud reset\r\n"); |
|
319 |
xbee_send_string("ATCN\r\n"); |
|
307 | 320 |
xbee_wait_for_ok(); |
321 |
WL_DEBUG_PRINT("got ok from exiting command mode\r\n"); |
|
308 | 322 |
|
309 | 323 |
// set UART baud |
310 | 324 |
#if (XBEE_BAUD == 250000) |
... | ... | |
316 | 330 |
UBRR1L = 8; |
317 | 331 |
UCSR1A |= _BV(U2X1); |
318 | 332 |
#elif (XBEE_BAUD == 57600) |
319 |
if (xbee_send_modify_at_command("BD","6")) { |
|
320 |
return -1; |
|
321 |
} |
|
322 | 333 |
UBRR1H = 0x00; |
323 | 334 |
UBRR1L = 16; |
324 | 335 |
UCSR1A |= _BV(U2X1); |
325 | 336 |
#elif (XBEE_BAUD == 38400) |
326 |
if (xbee_send_modify_at_command("BD","5")) { |
|
327 |
return -1; |
|
328 |
} |
|
329 | 337 |
UBRR1H = 0x00; |
330 | 338 |
UBRR1L = 25; |
331 | 339 |
UCSR1A |= _BV(U2X1); |
332 | 340 |
#elif (XBEE_BAUD == 19200) |
333 |
if (xbee_send_modify_at_command("BD","4")) { |
|
334 |
return -1; |
|
335 |
} |
|
336 | 341 |
UBRR1H = 0x00; |
337 | 342 |
UBRR1L = 51; |
338 | 343 |
UCSR1A |= _BV(U2X1); |
339 | 344 |
#elif (XBEE_BAUD == 9600) |
340 | 345 |
/* this is the default baud rate, so do nothing |
341 |
if (xbee_send_modify_at_command("BD","3")) { |
|
342 |
return -1; |
|
343 |
} |
|
344 | 346 |
UBRR1H = 0x00; |
345 | 347 |
UBRR1L = 103; |
346 | 348 |
UCSR1A |= _BV(U2X1);*/ |
347 | 349 |
#else //Baud rate is defined in the header file, we should not get here |
348 | 350 |
return 0; |
349 | 351 |
#endif |
352 |
delay_ms(50); |
|
350 | 353 |
|
351 | 354 |
// enter command mode |
352 |
if (xbee_enter_command_mode() != 0) {
|
|
353 |
usb_puts("error entering command mode after baud set\r\n");
|
|
354 |
return -1;
|
|
355 |
}
|
|
355 |
WL_DEBUG_PRINT("entering command mode 2\r\n");
|
|
356 |
xbee_send_string("+++");
|
|
357 |
xbee_wait_for_ok();
|
|
358 |
WL_DEBUG_PRINT("entered command mode 2\r\n");
|
|
356 | 359 |
|
357 | 360 |
if (xbee_enter_api_mode() != 0) { |
358 |
usb_puts("can't enter api mode\r\n");
|
|
361 |
WL_DEBUG_PRINT("can't enter api mode\r\n");
|
|
359 | 362 |
return -1; |
360 | 363 |
} |
361 | 364 |
|
362 | 365 |
WL_DEBUG_PRINT("Entered api mode.\r\n"); |
363 | 366 |
|
364 | 367 |
if (xbee_exit_command_mode() != 0) { |
365 |
usb_puts("can't exit command mode\r\n");
|
|
368 |
WL_DEBUG_PRINT("can't exit command mode\r\n");
|
|
366 | 369 |
return -1; |
367 | 370 |
} |
368 | 371 |
|
... | ... | |
370 | 373 |
|
371 | 374 |
// get MY address |
372 | 375 |
if (xbee_send_read_at_command("BD")) { |
373 |
usb_puts("can't send BD command\r\n");
|
|
376 |
WL_DEBUG_PRINT("can't send BD command\r\n");
|
|
374 | 377 |
return -1; |
375 | 378 |
} |
376 | 379 |
WL_DEBUG_PRINT("Getting ATBD rate.\n"); |
377 | 380 |
|
378 | 381 |
// get MY address |
379 | 382 |
if (xbee_send_read_at_command("MY")) { |
380 |
usb_puts("can't send my command\r\n");
|
|
383 |
WL_DEBUG_PRINT("can't send my command\r\n");
|
|
381 | 384 |
return -1; |
382 | 385 |
} |
383 | 386 |
WL_DEBUG_PRINT("Getting ATMY address.\n"); |
... | ... | |
579 | 582 |
if (buffer_first == XBEE_BUFFER_SIZE) { |
580 | 583 |
buffer_first = 0; |
581 | 584 |
} |
582 |
WL_DEBUG_PRINT("buffer char:");
|
|
583 |
WL_DEBUG_PRINT(c); |
|
584 |
WL_DEBUG_PRINT("\r\n"); |
|
585 |
WL_DEBUG_PRINT("buffer char|");
|
|
586 |
WL_DEBUG_PRINT_CHAR(c);
|
|
587 |
WL_DEBUG_PRINT("|\r\n");
|
|
585 | 588 |
|
586 | 589 |
if (c == *curr) { |
587 | 590 |
curr++; |
branches/wireless/code/behaviors/Wireless_Speed_test/serial.h | ||
---|---|---|
126 | 126 |
// if no baud rate is defined for xbee, default is set here |
127 | 127 |
#ifndef XBEE_BAUD |
128 | 128 |
/** @brief the XBee baud rate **/ |
129 |
#define XBEE_BAUD 9600 |
|
129 |
//#define XBEE_BAUD 9600
|
|
130 | 130 |
//#define XBEE_BAUD_STR "9600" |
131 |
//#define XBEE_BAUD 115200
|
|
131 |
#define XBEE_BAUD 115200 |
|
132 | 132 |
#define XBEE_BAUD_STR "115200" |
133 | 133 |
#endif |
134 | 134 |
|
branches/wireless/code/behaviors/Wireless_Speed_test/wl_defs.h | ||
---|---|---|
40 | 40 |
#define ROBOT |
41 | 41 |
|
42 | 42 |
//uncomment this line for debug information |
43 |
#define WL_DEBUG |
|
43 |
//#define WL_DEBUG
|
|
44 | 44 |
|
45 | 45 |
//return value definitions |
46 | 46 |
/** @brief Error code for init failure **/ |
... | ... | |
84 | 84 |
|
85 | 85 |
#ifdef ROBOT |
86 | 86 |
#define WL_DEBUG_PRINT( s ) usb_puts( s ) |
87 |
#define WL_DEBUG_PRINT_CHAR( c ) usb_putc( c ) |
|
88 |
#define WL_DEBUG_PRINT_INT( i ) usb_puti(i) |
|
87 | 89 |
#else |
88 | 90 |
#define WL_DEBUG_PRINT( s ) printf( s ) |
91 |
#define WL_DEBUG_PRINT_CHAR( c ) printf("%c", c) |
|
92 |
#define WL_DEBUG_PRINT_INT( i ) printf("%i", i) |
|
89 | 93 |
#endif |
90 | 94 |
|
91 | 95 |
#ifdef ROBOT |
92 |
#define WL_DEBUG_PRINT_INT( i ) usb_puti(i) |
|
93 | 96 |
#else |
94 |
#define WL_DEBUG_PRINT_INT( i ) printf("%i", i) |
|
95 | 97 |
#endif |
96 | 98 |
|
97 | 99 |
#else |
98 | 100 |
|
99 | 101 |
#define WL_DEBUG_PRINT( s ) |
102 |
#define WL_DEBUG_PRINT_CHAR( c ) |
|
100 | 103 |
#define WL_DEBUG_PRINT_INT( i ) |
101 | 104 |
|
102 | 105 |
#endif |
Also available in: Unified diff