Инит юартов. Использую прерывания RX
Код
/***********************************************************************
Function : uart0_init
Parameters : nil
Date :
Desc : int disabled
//UART0 initialize
// desired baud rate: 57600
// actual: baud rate:57600 (0,0%)
// char size: 8 bit
// parity: Disabled
//ICC-AVR application builder : 04.06.2008 15:23:56
// Target : M128
// Crystal: 7.3728Mhz
***********************************************************************/
void uart0_init(void)
{
#ifndef UartOVF
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x07; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
#else
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x07; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
//UCSR0B = 0xB8;
UCSR0B = 0x98; //without UDR is now empty int
#endif
}
/***********************************************************************
Function : uart1_init
Parameters : nil
Date :
Desc : int disabled
//UART1 initialize
// desired baud rate:57600
// actual baud rate:57600 (0,0%)
// char size: 8 bit
// parity: Disabled
//ICC-AVR application builder : 04.06.2008 15:23:56
// Target : M128
// Crystal: 7.3728Mhz
***********************************************************************/
void uart1_init(void)
{
#ifndef UartOVF
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x07; //set baud rate lo
UBRR1H = 0x00; //set baud rate hi
UCSR1B = 0x18;
#else
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x07; //set baud rate lo
UBRR1H = 0x00; //set baud rate hi
//UCSR1B = 0xB8;
UCSR1B = 0x98; //without UDR is now empty int
#endif
}
Function : uart0_init
Parameters : nil
Date :
Desc : int disabled
//UART0 initialize
// desired baud rate: 57600
// actual: baud rate:57600 (0,0%)
// char size: 8 bit
// parity: Disabled
//ICC-AVR application builder : 04.06.2008 15:23:56
// Target : M128
// Crystal: 7.3728Mhz
***********************************************************************/
void uart0_init(void)
{
#ifndef UartOVF
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x07; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
#else
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x07; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
//UCSR0B = 0xB8;
UCSR0B = 0x98; //without UDR is now empty int
#endif
}
/***********************************************************************
Function : uart1_init
Parameters : nil
Date :
Desc : int disabled
//UART1 initialize
// desired baud rate:57600
// actual baud rate:57600 (0,0%)
// char size: 8 bit
// parity: Disabled
//ICC-AVR application builder : 04.06.2008 15:23:56
// Target : M128
// Crystal: 7.3728Mhz
***********************************************************************/
void uart1_init(void)
{
#ifndef UartOVF
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x07; //set baud rate lo
UBRR1H = 0x00; //set baud rate hi
UCSR1B = 0x18;
#else
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x07; //set baud rate lo
UBRR1H = 0x00; //set baud rate hi
//UCSR1B = 0xB8;
UCSR1B = 0x98; //without UDR is now empty int
#endif
}
вызовы
Код
/***********************************************************************
Function : putchar
Parameters :
Date :
Desc :
***********************************************************************/
void putchar(unsigned char tx_char, unsigned char CASE_UART)
{
switch(CASE_UART)
{
case UART_1:{ //printing to UART PHONE
while( !(UCSR0A & (1 << UDRE0) ) ); // ??????????????????????????????????
UDR0 = tx_char;
break;}
case UART_2:{ //printing to UART TUNER
while( !(UCSR1A & (1 << UDRE1) ) ); //???????????????????????????????????
UDR1 = tx_char;
break;}
case UART_3:{ //printing to UART_3 (SOFT DEBUG UART)
sUARTtx(tx_char);
break;}
}
}
Function : putchar
Parameters :
Date :
Desc :
***********************************************************************/
void putchar(unsigned char tx_char, unsigned char CASE_UART)
{
switch(CASE_UART)
{
case UART_1:{ //printing to UART PHONE
while( !(UCSR0A & (1 << UDRE0) ) ); // ??????????????????????????????????
UDR0 = tx_char;
break;}
case UART_2:{ //printing to UART TUNER
while( !(UCSR1A & (1 << UDRE1) ) ); //???????????????????????????????????
UDR1 = tx_char;
break;}
case UART_3:{ //printing to UART_3 (SOFT DEBUG UART)
sUARTtx(tx_char);
break;}
}
}
при этом первый юарт работает нормально как только вызываю второй программа вешается, как я понял на строке while( !(UCSR1A & (1 << UDRE1) ) ); и всё вечное ожидание.