-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoft_uart.h
More file actions
55 lines (47 loc) · 2.21 KB
/
soft_uart.h
File metadata and controls
55 lines (47 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//*****************************************************************************
//
// File Name : 'suart.h'
// Title : UART Interface
// Author : Ehsan Varasteh
// Created : 2011-08-04
// Version : 1.0
// Target MCU : Atmel AVR series
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
//*****************************************************************************
// THESE CONSTANTS YOU SHOULD DEFINE YOURSELF {{
#ifndef UART_BAUD_RATE
#define UART_BAUD_RATE 9600 // default
/* some standard baud rates:
57600 38400 19200 9600 4800 2400 1200 300 110
*/
#endif
#ifndef UART_PORT
#define UART_PORT PORTC // for transmit
#endif
#ifndef UART_PIN
#define UART_PIN PINC // for receive
#endif
// }}
//*****************************************************************************
#define UART_NO_PARITY 0
#define UART_EVEN_PARITY 1
#define UART_ODD_PARITY 2
// System Errors
#define UART_ERROR_OVERRUN 100 // If the CPU does not service the UART quickly enough and the buffer becomes full, an Overrun Error will occur, and incoming characters will be lost.
#define UART_ERROR_UNDERRUN 101 // This error indication is commonly found in USARTs, since an underrun is more serious in synchronous systems.
#define UART_ERROR_FRAMING 102 // If the data line is not in the expected idle state when the "stop" bit is expected, a Framing Error will occur.
#define UART_ERROR_PARITY 103 // Parity error is set when the parity of an incoming data character does not match the expected value.
#define UART_ERROR_BREAK_CONDITION 104 // This error occurs when the receiver input is at the "space" level for longer than some duration of time, typically, for more than a character time.
typedef struct {
unsigned char _pp; // port bit number, default = 1
unsigned char _stop_bits; // stop bits, default = 1
unsigned char _data_size; // data size, default = 8
unsigned char _parity_bit; // 0:no, 1:EVEN, 2:ODD, default = 0
} UART_OPT; // UART Options
void set_uart(UART_OPT set); // set uart_settings
void uart_transmit(uint8_t data); // transmits 1 frame
uint8_t uart_receive(); // receives 1 frame