Download Print this page

NEX ROBOTICS Fire Bird V ATMEGA2560 Software Manual page 108

Robotic research platform
Hide thumbs Also See for Fire Bird V ATMEGA2560:

Advertisement

8.1.5 UDRn – USART I/O Data Register n
The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share
the same I/O address referred to as USART Data Register or UDRn. The Transmit Data Buffer
Register (TXB) will be the destination for data written to the UDRn Register location. Reading
the UDRn Register location will return the contents of the Receive Data Buffer Register (RXB).
For 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the Transmitter and set to
zero by the Receiver.
The transmit buffer can only be written when the UDREn Flag in the UCSRnA Register is set.
Data written to UDRn when the UDREn Flag is not set, will be ignored by the USART
Transmitter. When data is written to the transmit buffer, and the Transmitter is enabled, the
Transmitter will load the data into the Transmit Shift Register when the Shift Register is empty.
Then the data will be serially transmitted on the TxDn pin.
The receive buffer consists of a two level FIFO. The FIFO will change its state whenever the
receive buffer is accessed. Due to this behavior of the receive buffer, do not use Read-Modify-
Write instructions (SBI and CBI) on this location. Be careful when using bit test instructions
(SBIC and SBIS), since these also will change the state of the FIFO.
8.2 Functions used in serial communication
Note:
In all the functions below function will remain same for other UARTs. Only '1' of UART1 will
be replaced with the appropriate UART number
8.2.1 Function to configure UART1
//Function To Initialize UART1
// desired baud rate:9600
// actual baud rate:9600 (error 0.0%)
// char size: 8 bit
// parity: Disabled
void
uart1_init(void)
{
UCSR1B = 0x00;
//disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x5F;
//set baud rate lo
UBRR1H = 0x00;
//set baud rate hi
UCSR1B = 0x98;
}
8.2.2 Function to initialize uart 1
void
init_devices()
{
cli();
//Clears the global interrupts
port_init();
//Initializes all the ports
uart1_init();
//Initialize UART1 for serial communication
sei();
//Enables the global interrupts
}
© NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA
Fire Bird V ATMEGA2560 Software Manual
108

Advertisement

loading
Need help?

Need help?

Do you have a question about the Fire Bird V ATMEGA2560 and is the answer not in the manual?