usart library for the atmega328p for embedded systems programming using embedded C and avr-gcc
The following is a list of features still to be implemented into the library:
- ODR (output data rate) flag for baud rate control
- Resolve issue with F_CPU macro conflict
- Add interrupt support handlers
- Add usart number flag to select which usart to use (if more that usart 0 is available on microcontroller)
- add read functions (unfortunately missed this in first pass 🫣)
A possible way of including this library to projects are to git clone the repository to a libs directory in the project directory. Then you can either generate a shell script to iterate through all project folders to call make or make a explicit rule in your project makefile.
make -C other_makefile_dir
the command above will run make in the provided directory.
Currently the library requires the manual definition of F_CPU macro in usart.h. This macro is also used by the avr-libc for functions like _delay_ms()
Asynchronous communication (UART)
Synchronous communication (USRT)
Sets the frame to use 1 stop bit
Sets the frame to use 2 stop bits
Disables parity checking on frame transmission
Sets parity on and enables even parity
Sets parity on and enables odd parity
Struct that hold the desired usart configuration data.
| data member name | description |
|---|---|
| usart_num | The index number of target usart |
| baudrate | the desired baudrate of the usart communication |
| usart_mode | the desired mode of communication async or sync (refer to usart modes for macro options) |
| frame_size | the number of bits per frame transmission (accepts values where 5 <= frameSize <= 9 as uint8_t) |
| stop_bits | the number of stopBits per frame transmission (refer to stop bit options for macro options) |
| parity_mode | enable/disable parity for usart transmission (refer to parity modes for macro options) |
pointer to usart_config_t
Function that calculates the UDDRn value required to achieve desired baudrate. (Disclaimer currently requires manual setting of U2Xn)
Function to the baudrate of target usart
Function to set frame size of target usart
Function to set the mode of target usart.
Function to set the parity of target usart
Function to set the stop bits of target usart
function that initialises the usart using the usart_config_t data passed
Function to send a single character of the usart bus
Function to send a string over the usart bus