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
Loading...
Searching...
No Matches
Macros
avr_uart.h File Reference
#include <avr/io.h>
#include <stdint.h>
Include dependency graph for avr_uart.h:
This graph shows which files directly or indirectly include this file:

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.
 

Macro Definition Documentation

◆ _UART_Init

#define _UART_Init ( uart_no,
ubrr,
rxIntEnable )
Value:
UBRR##uart_no##H = (uint8_t)(ubrr >> 8) & 0xFF; \
UBRR##uart_no##L = (uint8_t)(ubrr)&0xFF; \
UCSR##uart_no##A = 0; \
UCSR##uart_no##C = (3 << UCSZ00); \
UCSR##uart_no##B = (1 << RXEN0) | (1 << TXEN0) | (rxIntEnable << RXCIE0);

Second level of macro makes sure parameters are expanded before subbing into string concatenation

Definition at line 27 of file avr_uart.h.

◆ def_usart_isr_push_rx_to_circ_buf

#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.

Notes

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();

Parameters

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.

◆ UART_Init

#define UART_Init ( uart_no,
ubrr,
rxIntEnable )    _UART_Init(uart_no, ubrr, rxIntEnable)

Initialize USART.

8 bit, 1 stop bit, no parity bit

Parameters
uart_nonumber of UART, like 0 or 1
ubrr12 bits of uint16_t: should be clock / 16 / baud - 1
rxIntEnable1 bit enable RX interrupt

Definition at line 20 of file avr_uart.h.

◆ USART_disable_udre_interrupt

#define USART_disable_udre_interrupt ( uart_no)     UCSR##uart_no##B &= ~(1 << UDRIE##uart_no)

Definition at line 38 of file avr_uart.h.

◆ USART_enable_udre_interrupt

#define USART_enable_udre_interrupt ( uart_no)     UCSR##uart_no##B |= (1 << UDRIE##uart_no)

Definition at line 36 of file avr_uart.h.