-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-recv.c
63 lines (48 loc) · 1.15 KB
/
example-recv.c
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
56
57
58
59
60
61
62
63
/*
** Demonstration of fd-serial module
** (C) 2010, Nick Andrew <[email protected]>
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "fd-serial.h"
/* Set highest frequency CPU operation.
** Startup frequency is assumed to be 1 MHz;
** 8 MHz for the internal clock.
*/
void set_cpu_8mhz(void) {
// Prepare for clock change
CLKPR = 1<<CLKPCE;
// Set the internal clock
CLKPR = 0<<CLKPS3 | 0<<CLKPS2 | 0<<CLKPS1 | 0<<CLKPS0;
// System clock is now 8 MHz
}
void writeString(char const *cp) {
while (*cp) {
fdserial_send(*cp++);
}
}
int main(void) {
// Disable interrupts
cli();
// Setup the clock
set_cpu_8mhz();
// Enable the software UART
fdserial_init();
// Enable interrupts
sei();
uint32_t loops = 0;
writeString("\r\nFull Duplex Serial example: receive and echo\r\n");
while (1) {
// Wait for a RX character and return it
char c = fdserial_recv();
// If a non-null character was received, initiate TX
if (c) {
// This does not wait for the character to be sent.
// Instead, it waits for TX idle, which may mean
// the end of the last TX character.
fdserial_send(c);
}
loops ++;
}
}