OK, so I’m going down the road of figuring out what registers have to be changed and using a baud calculator I found on line for NXP LPC2000 UART Baudrate Calculator (Fraction Divide Register)
See http://prototalk.net/forums/showthread.php?t=11
I can find the address for FDR,DLM,DLL (these are UART registers)
Register CCLKCFG = new Register(0xE01FC104);
Register U0FDR = new Register(0xE000C028);
Register U0DLM = new Register(0xE000C004);
Register U0DLL = new Register(0xE000C000);
// set the clock to 24Mhz
CCLKCFG.Write(11);
//write the UART0 registers
U0FDR.Write(193);
U0DLM.Write(0);
U0DLL.Write(12);
So when I set the 3 registers, along with the change to 24Mhz, CCLKCFG.Write(11);
I still get garbage out…
From the links you gave it seems that only certain baud rates are possible. To get as close as possible to 115200 values are suggested but it seems that you can’t achieve that specific value exactly.
Lower values like 9600 can be achieved exact, 115200 not. :’(
Or you have to play with the clock frequency: A good guess would be to take a multiple of 115200 if that is possible (2340000 instead of 24000000).
Finally figured it out how to reconfigure the UARTs to work after slowing down processor clock.
We discovered that to access the various UART baud rate divider registers, the UART must be opened!!! If you try to write values to the registers before the UART is open, they don’t change. Only after the port is open will writes to the registers be valid. Note: For certain registers, one needs to set DLAB to 1, but this is documented in the LPC2387 user manual.
We had a similar issue with UART data receive event handlers which didn’t work if they were declared before the port is opened. You can only declare them after the port is open.
I’m guessing this is a managed code issue which those who grew up in the assembler world are not familiar with.
If anybody is interested in some sample code, please advise.
Here is the code to slow down the system clock by 1/3 (72Mhz ->24Mhz)
and set the UART0 baud to 115200… You have to open the port before you can change the FDR and DLL/DLM registers, and you have to raise DLAB to read/write the DLL/DLM registers.
Register CCLKCFG = new Register(0xE01FC104);
Register U0FDR = new Register(0xE000C028);
Register U0DLM = new Register(0xE000C004);
Register U0DLL = new Register(0xE000C000);
Register U0LCR = new Register(0xE000C00C); //DLAB - B:7
UART = new SerialPort("COM1", 115200); //using teraterm and the fez usb->RJ-11
UART.Open();
CCLKCFG.Write(11); // 24Mhz or 1/3
U0LCR.SetBits(1 << 7); //Raise DLAB
U0DLM.Write(0); //115200 baud
U0DLL.Write(2); //115200 baud
U0LCR.ClearBits(1 << 7); //Lower DLAB
U0FDR.Write(133); //115200 baud
UART.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
The Transmit side is working correctly,
However, the UART0 is not receiving the correct data,
If I send out ‘U’ = 0x55, I receive 2 bytes back ‘C3 B0’
Does anybody know why the transmit works, but not the receive? ???