# LPC1768 Uart Baud Rate Problema

**URL:** <https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668>\
**Category:** Kernel\
**Created:** [August 26, 2013, 9:41pm UTC](https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668 "2013-08-26T21:41:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 26, 2013, 9:41pm UTC](https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668/1 "2013-08-26T21:41:14Z")

</div>

**[frehner](https://sourceforge.net/u/frehner/)** wrote on [Monday, August 26, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/762deee8/#dd5b):

Hello, there is a question: I be using Free-RTos and have created a task to iniciate Uart on 115200 baud rate, but however&nbsp; all I do&nbsp; on configurations registers can´t get right baud rate. For example, if I initiate Uart on 115200 I get 4800 on the terminal. I tried to implement the DLM and DLL starting a example code from hoan’s blog, but nothing works on Free-Rtos, without Free-Rtos works normally. Can someone help me on this simple problem?

Using Keil, FreeRTOS V6.1.0 and NPX LPC1768 microcontroller

Uart Init Code:

```
void Uart0_Init(uint32_t baudrate)
{
		uint32_t uClk;
		uint32_t rate16 = 16 * baudrate;
		uint32_t dval, mval;
		uint32_t dl;
		uint32_t rem;
	
		uClk = CLKPWR_GetPCLK (CLKPWR_PCLKSEL_UART0);
	
		rem = uClk % rate16;
		dval = uClk % rate16;
	
		if (dval > 0)
		{
				mval = rate16 / dval;
				dval = 1;
				// in case mval still bigger then 4 bits
				// no adjustment require
				if (mval > 12)
				{
					dval = 0;
				}
		}
		dval &= 0xf;
		mval &= 0xf;
		
		dl = uClk / (rate16 + rate16 *dval / mval);
		
			LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */
			LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */
		
			LPC_UART0->LCR = 0x83;
      LPC_UART0->DLM = (((dl) >> 8) & 0xFF);
      LPC_UART0->DLL = ((dl) & 0xFF);
      /* Then reset DLAB bit */
			LPC_UART0->LCR = 0x03; / */
			LPC_UART0->FCR = 0x06; 		
}
```

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 27, 2013, 8:09am UTC](https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668/2 "2013-08-27T08:09:04Z")

</div>

**[diptopal](https://sourceforge.net/u/diptopal/)** wrote on [Tuesday, August 27, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/762deee8/#ea3e):

Your UART implementation generally falls outside of FreeRTOS. Probably where you might be getting stuck is initiating the UART in a task. Have you tried initialising UART in your ‘main’ before creating your tasks and then using the UART in your tasks? I have not tried out 115200 on my LPC1768 based board, I work on 38400. But ideally if your UART works , theres no reason it should not work on FreeRTOS.&nbsp; Have you tried using the CMSIS libraries, makes your life far easier?&nbsp;  
Have you verified if your tasks are running properly on FreeRTOS? Are you on the Keil simulator or on a real hardware?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 27, 2013, 3:26pm UTC](https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668/3 "2013-08-27T15:26:05Z")

</div>

**[frehner](https://sourceforge.net/u/frehner/)** wrote on [Tuesday, August 27, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/762deee8/#4d36):

Hello Diptopal, now I be testing your recommendations and soon as possible I will tell you the results. Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 29, 2013, 8:53pm UTC](https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668/4 "2013-08-29T20:53:22Z")

</div>

**[frehner](https://sourceforge.net/u/frehner/)** wrote on [Thursday, August 29, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/762deee8/#aa1c):

~~Finally I get my project running. I followed your tips and had my LPC1768 running properly. All I done was starting of zero adding each kernel library from my working start project and then putting the UART\_Init function before the tasks.  
My Keil are simulating on a real hardware. Thank you very much.~~

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 29, 2013, 8:53pm UTC](https://forums.freertos.org/t/lpc1768-uart-baud-rate-problema/2668/5 "2013-08-29T20:53:48Z")

</div>

**[frehner](https://sourceforge.net/u/frehner/)** wrote on [Thursday, August 29, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/762deee8/#9d36):

Finally I get my project running. I followed your tips and had my LPC1768 running properly. All I done was starting of zero adding each kernel library from my working start project and then putting the UART\_Init function before the tasks.  
My Keil are simulating on a real hardware. Thank you very much.
