Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / projects / unit_tests / test_xbee.c @ 1625

History | View | Annotate | Download (3.77 KB)

1
#include <dragonfly_lib.h>
2
#include <wl_defs.h>
3
#include "xbee.h"
4

    
5
#define ROBOT
6
#define WL_DEBUG
7

    
8
/*
9
 * This function tests the xbee, returning the results to teraterm
10
 *
11
 * 
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

    
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
int testxbee(void) {
43

    
44
  unsigned char buf[100];
45
  int i=0;
46
        
47
        usb_init();
48
        usb_puts("usb turned on, test starting:\r\n");
49
  
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
  int ret = xbee_init();
73
  
74
  if (ret != WL_SUCCESS) {
75
    usb_puts("xbee_init() failed\r\n");
76
    usb_puti(ret);
77
    usb_puts("|\r\n");
78
    return -1;
79
  } else {
80
    usb_puts("xbee_init successful\r\n");
81
  }
82
  
83
 
84
        usb_puts("\r\n\n");
85
        delay_ms(1000);
86
  
87
  // check registers
88
  WL_DEBUG_PRINT("receive interrupt flag(80)=");
89
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1));
90
  WL_DEBUG_PRINT("|\r\nreceive flag(10)=");
91
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXEN1));
92
  WL_DEBUG_PRINT("|\r\ntransmit flag(08)=");
93
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<TXEN1));
94
  WL_DEBUG_PRINT("|\r\ncharacter size(06)=");
95
  WL_DEBUG_PRINT_HEX(UCSR1C&((1<<UCSZ10)|(1<<UCSZ11)));
96
  WL_DEBUG_PRINT("|\r\ncharacter size2(00)=");
97
  WL_DEBUG_PRINT_HEX((UCSR1B&(1<<UCSZ12))|(0<<UCSZ12));
98
  WL_DEBUG_PRINT("|\r\n");
99
    
100
        
101
        // 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
  }*/
112
  
113
  // try setting channel
114
  /*xbee_set_channel(0x0F);
115
  while(i++ < 10000) {
116
    if(xbee_get_packet(buf) == 3) {
117
      usb_puts("got response from xbee\r\n");
118
      break; // got a response
119
    }
120
  }
121
  
122
  xbee_send_read_at_command("CH");
123
  while(i++ < 10000) {
124
    if(xbee_get_packet(buf) == 3) {
125
      usb_puts("got response from xbee\r\n");
126
      break; // got a response
127
    }
128
  }
129
  
130
  usb_puts("\r\nxbee set channel works\r\n\r\n");
131
  
132
  wl_set_channel(0x16);
133
  while(i++ < 10000) {
134
    if(xbee_get_packet(buf) == 3) {
135
      usb_puts("got response from xbee\r\n");
136
      break; // got a response
137
    }
138
  }
139
  
140
  xbee_send_read_at_command("CH");
141
  while(i++ < 10000) {
142
    if(xbee_get_packet(buf) == 3) {
143
      usb_puts("got response from xbee\r\n");
144
      break; // got a response
145
    }
146
  }  
147
  
148
  usb_puts("\r\nwireless set channel works\r\n");*/
149
  
150
  // scan all xbees in network
151
  /*xbee_send_read_at_command("ND");
152
  i=0;
153
  while(i < 1000) {
154
    if(xbee_get_packet(buf) == 3) {
155
      usb_puts("got response from xbee\r\n");
156
      i++;
157
    }
158
  }*/
159
  
160
  // end of tests
161
  /*if (xbee_terminate() != 0) {
162
    usb_puts("xbee_terminate error\r\n");
163
  } else {
164
    usb_puts("xbee_terminate success\r\n");
165
  }*/
166
  usb_puts("testxbee done\r\n\r\n");
167
    
168
        return 0;
169
}