-
Notifications
You must be signed in to change notification settings - Fork 0
/
UART.c
59 lines (57 loc) · 1.62 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
/*
* UART.c
*
* Created on: Nov 25, 2019
* Author: Ahmed Magdy
*/
#include"util.h"
#include"stdtypes.h"
#include "GPIO.h"
#include"UART .h"
void UART_Initialization(void){
SET_BIT(RCGCUART,3); //enable UART3
SET_BIT(RCGCGPIO,2); // enable clock to portC
unsigned long delay1_C=RCGCGPIO;
GPIOLOCK_C=0x4C4F434B; //UNLOCK PORTC
SET_BIT(GPIOCR_C,6); //Enable PC6,PC7 TO CONTROL ALTERNTIVE FUNC
SET_BIT(GPIOCR_C,7);
SET_BIT(GPIOAFSEL_C,6); //PC6 PC7 to alternative function (UART3)
SET_BIT(GPIOAFSEL_C,7);
SET_BIT(GPIOPCTL_C,24); //pins is working in UART mode
SET_BIT(GPIOPCTL_C,28);
SET_BIT(GPIODEN_C,6); //enable PC6,PC7
SET_BIT(GPIODEN_C,7);
SET_BIT(UARTIM,4); // to enable receive interrupt
SET_BIT(UARTIM,5); // to enable transmit interrupt
SET_BIT(EN1,27); //to enable the uart3 interrupt using NVIC
CLR_BIT(UARTCTL,0); //disable UART
UARTIBRD=104; //configuring the baud rate
UARTFBRD=11;
UARTLCRH=(0x3<<5); // start,, data(8-bit) ,, stop(1-bit),,no parity
SET_BIT(UARTLCRH,4); // enabling FIFO
CLR_BIT(UARTIFLS,1); //making FIFO transmission length = 14 bytes at a time
CLR_BIT(UARTIFLS,4); //making FIFO receive length = 2 bytes at a time
UARTCC=0x0;
SET_BIT(UARTCTL,0); // enabling UART
SET_BIT(UARTCTL,8); // enabling TX
SET_BIT(UARTCTL,9); //enabling RX
}
u8 read (void)
{
u8 res;
res=UARTDR;
return res;
}
void write (u8 x)
{
UARTDR=(x);
}
void write_string(u8 *ptr)
{
u8 i=0;
while (ptr[i] != '\0')
{
write(ptr[i]);
i++;
}
}