Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1820 → Rev 1821

/branches/dongfang_FC_rewrite/uart1.c
69,10 → 69,10
/****************************************************************/
/* Initialization of the USART1 */
/****************************************************************/
void usart1_Init (void) {
void usart1_Init(void) {
// USART1 Control and Status Register A, B, C and baud rate register
uint8_t sreg = SREG;
uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * USART1_BAUD) - 1);
uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK / (8 * USART1_BAUD) - 1);
 
// disable all interrupts before reconfiguration
cli();
91,12 → 91,12
 
// set TXD1 (PD3) as an output pin
PORTD |= (1 << PORTD3);
DDRD |= (1 << DDD3);
DDRD |= (1 << DDD3);
 
// USART0 Baud Rate Register
// set clock divider
UBRR1H = (uint8_t)(ubrr>>8);
UBRR1L = (uint8_t)ubrr;
UBRR1H = (uint8_t) (ubrr >> 8);
UBRR1L = (uint8_t) ubrr;
 
// enable double speed operation
UCSR1A |= (1 << U2X1);
112,11 → 112,12
UCSR1C &= ~(1 << USBS1);
// 8-bit
UCSR1B &= ~(1 << UCSZ12);
UCSR1C |= (1 << UCSZ11);
UCSR1C |= (1 << UCSZ10);
UCSR1C |= (1 << UCSZ11);
UCSR1C |= (1 << UCSZ10);
 
// flush receive buffer explicit
while ( UCSR1A & (1<<RXC1) ) UDR1;
while (UCSR1A & (1 << RXC1))
UDR1;
 
// enable interrupts at the end
// enable RX-Interrupt
127,7 → 128,7
//UCSR1B |= (1 << UDRIE1);
 
// restore global interrupt flags
SREG = sreg;
SREG = sreg;
}
 
/****************************************************************/
134,25 → 135,26
/* USART1 data register empty ISR */
/****************************************************************/
/*ISR(USART1_UDRE_vect) {
}
*/
}
*/
 
/****************************************************************/
/* USART1 transmitter ISR */
/****************************************************************/
/*ISR(USART1_TX_vect) {
}
*/
}
*/
/****************************************************************/
/* USART1 receiver ISR */
/****************************************************************/
ISR(USART1_RX_vect) {
ISR(USART1_RX_vect)
{
uint8_t c;
c = UDR1; // get data byte
#ifdef USE_RC_DSL
dsl_parser(c); // parse dsl data stream
#endif
#ifdef USE_RC_SPECTRUM
spectrum_parser(c); // parse spectrum data stream
#endif
#ifdef USE_RC_DSL
dsl_parser(c); // parse dsl data stream
#endif
#ifdef USE_RC_SPECTRUM
spectrum_parser(c); // parse spectrum data stream
#endif
}