by bergere » Mon May 26, 2008 1:55 pm
by bergere
Mon May 26, 2008 1:55 pm
Hello again,
I want to transmit Data via USART. This works fine for UDR1 on my Atmega128. I was surprised that works without any initialisation.
- Code: Select all
void TxD81(byte bTxdData)
{
while(!(bit_is_set(UCSR1A,5)));
UDR1 = bTxdData;
}
But if i try to use UDR0 it doesn´t work. So i want to initialise UDR0.
- Code: Select all
void USART_Init( unsigned int ubrr )
{
/* Activate USART Transmitter */
UCSR0B |= (1<<TXEN0);
/* Set 1 Stop Bit */
UCSR0C &= ~(1<<USBS0);
/* Activate Asynchronus Transfermode */
UCSR0C &= ~(1<<UMSEL0);
/* Choose Frame Format */
UCSR0C |= (1<<UCSZ00);
UCSR0C |= (1<<UCSZ01);
UCSR0B &= ~(1<<UCSZ02);
/* Synchronisation */
UBRR0H = 0x00;
UBRR0L = 0x22;
}
My UDRR is 34 for Asynchronous Transfer Mode.
Question Number 1: Why i havn´t to initalise UDR1???
Question Number 2: Is this Initialisation correct? Or do i forgot something?
Question Number 3: Maybe UDR0 isn´t Used for Transmitting Data because i found that his UBRRL isn´t correctly defined in the iom128.h file.
For example:
- Code: Select all
/* USART0 Baud Rate Register High */
#define UBRR0H _SFR_MEM8(0x90)
/* USART0 Control and Status Register C */
#define UCSR0C _SFR_MEM8(0x95)
/* USART1 Baud Rate Register High */
#define UBRR1H _SFR_MEM8(0x98)
/* USART1 Baud Rate Register Low*/
#define UBRR1L _SFR_MEM8(0x99)
/* USART1 Control and Status Register B */
#define UCSR1B _SFR_MEM8(0x9A)
/* USART1 Control and Status Register A */
#define UCSR1A _SFR_MEM8(0x9B)
/* USART1 I/O Data Register */
#define UDR1 _SFR_MEM8(0x9C)
/* USART1 Control and Status Register C */
#define UCSR1C _SFR_MEM8(0x9D)
You can see that there isnt defined the UBRRL and many other things. But in the Atmega 128 Documentation they are listed. For example
||$09 ($29)|| UBRR0L USART0 Baud Rate Register Low
But it isn´t defined in the iom128.h. Why?
OK I hope you understand my problem despite my bad english.
Hello again,
I want to transmit Data via USART. This works fine for UDR1 on my Atmega128. I was surprised that works without any initialisation.
- Code: Select all
void TxD81(byte bTxdData)
{
while(!(bit_is_set(UCSR1A,5)));
UDR1 = bTxdData;
}
But if i try to use UDR0 it doesn´t work. So i want to initialise UDR0.
- Code: Select all
void USART_Init( unsigned int ubrr )
{
/* Activate USART Transmitter */
UCSR0B |= (1<<TXEN0);
/* Set 1 Stop Bit */
UCSR0C &= ~(1<<USBS0);
/* Activate Asynchronus Transfermode */
UCSR0C &= ~(1<<UMSEL0);
/* Choose Frame Format */
UCSR0C |= (1<<UCSZ00);
UCSR0C |= (1<<UCSZ01);
UCSR0B &= ~(1<<UCSZ02);
/* Synchronisation */
UBRR0H = 0x00;
UBRR0L = 0x22;
}
My UDRR is 34 for Asynchronous Transfer Mode.
Question Number 1: Why i havn´t to initalise UDR1???
Question Number 2: Is this Initialisation correct? Or do i forgot something?
Question Number 3: Maybe UDR0 isn´t Used for Transmitting Data because i found that his UBRRL isn´t correctly defined in the iom128.h file.
For example:
- Code: Select all
/* USART0 Baud Rate Register High */
#define UBRR0H _SFR_MEM8(0x90)
/* USART0 Control and Status Register C */
#define UCSR0C _SFR_MEM8(0x95)
/* USART1 Baud Rate Register High */
#define UBRR1H _SFR_MEM8(0x98)
/* USART1 Baud Rate Register Low*/
#define UBRR1L _SFR_MEM8(0x99)
/* USART1 Control and Status Register B */
#define UCSR1B _SFR_MEM8(0x9A)
/* USART1 Control and Status Register A */
#define UCSR1A _SFR_MEM8(0x9B)
/* USART1 I/O Data Register */
#define UDR1 _SFR_MEM8(0x9C)
/* USART1 Control and Status Register C */
#define UCSR1C _SFR_MEM8(0x9D)
You can see that there isnt defined the UBRRL and many other things. But in the Atmega 128 Documentation they are listed. For example
||$09 ($29)|| UBRR0L USART0 Baud Rate Register Low
But it isn´t defined in the iom128.h. Why?
OK I hope you understand my problem despite my bad english.
Für Fehler und Schrift haftet der Stift. Palim Palim