A tiny printf for embedded systems
Often embedded systems have small amount of RAM and flash, so you could have the need of specifically written standard functions.
Often embedded systems have small amount of RAM and flash, so you could have the need of specifically written standard functions.
Using the Standard IO facilities of the avr-libc
The avr-libc gives some facilities of the standard I/O. Only a limited subset of the standard IO is implemented (refer to the <stdio.h>: Standard IO facilities section of the avr-libc manual.). The uart.c source code could be used to interface the uart device with the Standard IO. The following example from the stdio man page of avr-libc illustrates the usage of the uart library.
The getopt function
int getopt(int argc, char * const argv[], const char *optstring);
extern char *optarg;
extern int optind, opterr, optopt;
The getopt function is used to parse command option. The parameters argc and argv are the argument count and argument array as passed to the “command”. The argument optstring is a string of recognized option characters; if a character is followed by a colon, the option takes an argument.
The Shell functions
The shell contains the following functions:
The Uart bla bla bla functions
NAME
uart_init — Init the UART port.
SYNTAX
#include “uart.h”
char uart_init (unsigned long ulBaudRate,
unsigned char ucParity,
unsigned char ucDataBit,
unsigned char ucStopBit
)
My U[S]ART implementation
My USART software is based on the ATMEL application note AVR306 : Using the AVR® UART in C.
The original source code of the application note was changed to support receiver error and to support some of the capabilities of the avr UART interface databit (5..8 ), stop bit (1-2) and parity check (none, odd and even).
UART Data Register Empty Interrupt
As described the USART can generate interrupt if the data register is empty. The interrupt could be enabled setting the Data Register Empty Interrupt Enable(UDRIE0) .
The USART Data Register Empty ISR will be executed until the UDRE0 is set (if the global interrupts are enabled).
Interrupt from the USART
Before to speak about the interrupts implementation of the USART, I want to say a little bit regarding the “Interrupts” and then it will follow by a description of the usage of the USART interrupts if one of the following conditions happen:
Frame format
The frame formats supported by the Atmega is the standard UART frame format, specifically it accepts all 30 combinations of the following as valid frame formats:
1 start bit
5, 6, 7, 8, or 9 data bits
no, even or odd parity bit
Receiver’s Errors
The USART Receiver has three Error Flags: Frame Error (FE0), Data OverRun (DOR0) and Parity Error (UPE0). All can be accessed by reading UCSR0A.
Latest Comments