|
ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
|
#include <avr/io.h>#include <stdint.h>

Go to the source code of this file.
Macros | |
| #define | UART_Init(uart_no, ubrr, rxIntEnable) _UART_Init(uart_no, ubrr, rxIntEnable) |
| Initialize USART. | |
| #define | _UART_Init(uart_no, ubrr, rxIntEnable) |
| #define | USART_enable_udre_interrupt(uart_no) UCSR##uart_no##B |= (1 << UDRIE##uart_no) |
| #define | USART_disable_udre_interrupt(uart_no) UCSR##uart_no##B &= ~(1 << UDRIE##uart_no) |
| #define | def_usart_isr_push_rx_to_circ_buf(isr_name, data_register, circular_buffer) ISR(USART_RX_vect) { circular_buffer_push_back_uint8(circular_buffer, UDR0); } |
| Define the ISR for a USART to push rx bytes to a circular buffer. | |
| #define _UART_Init | ( | uart_no, | |
| ubrr, | |||
| rxIntEnable ) |
Second level of macro makes sure parameters are expanded before subbing into string concatenation
Definition at line 27 of file avr_uart.h.
| #define def_usart_isr_push_rx_to_circ_buf | ( | isr_name, | |
| data_register, | |||
| circular_buffer ) ISR(USART_RX_vect) { circular_buffer_push_back_uint8(circular_buffer, UDR0); } |
Define the ISR for a USART to push rx bytes to a circular buffer.
Defines the interrupt handler for the given USART. The interrupt handler will push all rx bytes to the back of the circular buffer the user provides.
DON'T USE A SEMICOLON AFTER THIS MACRO.
Use atomic operations to remove data from the front of the circular buffer like CM_ATOMIC_BLOCK() {}
Make sure to setup the USART with rx interrupt enabled: USART0_Init(<ubrr>,1)
Make sure to turn enable the global interrupt flag: sei();
isr_name: USART_RX_vect for 328
data_register: UDR0 for 328
circular_buffer: a pointer to a circular_buffer_uint8 that you want received bytes pushed_back on.
Definition at line 68 of file avr_uart.h.
| #define UART_Init | ( | uart_no, | |
| ubrr, | |||
| rxIntEnable ) _UART_Init(uart_no, ubrr, rxIntEnable) |
Initialize USART.
8 bit, 1 stop bit, no parity bit
| uart_no | number of UART, like 0 or 1 |
| ubrr | 12 bits of uint16_t: should be clock / 16 / baud - 1 |
| rxIntEnable | 1 bit enable RX interrupt |
Definition at line 20 of file avr_uart.h.
| #define USART_disable_udre_interrupt | ( | uart_no | ) | UCSR##uart_no##B &= ~(1 << UDRIE##uart_no) |
Definition at line 38 of file avr_uart.h.
| #define USART_enable_udre_interrupt | ( | uart_no | ) | UCSR##uart_no##B |= (1 << UDRIE##uart_no) |
Definition at line 36 of file avr_uart.h.