#include <avr/io.h>
#include <inttypes.h>
Go to the source code of this file.
Defines | |
#define | BAUD 9600 |
The desired baud rate (default is 9600 baud). | |
#define | BAUD_SETTING (F_CPU/(16UL*BAUD)-1) |
Functions | |
void | uart_init (uint16_t brr) |
Set up the UART. | |
int | uart_putchar (char c) |
Send a character. | |
char | uart_getchar (char *c) |
Reads a character from the receiver buffer. | |
int | uart_puts (const char *s) |
Sends a string. |
Define UART_X2 in your compiler flags to use the X2 mode in UART clock generation. Check the "examples of baud rate setting" table in your data sheet to see if you should be using X2 mode.
#define BAUD 9600 |
The desired baud rate (default is 9600 baud).
#define BAUD_SETTING (F_CPU/(16UL*BAUD)-1) |
char uart_getchar | ( | char * | c | ) |
Reads a character from the receiver buffer.
This function reads the next byte (if any) from the receive buffer and copies it to the specified address. This is essentially a non-blocking getchar() routine. Nothing is written to the specified address if the receive buffer was empty.
[out] | c | Pointer to where the byte is to be written. |
char | 1 if something was read, 0 if the receive buffer was empty. |
void uart_init | ( | uint16_t | brr | ) | [inline] |
Set up the UART.
This function sets up the UART using the baud rate setting specified and initializes the transmit and receive buffers. It should be called with the BAUD_SETTING macro as an argument. X2 clock mode will be enabled if UART_X2 is defined.
[in] | brr | Baud rate setting to use. |
int uart_putchar | ( | char | c | ) |
Send a character.
This function writes a byte to the transmit buffer and enables the UDRE interrupt so that the byte will be transmitted.
[in] | c | Byte to transmit. |
int | The parameter 'c' on success, -1 if there was not enough room in the transmit buffer. |
int uart_puts | ( | const char * | s | ) |
Sends a string.
This function is provided for convenience. It writes a string to the transmit buffer by calling uart_putchar() repeatedly.
[in] | s | String to write (must be NULL-terminated). |
int | Number of bytes successfully written. |