APP 1 S5.

Dependencies:   mbed

Revision:
9:f35a5cde61a3
Parent:
6:ccdbd5923e37
Child:
10:f58cbb203c59
diff -r ccdbd5923e37 -r f35a5cde61a3 UART.cpp
--- a/UART.cpp	Sun Jan 10 22:24:00 2016 +0000
+++ b/UART.cpp	Mon Jan 11 19:07:16 2016 +0000
@@ -1,40 +1,43 @@
+#include <stdint.h>
+
 #include "UART.h"
 #include "APP.h"
-
+#include "LPC17xx.h"
 
 void UARTInit(uint32_t baudrate)
 {
     uint32_t Fdiv;
     uint32_t pclkdiv, pclk;
-    
+
+    LPC_PINCON->PINSEL0 &= ~0x00000003;
+    LPC_PINCON->PINSEL0 |= 0x00000002;
+
     LPC_SC->PCONP |= 1 << 25; // Activate UART3 in PCONP register.
     pclkdiv = (LPC_SC->PCLKSEL1 >> 18) & 0x03; // Bits 18~19 are for UART3
-    
+
     switch (pclkdiv)
     {
         case 0x00:
         default:
-            pclk = SYSTEM_CLOCK_FREQUENCY/4;
+            pclk = SystemCoreClock/4;
             break;
         case 0x01:
-            pclk = SYSTEM_CLOCK_FREQUENCY;
+            pclk = SystemCoreClock;
             break;
         case 0x02:
-            pclk = SYSTEM_CLOCK_FREQUENCY/2;
+            pclk = SystemCoreClock/2;
             break;
         case 0x03:
-            pclk = SYSTEM_CLOCK_FREQUENCY/8;
+            pclk = SystemCoreClock/8;
             break;
     }
-
-    LPC_PINCON->PINSEL0 &= ~0x00000003;
-    LPC_PINCON->PINSEL0 |= 0x00000002;
-    
+   
     LPC_UART3->LCR = 0x83;         // 8 bits, no Parity, 1 Stop bit, DLAB = 1
     Fdiv = (pclk / 16) / baudrate; // baud rate
     LPC_UART3->DLM = Fdiv / 256;
     LPC_UART3->DLL = Fdiv % 256;
     LPC_UART3->LCR = 0x03;         // DLAB = 0
+    LPC_UART3->FCR = 0x07;
 }
 
 void UARTSend(uint8_t byte)