usrat.h File Reference
USART interface.
More...
Go to the source code of this file.
Defines |
#define | RX_BUFFER_SIZE 4 |
| USART RX buffer length.
|
Functions |
void | usart_init (uint16_t baudrate) |
| Initialize USART, perform fdevopen with uart_putchar.
|
void | usart_stop () |
| Disable USART completely.
|
int | uart_putchar (char data) |
| putchar() for USART.
|
int | uart_getchar () |
| getchar() for USART. Wait for data if not available.
|
uint8_t | uart_available (void) |
| Check data availability in USART buffer.
|
uint8_t | uart_getc () |
| Nonblocking, nonchecking getchar for USART. Use with care.
|
Detailed Description
USART interface.
Define Documentation
Function Documentation
uint8_t uart_available |
( |
void |
|
) |
|
Check data availability in USART buffer.
- Returns:
- 1 if buffer is not empty.
00070 {
00071 return rx_buffer_in != rx_buffer_out;
00072 }
Nonblocking, nonchecking getchar for USART. Use with care.
00075 {
00076 uint8_t result = rx_buffer[rx_buffer_out];
00077 rx_buffer_out = (rx_buffer_out + 1) % RX_BUFFER_SIZE;
00078
00079 return result;
00080 }
getchar() for USART. Wait for data if not available.
- Returns:
- value read.
- See also:
- uart_available()
int uart_putchar |
( |
char |
data |
) |
|
putchar() for USART.
- Parameters:
-
00044 {
00045
00046 if (data == '\n') {
00047 (void)uart_putchar('\r');
00048 }
00049
00050
00051 while (!(UCSRA & (1<<UDRE))) {};
00052
00053
00054 UDR = (uint8_t)data;
00055
00056 return 0;
00057 }
void usart_init |
( |
uint16_t |
baudval |
) |
|
Initialize USART, perform fdevopen with uart_putchar.
- Parameters:
-
| baudval | (F_CPU/(16*baudrate))-1 |
- See also:
- uart_putchar()
00020 {
00021
00022 UBRRH = (uint8_t)(baudval>>8);
00023 UBRRL = (uint8_t)baudval;
00024
00025 rx_buffer_in = rx_buffer_out = 0;
00026
00027
00028 UCSRC = (uint8_t)((1<<URSEL) | (0<<USBS) | (3<<UCSZ0));
00029
00030
00031 UCSRB = (uint8_t)((1<<RXEN) | (1<<TXEN) | (1<<RXCIE));
00032
00033 (void)fdevopen(uart_putchar, NULL);
00034 }
Disable USART completely.
00037 {
00038 UCSRB = 0;
00039 (void)fdevopen(uart_non,NULL);
00040 }