Simon Ford
/
serial_baudrate_dividers
Program to dump out dividers for a UART, after it being set up
Revision 0:9343a4c09e4d, committed 2010-10-13
- Comitter:
- simon
- Date:
- Wed Oct 13 10:43:43 2010 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 13 10:43:43 2010 +0000 @@ -0,0 +1,28 @@ +#include "mbed.h" + +DigitalOut myled(LED1); + +Serial s(p9, p10); + +int main() { + + // setup the baudrate to 4800 + s.baud(4800); + + // extract the resulting divider values that were setup + + LPC_UART3->LCR |= (1 << 7); // set LCR[DLAB] to get access to dividers + int dlm = LPC_UART3->DLM; + int dll = LPC_UART3->DLL; + int div = LPC_UART3->FDR & 0xF; + int mul = LPC_UART3->FDR >> 4; + LPC_UART3->LCR &= ~(1 << 7); // clear LCR[DLAB] + + int pclk = 96000000; + + // from LPC1768 User Manual, 14.4.12 : + float baudrate = pclk / (16.0 * (float)(256 * dlm + dll) * (1.0 + ((float)div / (float)mul))); + + printf("dlm = %d, dll = %d, div = %d, mul = %d\n", dlm, dll, div, mul); + printf("baudrate = %f\n", baudrate); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 13 10:43:43 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e