Project

General

Profile

Revision 1625

Got xbee interrupt to work in command mode (API mode 0 off)
Still working on API mode 1 ON

View differences:

branches/wireless/code/projects/unit_tests/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
}*/
13 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
}*/
14 41
 
15 42
int testxbee(void) {
16 43

  
......
20 47
	usb_init();
21 48
	usb_puts("usb turned on, test starting:\r\n");
22 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
 
23 72
  int ret = xbee_init();
24 73
  
25 74
  if (ret != WL_SUCCESS) {
......
30 79
  } else {
31 80
    usb_puts("xbee_init successful\r\n");
32 81
  }
82
  
33 83
 
34 84
	usb_puts("\r\n\n");
35 85
	delay_ms(1000);
......
108 158
  }*/
109 159
  
110 160
  // end of tests
111
  if (xbee_terminate() != 0) {
161
  /*if (xbee_terminate() != 0) {
112 162
    usb_puts("xbee_terminate error\r\n");
113 163
  } else {
114 164
    usb_puts("xbee_terminate success\r\n");
115
  }
165
  }*/
116 166
  usb_puts("testxbee done\r\n\r\n");
117 167
    
118 168
	return 0;
branches/wireless/code/projects/unit_tests/xbee.c
34 34
#include <lights.h>
35 35

  
36 36
#include <string.h>
37
#include <avr/io.h>
37 38
#include <avr/interrupt.h>
38 39
#include <time.h>
39 40
#include <wl_defs.h>
......
57 58
/* API Mode Functions */
58 59
//TODO: does this exist?  static int8_t xbee_handle_packet(uint8_t* packet, uint16_t len);
59 60
static int8_t xbee_handle_at_command_response(uint16_t command, uint8_t result, uint8_t len);
60
static int8_t xbee_handle_at_command_response(uint16_t command, uint8_t result, uint8_t len);
61 61
static void xbee_handle_status(uint8_t status);
62 62
static int8_t xbee_verify_checksum(uint8_t* packet, uint16_t len);
63 63
static uint8_t xbee_compute_checksum(uint8_t* packet, uint16_t len);
......
142 142
//#ifndef FIREFLY
143 143
#define PORT UDR1
144 144
#define FLAG RXC1
145
ISR(USART1_RX_vect)
145
ISR(USART1_RX_vect) {
146 146
//#else
147 147
//#define PORT UDR0
148 148
//#define FLAG RXC0
149 149
//SIGNAL(SIG_USART0_RECV)
150 150
//#endif
151
{
151
  step=0;
152 152
  // start of frame
153 153
  uint8_t apitype = PORT; // get frame start byte
154 154
  uint16_t i=0;
......
167 167
    step=1;
168 168
    if (getStatus(XBEE_COMMAND_MASK) == XBEE_COMMAND_WAIT) {
169 169
      // get rest of command and put in basic buf
170
      xbee_basic_buf[0] = apitype;
171
      if (xbee_basic_buf[i] != '\r') {
170
      xbee_basic_buf[i] = apitype;
171
      if (xbee_basic_buf[i++] != '\r') {
172 172
        while(i < PACKET_BUFFER_SIZE) {
173 173
          if (FLAG) {
174 174
            xbee_basic_buf[i] = PORT;
175 175
            if (xbee_basic_buf[i] == '\r')
176 176
              break;
177 177
          }
178
          i++;
178 179
        }
179 180
      }
180
      WL_DEBUG_PRINT("got packet=");
181
      WL_DEBUG_PRINT("got packet, len=");
182
      WL_DEBUG_PRINT_INT(i);
183
      WL_DEBUG_PRINT("str=");
181 184
      WL_DEBUG_PRINT(xbee_basic_buf);
182 185
      step=2;
183 186
      // signal handler that command response is done
......
400 403
inline void setStatus(uint8_t mask,uint8_t value) { xbee_status = (xbee_status&(!mask))|value; }
401 404

  
402 405

  
406
// test interrupt
407
/*ISR(USART1_RX_vect) {
408
  WL_DEBUG_PRINT("in interrupt|");
409
  char c = UDR1;
410
  WL_DEBUG_PRINT_HEX(c);
411
  WL_DEBUG_PRINT("|in interrupt");
412
}*/
413

  
414

  
415

  
403 416
/**
404 417
 * Initializes the XBee library so that other functions may be used.
405 418
 **/
......
426 439
  UCSR0B |= (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE); 
427 440
#else*/
428 441
  // Bayboard or robot
429
  UCSR1A |= (1<<U2X1); // double transmit speed 
442
  
430 443
  UBRR1H = 0x00; // baud rate
431 444
  UBRR1L = 103;  // baud rate
432
  UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
433
  UCSR1B |= (1<<RXEN1) | (1<<TXEN1);
434
  UCSR1B |= _BV(RXCIE);  // enable receive, transmit (1<<RXCIE)
445
  UCSR1A |= (1<<U2X1); // double transmit speed 
446
  //Enable receiver and transmitter on USART1
447
  UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
448
	
449
  // Set frame format: 8data, 1stop bit, asynchronous normal mode
450
  //UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
451
  
452
  //UCSR1C |= (1<<UMSEL1) | (1<<UCSZ10) | (1<<UCSZ11);   
453
  //UCSR1C |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
454
  UCSR1B |= (1<<RXCIE1);  // enable receive, transmit (1<<RXCIE)
435 455
  WL_DEBUG_PRINT("receive interrupt flag=");
436
  WL_DEBUG_PRINT_HEX(UCSR1B&(_BV(RXCIE)));
456
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1));
437 457
  WL_DEBUG_PRINT("|\r\n");
438
//#endif
439 458
  sei();
459
 
460
  /*xbee_putc('+');
461
  xbee_putc('+');
462
  xbee_putc('+');
463
  delay_ms(1000);*/
440 464
  
441 465
  
442
//#ifdef ROBOT
443
  // enable basic xbee serial communications
444
 // xbee_init();
445
 
446
/* #if (XBEE_BAUD == 115200)
447
  UBRR1H = 0x00;
448
  UBRR1L = 8;
449
  UCSR1A |= _BV(U2X1); // set bit 1
450
#elif (XBEE_BAUD == 9600)
451
  UBRR1H = 0x00;
452
  UBRR1L = 103;
453
  UCSR1A |= _BV(U2X1);
454
#else //Baud rate is defined in the header file, we should not get here
455
  return;
456
#endif
466
  WL_DEBUG_PRINT("entering command mode\r\n");
467
  xbee_send_string((uint8_t*)"+++");
468
  xbee_wait_for_ok();
469
  WL_DEBUG_PRINT("entered command mode\r\n");
457 470

  
458
  //Enable receiver and transmitter on USART1
459
  UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
460
	
461
  // Set frame format: 8data, 1stop bit, asynchronous normal mode
462
  UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
463

  
464
	// enable the receiving interrupt for USART1
465
#ifdef FIREFLY
466
	UCSR0B |= _BV(RXCIE) | _BV(RXEN);
467
#else
468
#ifdef BAYBOARD
469
	UCSR1B |= _BV(RXCIE1);
470
#else
471
  // dragonfly register 
472
	UCSR1B |= _BV(RXCIE);
473
#endif
474
#endif
475
	sei();
476
//#else*/
477

  
478
  WL_DEBUG_PRINT("Entering command mode.\r\n");
479
  if (xbee_enter_command_mode() != 0) {
480
    WL_DEBUG_PRINT("error entering command mode\r\n");
481
    return -1;
482
  }
483
  WL_DEBUG_PRINT("\r\n***************UDR0=|");
484
  WL_DEBUG_PRINT(UDR0);
485
  WL_DEBUG_PRINT("|Entered command mode.\r\n");
486

  
487 471
  
488 472
  // set baud on xbee
489 473
#if (XBEE_BAUD == 115200)
490 474
  xbee_send_string((uint8_t*)"ATBD7\r");
491
  xbee_send_string((uint8_t*)"ATBD7\r");
492 475
#elif (XBEE_BAUD == 57600)
493 476
  xbee_send_string((uint8_t*)"ATBD6\r");
494 477
#elif (XBEE_BAUD == 38400)
......
497 480
  xbee_send_string((uint8_t*)"ATBD4\r");
498 481
#elif (XBEE_BAUD == 9600)
499 482
  // already at this baud rate
500
  //xbee_send_string("ATBD3\r\n");
483
  xbee_send_string("ATBD3\r\n");
501 484
#else
502 485
  WL_DEBUG_PRINT("undefined baud rate\r\n");
503 486
  return WL_ERROR_BAUD;
......
553 536
  return WL_ERROR_BUAD;
554 537
#endif
555 538
#endif
556
  delay_ms(50);
539
  delay_ms(1000);
557 540

  
558 541
  // enter command mode
559 542
  WL_DEBUG_PRINT("entering command mode 2\r\n");
......
565 548
    WL_DEBUG_PRINT("can't enter api mode\r\n");
566 549
    return -1;
567 550
  }
551
  
552
  
568 553

  
569 554
  WL_DEBUG_PRINT("Entered api mode.\r\n");
570 555

  
......
572 557
    WL_DEBUG_PRINT("can't exit command mode\r\n");
573 558
    return -1;
574 559
  }
560
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_NONE); // clear status
575 561
  
576 562
  WL_DEBUG_PRINT("Left command mode.\r\n");
577 563
  
......
615 601
  // Wait until buffer is clear for sending
616 602
  // Then load buffer with your character
617 603
  
604
  WL_DEBUG_PRINT("xbee_putc:");
605
  WL_DEBUG_PRINT_HEX(c);
606
  WL_DEBUG_PRINT("|\r\n");
618 607
  
619
#ifdef FIREFLY
608
/*#ifdef FIREFLY
620 609
  loop_until_bit_is_set(UCSR0A, UDRE0);  
621 610
  UDR0 = c;
622
#else
611
#else*/
623 612
  loop_until_bit_is_set(UCSR1A, UDRE1);
613
  WL_DEBUG_PRINT_HEX(UCSR1A&TXC1);
624 614
  UDR1 = c;
625
#endif
626
  WL_DEBUG_PRINT("xbee_putc:");
627
  WL_DEBUG_PRINT_HEX(c);
628
  WL_DEBUG_PRINT("|\r\n");
615
//#endif
629 616
  
630 617
  return WL_SUCCESS;
631 618
}
......
822 809
 **/
823 810
static int8_t xbee_wait_for_string(uint8_t* s, uint16_t len)
824 811
{
825
  uint8_t i=0;
812
  uint8_t i=0;  
813
  setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_WAIT); // set status flag
826 814
  if (getStatus(XBEE_API_MASK) == XBEE_API_OFF) {
827 815
    // wait until the response is received (only wait 1 second)
828 816
    while(getStatus(XBEE_COMMAND_MASK) != XBEE_COMMAND_RESPONSE && i++ < 1000) {
......
840 828
    setStatus(XBEE_COMMAND_MASK,XBEE_COMMAND_NONE); // clear status
841 829
  }
842 830
  
843
  WL_DEBUG_PRINT("done waiting for string. interrupt status=");
831
  WL_DEBUG_PRINT("|\r\ndone waiting for string. interrupt status=");
844 832
  WL_DEBUG_PRINT_INT(step);
845 833
  WL_DEBUG_PRINT("\r\n");
846 834

  
branches/wireless/code/projects/unit_tests/test_inits.c
7 7

  
8 8
  usb_puts("usb\n");
9 9

  
10
  if(xbee_init()) {
10
  /*if(xbee_init()) {
11 11
    usb_puts("ERROR! xbee\n"); 
12 12
    return -1;
13 13
  }
14
  usb_puts("xbee\n");
14
  usb_puts("xbee\n");*/
15 15
  if(analog_init(0)) {
16 16
    usb_puts("ERROR! analog\n");
17 17
    return -1;
......
49 49
  }
50 50
  usb_puts("usb\n");
51 51

  
52
  if(xbee_init() != ERROR_INIT_ALREADY_INITD) {
52
  /*if(xbee_init() != ERROR_INIT_ALREADY_INITD) {
53 53
    usb_puts("ERROR! xbee\n"); 
54 54
    return -1;
55 55
  }
56
  usb_puts("xbee\n");
56
  usb_puts("xbee\n");*/
57 57
  if(analog_init(0) != ERROR_INIT_ALREADY_INITD) {
58 58
    usb_puts("ERROR! analog\n");
59 59
    return -1;

Also available in: Unified diff