1 | const int idelay = 1000; //for delay
|
2 |
|
3 | unsigned long int* RCGCUART; //address of Rcgcuart
|
4 | unsigned long int* RCGCGPIO; //..
|
5 | unsigned long int* GPIOAFSEL; //..
|
6 | unsigned long int* GPIOPCTL; //..
|
7 | unsigned long int* UARTCTL; //..
|
8 | unsigned long int* UARTIBRD; //..
|
9 | unsigned long int* UARTFBRD; //..
|
10 | unsigned long int* UARTLCRH; //..
|
11 | unsigned long int* PPUART; //..
|
12 |
|
13 | //1.Enable UART via RCGCUART Register page 333
|
14 | //Base address 0x400F.E000 is a System Control Register as seen on page 97
|
15 | //Offset address 0x618 Adress for the RCGCUART Register
|
16 | //Addition gives the adresse: 0x400F.E618
|
17 | //to set the UART4 the fifth Bit must be set.
|
18 | RCGCUART = 0x400FE618;
|
19 | //*RCGCUART &= 0xEF; // Disable UART4
|
20 | *RCGCUART |= 0x10; //Enable UART4
|
21 | delay_ms(idelay);
|
22 |
|
23 | //2.Enable the clock to the appropiate GPIO module via RCGCGPIO page 328
|
24 | //The Base address is 0x400F.E000
|
25 | //The offset address is 0x608
|
26 | //That gives: 0x400F.E608
|
27 | //PORTC is the third Bit so : 0x4 = 0b100
|
28 | RCGCGPIO = 0x400FE608;
|
29 | *RCGCGPIO |= 0x4;
|
30 | delay_ms(idelay);
|
31 |
|
32 | //3.Setting the GPIO AFSEL for the appropiate PINs
|
33 | //GPIO PORTC APB Base is on 0x4000.6000
|
34 | //Offset is 0x420 -> that gives in total 0x4000.6420
|
35 | //PORTC4/5 Uart4 is on Pin 36/35
|
36 | GPIOAFSEL = 0x40006420;
|
37 | *GPIOAFSEL |= 0x30;
|
38 | delay_ms(idelay);
|
39 |
|
40 | //4.Configure Current level and slew rate control
|
41 | //2mA default
|
42 | //Slew rate default no slew rate control
|
43 |
|
44 | //5.Configure PMCn fields in the GPIOPCTL register to asign the UART Signals to the appropiate pin
|
45 | //Base of the GPIOPCTL register is 0x4000.6000 for PORTC APB
|
46 | //The offset is 0x52C
|
47 | //That gives 0x4000652C
|
48 | //Write the appropiate value for UART4 into the Pin4 and Pin5 fields. Should be 0x2;
|
49 | GPIOPCTL = 0x4000652C;
|
50 | *GPIOPCTL |= 0x00110000;
|
51 | delay_ms(idelay);
|
52 |
|
53 | //Configuration of the UART:
|
54 | //1.Disable UART
|
55 | //Disabling by resetting UARTEN in the UARTCTL register
|
56 | //Base address is 0x4001.0000
|
57 | //The offset address is 0x030
|
58 | //UARTEN is the first Bit
|
59 | UARTCTL = 0x40010030;
|
60 | *UARTCTL &= 0xFFFFFFFE;
|
61 | *UARTCTL |= 0x300;
|
62 | delay_ms(idelay);
|
63 |
|
64 | //2.BAUDRATE
|
65 | //BRD = 16000000 / (16 * 115200) = 8,6805°
|
66 | //UARTFBRD = integer(0,6805 * 64 + 0.5) = 44
|
67 | //UARTIBRD base is on 0x4001.0000
|
68 | //and offset is 0x024
|
69 | //UARTFBRD base is on 0x4001.0000
|
70 | //and offset is 0x028
|
71 | UARTIBRD = 0x40010024;
|
72 | *UARTIBRD |= 0x8;
|
73 | UARTFBRD = 0x40010028;
|
74 | *UARTFBRD |= 0x2C;
|
75 | delay_ms(idelay);
|
76 |
|
77 | //3.data length, parity and stop bit
|
78 | //This is set in the UARTLCRH register
|
79 | //The base address is 0x4001.0000
|
80 | //The offset address is 0x02C
|
81 | // Bit 5 and 6 are the data length. 0x3 is 8 bits.
|
82 | // no parity and 1 stop bit default
|
83 | UARTLCRH = 0x4001002C;
|
84 | *UARTLCRH |= 0x60; //0b01100000
|
85 | delay_ms(idelay);
|
86 |
|
87 | //4.Enable the UART4 again
|
88 | UARTCTL = 0x40010030;
|
89 | *UARTCTL |= 0x00000001;
|
90 | delay_ms(idelay);
|
91 |
|
92 | //Transmit on UARTDR register
|
93 | //Base address for UART4 0x4001.0000
|
94 | //offset address is 0x00
|
95 | unsigned long int* UARTDR = 0x40010000;
|
96 | *UARTDR |= 0x41; //Letter A
|