Subversion Repositories FlightCtrl

Rev

Rev 1172 | Rev 1232 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1172 Rev 1213
Line 3... Line 3...
3
#######################################################################################*/
3
#######################################################################################*/
Line 4... Line 4...
4
 
4
 
5
#include "Spectrum.h"
5
#include "Spectrum.h"
Line -... Line 6...
-
 
6
#include "main.h"
-
 
7
 
-
 
8
//--------------------------------------------------------------//
-
 
9
 
-
 
10
//--------------------------------------------------------------//
-
 
11
void SpektrumBinding(void)
-
 
12
{
-
 
13
  unsigned int timerTimeout = SetDelay(10000);  // Timeout 10 sec.
-
 
14
  unsigned char connected = 0;
-
 
15
  unsigned int delaycounter;
-
 
16
 
-
 
17
  UCSR1B &= ~(1 << RXCIE1);  // disable rx-interrupt
-
 
18
  UCSR1B &= ~(1<<RXEN1);     // disable Uart-Rx
-
 
19
  PORTD &= ~(1 << PORTD2);   // disable pull-up
-
 
20
 
-
 
21
  printf("\n\rPlease connect Spektrum receiver for binding NOW...");
-
 
22
 
-
 
23
  while(!CheckDelay(timerTimeout))
-
 
24
  {
-
 
25
    if (PIND & (1 << PORTD2)) { timerTimeout = SetDelay(90); connected = 1; break; }
-
 
26
  }
-
 
27
 
-
 
28
  if (connected)
-
 
29
  {
-
 
30
   
-
 
31
    printf("ok.\n\r");
-
 
32
    DDRD |= (1 << DDD2);     // Rx as output
-
 
33
 
-
 
34
        while(!CheckDelay(timerTimeout));  // delay after startup of RX
-
 
35
        for (delaycounter = 0; delaycounter < 100; delaycounter++) PORTD |= (1 << PORTD2);
-
 
36
        for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2);
-
 
37
       
-
 
38
        for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2);
-
 
39
    for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2);
-
 
40
        for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2);
-
 
41
        for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2);
-
 
42
     
-
 
43
        for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2);
-
 
44
    for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2);
-
 
45
        for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2);
-
 
46
        for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2);
-
 
47
 
-
 
48
        for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2);
-
 
49
    for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2);
-
 
50
        for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2);
-
 
51
 
-
 
52
  }
-
 
53
   else
-
 
54
  { printf("Timeout.\n\r");
-
 
55
 
-
 
56
 
-
 
57
  }
-
 
58
   
-
 
59
  DDRD &= ~(1 << DDD2);      // RX as input
-
 
60
  PORTD &= ~(1 << PORTD2);  
-
 
61
 
-
 
62
  Uart1Init();    // init Uart again
6
#include "main.h"
63
}
7
 
64
 
8
//############################################################################
65
//############################################################################
9
// zum Decodieren des Spektrum Satelliten wird USART1 benutzt.
66
// zum Decodieren des Spektrum Satelliten wird USART1 benutzt.
10
// USART1 initialisation from killagreg
67
// USART1 initialisation from killagreg
Line 24... Line 81...
24
        // set RXD1 (PD2) as an input pin
81
        // set RXD1 (PD2) as an input pin
25
        PORTD |= (1 << PORTD2);
82
        PORTD |= (1 << PORTD2);
26
        DDRD &= ~(1 << DDD2);
83
        DDRD &= ~(1 << DDD2);
27
        // USART0 Baud Rate Register
84
        // USART0 Baud Rate Register
28
        // set clock divider
85
        // set clock divider
-
 
86
       
29
        UBRR1H = (uint8_t)(ubrr>>8);
87
        UBRR1H = (uint8_t)(ubrr>>8);
30
        UBRR1L = (uint8_t)ubrr;
88
        UBRR1L = (uint8_t)ubrr;
31
        // enable double speed operation
89
        // enable double speed operation
32
        UCSR1A |= (1 << U2X1);
90
        UCSR1A |= (1 << U2X1);
33
        // enable receiver and transmitter
91
        // enable receiver and transmitter
34
        //UCSR1B = (1<<RXEN1)|(1<<TXEN1);
92
        //UCSR1B = (1<<RXEN1)|(1<<TXEN1);
-
 
93
 
-
 
94
 
-
 
95
       
-
 
96
       
35
        UCSR1B = (1<<RXEN1);
97
        UCSR1B = (1<<RXEN1);
36
        // set asynchronous mode
98
        // set asynchronous mode
37
        UCSR1C &= ~(1 << UMSEL11);
99
        UCSR1C &= ~(1 << UMSEL11);
38
        UCSR1C &= ~(1 << UMSEL10);
100
        UCSR1C &= ~(1 << UMSEL10);
39
        // no parity
101
        // no parity