<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Please help to find the error in the code in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542639#M7916</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gbm on Thu Jul 21 12:59:59 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually the formula used everywhere in examples for calculating UART divisor is suboptimal (to express it nicely). The better one should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fdiv = (((SystemCoreClock*LPC_SYSCON-&amp;gt;SYSAHBCLKDIV)/regVal)/16 + BAUD_RATE/2)/BAUD_RATE;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This provides proper rounding of the divisor and results in smaller baud rate errors.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jun 2016 01:48:48 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-16T01:48:48Z</dc:date>
    <item>
      <title>Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542633#M7910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by akhilpo on Tue Jul 19 19:13:03 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying implement UART communication. It worked fine when using the drivers in the NXP examples. But it when I tried to implement the 'UARTInit()' on my own, it is sending occasionally some wrong characters. I have refereed the Uart driver code and the datasheet, but still cant figure out what I am doing wrong. Please help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#ifdef __USE_CMSIS
#include "LPC11xx.h"
#endif

#include &amp;lt;cr_section_macros.h&amp;gt;
#include &amp;lt;NXP/crp.h&amp;gt;

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "uart.h"
// TODO: insert other definitions and declarations here

int main(void) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t key[1];
&amp;nbsp;&amp;nbsp;&amp;nbsp; key[0] = 'n';
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t fdiv, regVal;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //UARTInit(115200);
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_IOCON-&amp;gt;PIO1_6 |= 1;
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_IOCON-&amp;gt;PIO1_7 |= 1;

&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= 1&amp;lt;&amp;lt;12;
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_SYSCON-&amp;gt;UARTCLKDIV = 12;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //fdiv = 48/(16*12*115200);
&amp;nbsp;&amp;nbsp;&amp;nbsp; regVal = LPC_SYSCON-&amp;gt;UARTCLKDIV;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fdiv = (((SystemCoreClock*LPC_SYSCON-&amp;gt;SYSAHBCLKDIV)/regVal)/16)/115200 ;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*baud rate */


&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_UART-&amp;gt;LCR |= 1&amp;lt;&amp;lt;7;
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_UART-&amp;gt;DLM = fdiv/0x100;
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_UART-&amp;gt;DLL = fdiv%0x100;
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_UART-&amp;gt;LCR &amp;amp;= ~(1&amp;lt;&amp;lt;7);

&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_UART-&amp;gt;LCR = 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_UART-&amp;gt;FCR = 7;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fdiv = LPC_UART-&amp;gt;LSR;




&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UARTSend(key,1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}

&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542633#M7910</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542634#M7911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by NXP_Europe on Wed Jul 20 07:51:16 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi akhilpo,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It probably doesn't work because of the fdiv calculation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you indeed state:&lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;//fdiv = 48/(16*12*115200);&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN&gt;Assuming your SystemCoreClock*LPC_SYSCON-&amp;gt;SYSAHBCLKDIV = 48MHz, fdiv will be 2.17, which is a bit hard to handle for a uC and introduces a large baudrate error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd advice to keep the UARTCLKDIV @ 1 for now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542634#M7911</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542635#M7912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by akhilpo on Wed Jul 20 08:08:39 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;fdiv = (((SystemCoreClock*LPC_SYSCON-&amp;gt;SYSAHBCLKDIV)/regVal)/16)/115200 ;&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN&gt;I copied this right from the UARTInit definition in the uart.c driver file included in the example files. Then why does it work when I use the driver function and doesnt work when I try to do it myself? :/&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542635#M7912</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542636#M7913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Wed Jul 20 08:24:14 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: akhilpo&lt;/STRONG&gt;&lt;BR /&gt;Then why does it work when I use the driver function and doesnt work when I try to do it myself? &lt;SPAN class="lia-unicode-emoji" title=":confused_face:"&gt;&lt;LI-EMOJI id="lia_confused-face" title=":confused_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Because in the uart.c file it states:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; /* Enable UART clock */
&amp;nbsp; LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (1&amp;lt;&amp;lt;12);
&amp;nbsp; LPC_SYSCON-&amp;gt;UARTCLKDIV = 0x1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* divided by 1 */
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and you are setting UARTCLKDIV to 12 :eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you copy, copy wisely ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542636#M7913</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542637#M7914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by StephenHawkings on Wed Jul 20 10:02:59 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use an UARTCLK divider as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;48MHz / 115.200 = 416,67.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;UARTCLK must be 16xBaudrate =&amp;gt; 416,67 / 16 = 26,0417.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, only divider of 26 is possible.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;48MHz / 16 / 26 = 115.384,62 bps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is 100 / 115.200 * 115.384,62 = 100.16% or just a difference of 0,16% if I'm correct, and a very good result.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SH&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542637#M7914</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542638#M7915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by akhilpo on Wed Jul 20 18:52:00 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;:eek:Ooh silly mistakes again... its working fine now.. thanks for the calculations stephan.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542638#M7915</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Please help to find the error in the code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542639#M7916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gbm on Thu Jul 21 12:59:59 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually the formula used everywhere in examples for calculating UART divisor is suboptimal (to express it nicely). The better one should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fdiv = (((SystemCoreClock*LPC_SYSCON-&amp;gt;SYSAHBCLKDIV)/regVal)/16 + BAUD_RATE/2)/BAUD_RATE;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This provides proper rounding of the divisor and results in smaller baud rate errors.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:48:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Please-help-to-find-the-error-in-the-code/m-p/542639#M7916</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:48:48Z</dc:date>
    </item>
  </channel>
</rss>

