Vincent Belanger
/
APP
APP 1 S5.
Diff: UART.cpp
- Revision:
- 8:e38cd9e16055
- Parent:
- 6:ccdbd5923e37
--- a/UART.cpp Sun Jan 10 22:24:00 2016 +0000 +++ b/UART.cpp Mon Jan 11 01:25:29 2016 +0000 @@ -1,15 +1,26 @@ +#include <stdint.h> +#include "mbed.h" + #include "UART.h" #include "APP.h" +static Serial pc(USBTX, USBRX); void UARTInit(uint32_t baudrate) { uint32_t Fdiv; uint32_t pclkdiv, pclk; - LPC_SC->PCONP |= 1 << 25; // Activate UART3 in PCONP register. - pclkdiv = (LPC_SC->PCLKSEL1 >> 18) & 0x03; // Bits 18~19 are for UART3 - + unsigned int volatile* pconp = PCONP_REGISTER; + unsigned int volatile* pclksel1 = PCLKSEL1_REGISTER; + unsigned int volatile* pinsel0 = PINSEL0_REGISTER; + unsigned int volatile* u3lcr = U3LCR_REGISTER; + unsigned int volatile* u3dll = U3DLL_REGISTER; + unsigned int volatile* u3dlm = U3DLM_REGISTER; + + *pconp |= 1 << 25; // Activate UART3 in PCONP register. + pclkdiv = (*pclksel1 >> 18) & 0x03; // Bits 18~19 are for UART3 + switch (pclkdiv) { case 0x00: @@ -27,27 +38,35 @@ break; } - LPC_PINCON->PINSEL0 &= ~0x00000003; - LPC_PINCON->PINSEL0 |= 0x00000002; - - LPC_UART3->LCR = 0x83; // 8 bits, no Parity, 1 Stop bit, DLAB = 1 + *pinsel0 &= ~0x00000003; + *pinsel0 |= 0x00000002; + + *u3lcr = 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 + *u3dlm = Fdiv / 256; + *u3dll = Fdiv % 256; + *u3lcr = 0x03; // DLAB = 0 } void UARTSend(uint8_t byte) { - LPC_UART3->THR = byte; + unsigned int volatile* u3thr = U3THR_REGISTER; + *u3thr = byte; + + pc.printf("%c ", byte); } void UARTSend(uint8_t *buffer, uint32_t length) { + unsigned int volatile* u3thr = U3THR_REGISTER; + while (length != 0) { - LPC_UART3->THR = *buffer; + // pc.printf("%c ", *buffer); + *u3thr = *buffer; buffer++; length--; } + + // pc.printf("\r\n"); }