-
Notifications
You must be signed in to change notification settings - Fork 0
/
OW_UART_fuctions.c
65 lines (60 loc) · 1.78 KB
/
OW_UART_fuctions.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
/**
******************************************************************************
* @file uart_fuctions_for_OVERWATCH.c
* @author Gachon Univ. TEAM TAKEOUT. Juhyeong Kim.
* @version V1.1.0
* @date 12-July-2017
* @brief UART fuctions for OVERWATCH project.
*
*
*
* USART_Send(USART_TypeDef* USARTx, char data)
* USART_String_Send(USART_TypeDef* USARTx, char *str)
*
* USART_Receive(USART_TypeDef* USARTx)
* USART_String_Receive(USART_TypeDef* USARTx, char *buffer)
*
* USART_CR_LF(USART_TypeDef* USARTx)
*
******************************************************************************
*/
/*Transmit 1byte data */
void USART_Send(USART_TypeDef* USARTx, char data)
{
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)));
USART_SendData(USARTx, data);
}
/*Transmit String data. This fuction needs null character in the data */
void USART_String_Send(USART_TypeDef* USARTx, char *str)
{
while(*str != 0)
{
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)));
USART_SendData(USARTx, *str);
str++;
}
}
/*Receive 1byte data */
char USART_Receive(USART_TypeDef* USARTx)
{
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_RXNE)));
return USART_ReceiveData(USARTx);
}
/*Receive String data. This fuction needs null character in the data */
void USART_String_Receive(USART_TypeDef* USARTx, char *buffer)
{
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_RXNE)));
while((*buffer = USART_ReceiveData(USARTx))!= '\0' )
{
buffer++;
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_RXNE)));
}
}
/*Transmit Carriage return and Line feed */
void USART_CR_LF(USART_TypeDef* USARTx)
{
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)));
USART_SendData(USARTx, '\r');
while(!(USART_GetFlagStatus(USARTx, USART_FLAG_TXE)));
USART_SendData(USARTx, '\n');
}