Subversion Repositories FlightCtrl

Rev

Rev 1180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1180 Rev 1201
Line 1... Line 1...
1
/*#######################################################################################
1
/*#######################################################################################
2
Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit
2
Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit
3
#######################################################################################*/
3
#######################################################################################*/
Line 4... Line 4...
4
 
4
 
5
#include "Spectrum.h"
5
#include "spectrum.h"
Line 6... Line -...
6
#include "main.h"
-
 
7
 
-
 
8
//############################################################################
-
 
9
// zum Decodieren des Spektrum Satelliten wird USART1 benutzt.
-
 
10
// USART1 initialisation from killagreg
-
 
11
void Uart1Init(void)
-
 
12
//############################################################################
-
 
13
    {
-
 
14
        // -- Start of USART1 initialisation for Spekturm seriell-mode
-
 
15
        // USART1 Control and Status Register A, B, C and baud rate register
-
 
16
        uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1);
-
 
17
        // disable RX-Interrupt
-
 
18
        UCSR1B &= ~(1 << RXCIE1);
-
 
19
        // disable TX-Interrupt
-
 
20
        UCSR1B &= ~(1 << TXCIE1);
-
 
21
        // disable DRE-Interrupt
-
 
22
        UCSR1B &= ~(1 << UDRIE1);
-
 
23
        // set direction of RXD1 and TXD1 pins
-
 
24
        // set RXD1 (PD2) as an input pin
-
 
25
        PORTD |= (1 << PORTD2);
-
 
26
        DDRD &= ~(1 << DDD2);
-
 
27
        // USART0 Baud Rate Register
-
 
28
        // set clock divider
-
 
29
        UBRR1H = (uint8_t)(ubrr>>8);
-
 
30
        UBRR1L = (uint8_t)ubrr;
-
 
31
        // enable double speed operation
-
 
32
        UCSR1A |= (1 << U2X1);
-
 
33
        // enable receiver and transmitter
-
 
34
        //UCSR1B = (1<<RXEN1)|(1<<TXEN1);
-
 
35
        UCSR1B = (1<<RXEN1);
-
 
36
        // set asynchronous mode
-
 
37
        UCSR1C &= ~(1 << UMSEL11);
-
 
38
        UCSR1C &= ~(1 << UMSEL10);
-
 
39
        // no parity
-
 
40
        UCSR1C &= ~(1 << UPM11);
-
 
41
        UCSR1C &= ~(1 << UPM10);
-
 
42
        // 1 stop bit
-
 
43
        UCSR1C &= ~(1 << USBS1);
-
 
44
        // 8-bit
-
 
45
        UCSR1B &= ~(1 << UCSZ12);
-
 
46
        UCSR1C |=  (1 << UCSZ11);
-
 
47
        UCSR1C |=  (1 << UCSZ10);
-
 
48
        // flush receive buffer explicit
-
 
49
        while(UCSR1A & (1<<RXC1)) UDR1;
-
 
50
        // enable RX-interrupts at the end
-
 
51
        UCSR1B |= (1 << RXCIE1);
-
 
52
        // -- End of USART1 initialisation
-
 
Line 53... Line 6...
53
  return;
6
#include rc.h
54
 }
7
 
55
       
8
 
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 121... Line 74...
121
// C3 to C0 is the channel number. 0 to 9 (4 bit, as assigned in the transmitter)
74
// C3 to C0 is the channel number. 0 to 9 (4 bit, as assigned in the transmitter)
122
// D9 to D0 is the channel data (10 bit) 0xaa..0x200..0x356 for 100% transmitter-travel
75
// D9 to D0 is the channel data (10 bit) 0xaa..0x200..0x356 for 100% transmitter-travel
123
//
76
//
124
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 125... Line -...
125
 
-
 
126
//############################################################################
-
 
-
 
78
 
127
//Diese Routine startet und inizialisiert den USART1 für seriellen Spektrum satellite reciever
79
 
128
SIGNAL(USART1_RX_vect)
-
 
-
 
80
void spectrum_parser(uint8_t c)
129
//############################################################################
81
 
130
{
82
{
131
static unsigned int Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0, FrameTimer;
83
        static unsigned int Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0, FrameTimer;
132
        unsigned int Channel, index;
84
        unsigned int Channel, index;
133
        signed int signal, tmp;
85
        signed int signal, tmp;
134
        int bCheckDelay;
-
 
135
        uint8_t c;
-
 
136
       
-
 
Line 137... Line 86...
137
        c = UDR1; // get data byte
86
        int bCheckDelay;
138
       
87
 
139
        if (ReSync == 1)
88
        if (ReSync == 1)
140
            {
89
            {