Subversion Repositories FlightCtrl

Rev

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

Rev 1426 Rev 1431
Line 5... Line 5...
5
#include "Spektrum.h"
5
#include "Spektrum.h"
6
#include "main.h"
6
#include "main.h"
7
unsigned char SpektrumTimer = 0;
7
unsigned char SpektrumTimer = 0;
Line 8... Line 8...
8
 
8
 
9
//--------------------------------------------------------------//
-
 
10
 
9
//--------------------------------------------------------------//
11
//--------------------------------------------------------------//
10
//--------------------------------------------------------------//
12
void SpektrumBinding(void)
11
void SpektrumBinding(void)
13
{
12
{
14
  unsigned int timerTimeout = SetDelay(10000);  // Timeout 10 sec.
13
  unsigned int timerTimeout = SetDelay(10000);  // Timeout 10 sec.
Line 68... Line 67...
68
void SpektrumUartInit(void)
67
void SpektrumUartInit(void)
69
//############################################################################
68
//############################################################################
70
    {
69
    {
71
        // -- Start of USART1 initialisation for Spekturm seriell-mode
70
        // -- Start of USART1 initialisation for Spekturm seriell-mode
72
        // USART1 Control and Status Register A, B, C and baud rate register
71
        // USART1 Control and Status Register A, B, C and baud rate register
-
 
72
        uint8_t sreg = SREG;
-
 
73
       
73
        uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1);
74
        uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1);
-
 
75
       
-
 
76
        // disable all interrupts before reconfiguration
-
 
77
        cli();
74
        // disable RX-Interrupt
78
        // disable RX-Interrupt
75
        UCSR1B &= ~(1 << RXCIE1);
79
        UCSR1B &= ~(1 << RXCIE1);
76
        // disable TX-Interrupt
80
        // disable TX-Interrupt
77
        UCSR1B &= ~(1 << TXCIE1);
81
        UCSR1B &= ~(1 << TXCIE1);
78
        // disable DRE-Interrupt
82
        // disable DRE-Interrupt
79
        UCSR1B &= ~(1 << UDRIE1);
83
        UCSR1B &= ~(1 << UDRIE1);
80
        // set direction of RXD1 and TXD1 pins
84
        // set direction of RXD1 and TXD1 pins
81
        // set RXD1 (PD2) as an input pin
85
        // set RXD1 (PD2) as an input pin
82
        PORTD |= (1 << PORTD2);
86
        PORTD |= (1 << PORTD2);
83
        DDRD &= ~(1 << DDD2);
87
        DDRD &= ~(1 << DDD2);
-
 
88
 
-
 
89
        // set TXD1 (PD3) as an output pin
-
 
90
        PORTD |= (1 << PORTD3);
-
 
91
        DDRD  |= (1 << DDD3);
-
 
92
       
84
        // USART0 Baud Rate Register
93
        // USART0 Baud Rate Register
85
        // set clock divider
94
        // set clock divider
86
 
-
 
87
        UBRR1H = (uint8_t)(ubrr>>8);
95
        UBRR1H = (uint8_t)(ubrr>>8);
88
        UBRR1L = (uint8_t)ubrr;
96
        UBRR1L = (uint8_t)ubrr;
89
        // enable double speed operation
97
        // enable double speed operation
90
        UCSR1A |= (1 << U2X1);
98
        UCSR1A |= (1 << U2X1);
91
        // enable receiver and transmitter
99
        // enable receiver and transmitter
Line 107... Line 115...
107
        // flush receive buffer explicit
115
        // flush receive buffer explicit
108
        while(UCSR1A & (1<<RXC1)) UDR1;
116
        while(UCSR1A & (1<<RXC1)) UDR1;
109
        // enable RX-interrupts at the end
117
        // enable RX-interrupts at the end
110
        UCSR1B |= (1 << RXCIE1);
118
        UCSR1B |= (1 << RXCIE1);
111
        // -- End of USART1 initialisation
119
        // -- End of USART1 initialisation
-
 
120
        // restore global interrupt flags
-
 
121
   
-
 
122
        SREG = sreg;
112
  return;
123
  return;
113
 }
124
 }
Line 114... Line 125...
114
 
125
 
115
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
126
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 188... Line 199...
188
 
199
 
189
 
200
 
190
 
-
 
191
//############################################################################
201
 
192
//Diese Routine startet und inizialisiert den USART1 für seriellen Spektrum satellite reciever
202
//############################################################################
193
//SIGNAL(USART1_RX_vect)
203
//Diese Routine startet und inizialisiert den USART1 für seriellen Spektrum satellite reciever
194
//############################################################################
204
//############################################################################
195
void SpektrumParser(unsigned char c)
205
void SpektrumParser(unsigned char c)