#WARNING:
- If you make optimization (OPTIMIZE == 1) of this code, it will uses ~500bytes, but you will not be able to write baud rate(9600, 115200, ETC) value in 'usart_init();' because in this case baud rate to UBRRn converter is disabled, so you would write directly UBRRn(103, 8, ETC) value(check in ATmega328p datasheet).
Baud rate -> UBRRn (UX2n == 0): 9600 -> 103 38400 -> 25 115200 -> 8
-
Of this library target is small memory usage and fast execution.
-
In code are preprocesors where user is able active or deactive some modes:
-
Active or deactive ISR by change value of ISR_EN (Default value is 1 as activated);
-
user can change memory usage by changeing value of OPTIMIZE (Default value is 0 as disabled);
#Functions:
- void usart_init(uint32_t baud, uint8_t speed);
- void usart_sendChar(char acter);
- void usart_sendStr(char *str);
- char usart_getChar(void);
- uint8_t usart_getStr(void);
- void usart_clear(void);
#libraries
- #include <avr/io.h>
- #include <avr/interrupt.h>
#variables
- volatile static char RECEIVED_CHAR = '\0';
- volatile static char RECEIVED_BUFFER[_BUFFER_SIZE] = {0};
- volatile static uint16_t RX_COUNT0 = 0;
- volatile static uint8_t TX_READY = 1;
#ISR
- USART_RX_vect
- USART_TX_vect
#Configurations
-
#define OPTIMIZE 0
-
#define ISR_EN 1
#Hardware requirements
- ATmega328p
#Software requirements
- AVR-GCC
- AVR-OBJCOPY
- AVRDUDE
- AVR-SIZE
- MAKE
=========================================
#About developer