Alexandre Lemay / Mbed 2 deprecated APP1_s5_A17

Dependencies:   mbed MMA8452

CommUART.h

Committer:
ThierryLeonard
Date:
2017-09-05
Revision:
9:b9ac1d914762
Parent:
7:b1b4db3eedb4
Child:
11:09317efe9bb5

File content as of revision 9:b9ac1d914762:

#ifndef COMMUART_H
#define COMMUART_H


#include "mbed.h"
#include "LPC17xx.h"

class CommUART3
{
public:
    CommUART3()
    {
        // Power 
        LPC_SC->PCONP |=  (1 << 25) ;//0x400F C0C4  -> PCUART3
        // Peripheral clock selection -> CCLK
        
        // DLab enable divide latch
        LPC_UART3->LCR |= (1 << 7);
        
        //Default Baud rate of 9600 in serial segment
        // MSB of baud rate divisor
        LPC_UART3->DLM = 0x2;
        // MLB of baud rate divisor
        LPC_UART3->DLL = 0x71;
        
        // want 8-bit characters
        LPC_UART3->LCR = 3;
        
        // Enable FIFO
        LPC_UART3->FCR = 1;
        
        // PINSEL0 1:0 : mode p9 -> 
        LPC_PINCON->PINSEL0 &= ~3;
        LPC_PINCON->PINSEL0 |= 2;
        LPC_SC->PCLKSEL1 &=  ~ (3 << 18  ) ; // clear the bits 18-19
        LPC_SC->PCLKSEL1 |=  1 << 18 ;//0x400F C1AC -> PCLK_UART3 =01
    
    }
    
    void write(char ch)
    {
        LPC_UART3->TER = 0x80;
        Serial pc(USBTX, USBRX); 
        pc.printf("%c", ch);
        LPC_UART3->THR = ch;
    }
    void write(char* ch, int length, char* unused, int unused2)
    {
        Serial pc(USBTX, USBRX); 
        pc.printf("rip");
        for(int i = 0 ; i < length ; i ++)
        {
            write(ch[i]);
        } 
    }
    

private:    
};




#endif