-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart.c
More file actions
57 lines (52 loc) · 1.03 KB
/
uart.c
File metadata and controls
57 lines (52 loc) · 1.03 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
56
57
/*
* uart.c
*
* Created on: 5 févr. 2017
* Author: postaron
*/
#include "uart.h"
#include "compteurCode.h"
#define START 0x0A //the real one
#define END 0x0D //same reason
#define SPACE 0x20 //a space between the tag, data and checksum
void uart_init(void) {
// set baudrate to 1200bit/second
//The 0 is for the timer0
UBRR0 |= BAUDRATE;
UCSR0C = 0b00100100; /*asynchronous mode enable, parity even, 7-bit data, 1 stop bit */
UCSR0B |= (1 << RXEN0); // Enable RX
}
//not finished yet : reboot µC (watchdog ?)
void uart_checkError(void) {
switch (~(0xE3 & UCSR0A)) { // 0xE3 = bits other than FE0 DOR0 and UPE0
case (1 << FE0):
break;
case (1 << DOR0):
break;
case (1 << UPE0):
break;
case 0:
//no errors
break;
default: //multiple errors
break;
}
}
char uart_getChar() {
while ((UCSR0A & (1 << RXC0)) == 0)
//do nothing while receive not complete
;
return UDR0;
}
void decode(char data) {
switch (data) {
case START:
break;
case SPACE:
break;
case END:
break;
default:
break;
}
}