§ Функции для работы
1#include <avr/io.h>
2#include <util/delay.h>
3
4
5
6#define BAUD 9600L
7
8
9#define UBRRL_value ((F_CPU / (BAUD * 16)) - 1)
10
11
12void UART_init() {
13
14
15 UBRR0L = UBRRL_value;
16 UBRR0H = UBRRL_value >> 8;
17
18
19 UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
20
21
22 UCSR0C |= (1 << UMSEL01) | (1 << UCSZ01 ) | (1 << UCSZ00);
23}
24
25void UART_put(unsigned char value) {
26
27
28 while (!( UCSR0A & (1 << UDRE0)));
29
30
31 UDR0 = value;
32}
33
34unsigned char UART_get(){
35
36 while ((UCSR0A & (1 << RXC0)) == 0);
37 return UDR0;
38}
39
40
41void UART_print(const char* s) {
42
43 int i = 0;
44 while (s[i]) UART_put(s[i++]);
45}
46
47
48void UART_pbyte(unsigned char b) {
49
50 int h = (b & 0xf0) >> 4;
51 int l = b & 0x0f;
52
53 UART_put(h + (h < 10 ? '0' : '7'));
54 UART_put(l + (l < 10 ? '0' : '7'));
55}
56
57int main(void) {
58
59 UART_init();
60 while (1) {
61 send_UART( UART_get() );
62 }
63}
§ Настройка портов
1stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr \
2 -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
3echo "Hello World" > /dev/ttyACM0