-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart.c
69 lines (57 loc) · 1.28 KB
/
uart.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
64
65
66
67
68
69
/*
* TongSheng TSDZ2 motor controller firmware/
*
* Copyright (C) Casainho, 2018.
*
* Released under the GPL License, Version 3
*/
#include <stdint.h>
#include <stdio.h>
#include "stm8s.h"
#include "stm8s_uart2.h"
#include "main.h"
void uart2_init (void)
{
UART2_DeInit();
#ifdef DEBUG_UART
UART2_Init((uint32_t) 115200,
#else
UART2_Init((uint32_t) 9600,
#endif
UART2_WORDLENGTH_8D,
UART2_STOPBITS_1,
UART2_PARITY_NO,
UART2_SYNCMODE_CLOCK_DISABLE,
UART2_MODE_TXRX_ENABLE);
UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);
}
#if __SDCC_REVISION < 9624
void putchar(char c)
{
//Write a character to the UART2
UART2_SendData8(c);
//Loop until the end of transmission
while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET);
}
#else
int putchar(int c)
{
//Write a character to the UART2
UART2_SendData8(c);
//Loop until the end of transmission
while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET);
return((unsigned char)c);
}
#endif
#if __SDCC_REVISION < 9989
char getchar(void)
#else
int getchar(void)
#endif
{
uint8_t c = 0;
/* Loop until the Read data register flag is SET */
while (UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET) ;
c = UART2_ReceiveData8();
return (c);
}