drtgddf

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
larryspaghetti
Date:
Mon Jan 11 21:09:20 2016 +0000
Parent:
0:aab1f335cf6b
Commit message:
f

Changed in this revision

UART.cpp Show annotated file Show diff for this revision Revisions of this file
UART.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r aab1f335cf6b -r 2b2be189b4db UART.cpp
--- a/UART.cpp	Mon Jan 11 19:10:09 2016 +0000
+++ b/UART.cpp	Mon Jan 11 21:09:20 2016 +0000
@@ -1,12 +1,23 @@
 #include "UART.h"
+#include "LPC17xx.h"
 
 UART::UART()
 {
+    PCOMP =  (int *)0x400FC0C4;
+    PCLKSEL0 = (int *)0x400FC1A8;
+    U0LCR = (int *)0x4000C00C;
+    U0DLL = (int *)0x4000C000;
+    U0DLM = (int *)0x4000C004;
+    U0FCR = (int *)0x4000C008;
+    PINSEL0 = (int *)0x4002C000;
     
-    //*PCLKSEL0 |= 0x000000C0;
+    
     //Donne acces aux registres DLL et DLM pour set le baud rate
     *U0LCR |= 0x00000080;
     
+    //On met le registre de PCLK_UART0 à 01
+    *PCLKSEL0 |= 0x00000080;
+    
     //On active les pins pour TXD0
     *PINSEL0 &= ~0x00000020;
     *PINSEL0 |= 0x00000010;
@@ -18,6 +29,4 @@
     *U0LCR |= 0x00000003;
     //1 Seul stop bit, pas de parite
     *U0LCR &= ~0x0000000C;
-    
-    
 }
\ No newline at end of file
diff -r aab1f335cf6b -r 2b2be189b4db UART.h
--- a/UART.h	Mon Jan 11 19:10:09 2016 +0000
+++ b/UART.h	Mon Jan 11 21:09:20 2016 +0000
@@ -2,7 +2,7 @@
 {
     public:
         //Le constructeur prend en parametre des valeurs de REGISTRES pour les pins, pas les "pin names"
-        UART(int registreTx, int registreRx);
+        UART();
         //Ecrit un caractere
         int putc(int c);
         //Sert a savoir si un bit peut etre ecrit dans le registre
@@ -11,22 +11,15 @@
     private:
         //Registre du POWER
         int * PCOMP;
-        PCOMP =  0x400FC0C4;
         //Registre du CLOCK
         int * PCLKSEL0;
-        PCLKSEL0 = 0x400FC1A8;
         //Registre pour le BAUD RATE
         int * U0LCR;
-        U0LCR = 0x4000C00C;
         //Registre pour le BAUD RATE
         int * U0DLL;
-        U0DLL = 0x4000C000;
         //Registre pour le BAUD RATE
         int * U0DLM;
-        U0DLM = 0x4000C004;
         //Registre du FIFO
         int * U0FCR;
-        U0FCR = 0x4000C008;
         int * PINSEL0;
-        PINSEL0 = 0x4002C000;
-}
\ No newline at end of file
+};
\ No newline at end of file
diff -r aab1f335cf6b -r 2b2be189b4db main.cpp
--- a/main.cpp	Mon Jan 11 19:10:09 2016 +0000
+++ b/main.cpp	Mon Jan 11 21:09:20 2016 +0000
@@ -1,8 +1,55 @@
 #include "mbed.h"
+#include "LPC17xx.h"
 
 
 int main() {
-    while(1) {
-        
+    UART3_init();
+    
+    UART3_putc('C');
+}
+
+void UART3_init()
+{
+    const uint32_t baudrate = 9600;
+    
+    //On "power on" le module UART3
+    LPC_SC->PCONP |= (1<<25);
+    
+    //On met le device clock a CPU CLOCK/1
+    LPC_SC->PCLKSEL1 &= ~(3<<18);
+    LPC_SC->PCLKSEL1 |= (1<<18);
+    
+    //Formule: registreValue = Clock du chip / (16*baudrate)
+    uint8_t dllRegValue = 96000000 / (16 * baudrate);
+    
+    //On set le bit DLAB a 1
+    LPC_UART3->LCR = (1 << 7);
+    //On donne la valeur au registre DLL pour que le baudrate soit 9600
+    LPC_UART3->DLL = dllRegValue;
+    
+    //8 bit de message, 1 bit de stop, pas de bit de parite
+    LPC_UART3->LCR = 3;
+    
+    //On allume le FIFO
+    LPC_UART3->FCR = 1;
+    
+    //Selection des pins pour UART3
+    LPC_PINCON->PINSEL0 |= 0x00000002;
+    
+    
+}
+
+void UART3_putc(char c)
+{
+    //Il faut attendre que le transfert soit fini pour envoyer un deuxieme caractere
+    LPC_UART3->THR = c;
+    
+    //Tant que le registre de transmiter n'est pas vide
+    while (true)
+    {
+        if (LPC_UART3->LSR & (1 << 5))
+        {
+            break;    
+        }
     }
-}
+}
\ No newline at end of file