Program to dump out dividers for a UART, after it being set up

Dependencies:   mbed

Committer:
simon
Date:
Wed Oct 13 10:43:43 2010 +0000
Revision:
0:9343a4c09e4d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:9343a4c09e4d 1 #include "mbed.h"
simon 0:9343a4c09e4d 2
simon 0:9343a4c09e4d 3 DigitalOut myled(LED1);
simon 0:9343a4c09e4d 4
simon 0:9343a4c09e4d 5 Serial s(p9, p10);
simon 0:9343a4c09e4d 6
simon 0:9343a4c09e4d 7 int main() {
simon 0:9343a4c09e4d 8
simon 0:9343a4c09e4d 9 // setup the baudrate to 4800
simon 0:9343a4c09e4d 10 s.baud(4800);
simon 0:9343a4c09e4d 11
simon 0:9343a4c09e4d 12 // extract the resulting divider values that were setup
simon 0:9343a4c09e4d 13
simon 0:9343a4c09e4d 14 LPC_UART3->LCR |= (1 << 7); // set LCR[DLAB] to get access to dividers
simon 0:9343a4c09e4d 15 int dlm = LPC_UART3->DLM;
simon 0:9343a4c09e4d 16 int dll = LPC_UART3->DLL;
simon 0:9343a4c09e4d 17 int div = LPC_UART3->FDR & 0xF;
simon 0:9343a4c09e4d 18 int mul = LPC_UART3->FDR >> 4;
simon 0:9343a4c09e4d 19 LPC_UART3->LCR &= ~(1 << 7); // clear LCR[DLAB]
simon 0:9343a4c09e4d 20
simon 0:9343a4c09e4d 21 int pclk = 96000000;
simon 0:9343a4c09e4d 22
simon 0:9343a4c09e4d 23 // from LPC1768 User Manual, 14.4.12 :
simon 0:9343a4c09e4d 24 float baudrate = pclk / (16.0 * (float)(256 * dlm + dll) * (1.0 + ((float)div / (float)mul)));
simon 0:9343a4c09e4d 25
simon 0:9343a4c09e4d 26 printf("dlm = %d, dll = %d, div = %d, mul = %d\n", dlm, dll, div, mul);
simon 0:9343a4c09e4d 27 printf("baudrate = %f\n", baudrate);
simon 0:9343a4c09e4d 28 }