EmbDev.net

Forum: ARM programming with GCC/GNU tools an uart problem from a newbie


von Adem K. (swer)


Rate this post
useful
not useful
Hello;

I just wanted to see a simple output before going further and chose the
code below from application note AN10369.As you see,I modified the code
for my board . My problem is that it gives a different output that what
I programmed.

the xtall value on the board is 14.7456Mhz.

Please give me a hand !! thanks
************************************************************************ 
********


#include <LPC21xx.h>
void Initialize(void);

/* Macro Definitions */
#define TEMT      (1<<6)
#define LINE_FEED    0xA
#define CARRIAGE_RET    0xD


/************************* MAIN *************************/
int main()  {
    int i;
    char c[]="Philips LPC";
    Initialize() ;
    /* Print forever */

    while(1){
        IOCLR0= 1<<31;    //led on
    i=0;
    /* Keep Transmitting until Null character('\0') is reached */

    while(c[i]) {
    U0THR=c[i];
    i++;    }

    U0THR=LINE_FEED;
    U0THR=CARRIAGE_RET;
    /* Wait till U0THR and U0TSR are both empty */
    while(!(U0LSR & TEMT)){}
    IOSET0= 1<<31;        //led off
    }
}
/*************** System Initialization ***************/
void Initialize() {
    IODIR0 = 0x80000000;

    /* Initialize Pin Select Block for Tx and Rx */
    PINSEL0=0x5;
    /* Enable FIFO's and reset them */
    U0FCR=0x7;
    /* Set DLAB and word length set to 8bits */
    U0LCR=0x83;
    /* Baud rate set to 9600 */
    U0DLL=0x18;
    U0DLM=0x00;
    /* Clear DLAB */
    U0LCR=0x3;
}
/*********************************************************/

von Clifford S. (clifford)


Rate this post
useful
not useful
Adem Kaya wrote:
>My problem is that it gives a different output that what
> I programmed.
So what output did you get!?


>
>     while(c[i]) {
>     U0THR=c[i];
>     i++;    }
>
I checked the app note (a link would have saved me some trouble), and
this is the code, but it does not look right to me, it places characters
into the register without checking whether the previous character has
been processed. I would need to check the data sheet to be sure that is
wrong, but I'd be suspicious.

Clifford

von Adem K. (swer)


Rate this post
useful
not useful
Clifford Slocombe wrote:
> Adem Kaya wrote:
>>My problem is that it gives a different output that what
>> I programmed.
> So what output did you get!?
>
>
>>
>>     while(c[i]) {
>>     U0THR=c[i];
>>     i++;    }
>>
> I checked the app note (a link would have saved me some trouble), and
> this is the code, but it does not look right to me, it places characters
> into the register without checking whether the previous character has
> been processed. I would need to check the data sheet to be sure that is
> wrong, but I'd be suspicious.
>
> Clifford

It gives some output but they are totally nonsense ! I have never seen
"Philips LPC" line at output.

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
> It gives some output but they are totally nonsense ! I have never seen
> "Philips LPC" line at output.

If "nonsense" gets send the problem is most probably caused by a wrong
assumption of the UART PCLK and so the Baud-Registers do not match the
expected settings.

You did not even write which controller you use so it's difficult to
help since the "default" clocking is not the same for also LPCs. Check
the startup-code, maybe there are some settings for the clocking-system
inside (PLL, PCLK-Dividers etc).

If it's a "older" LPC (not LPC23xx/24xx) and you do not set up anything
in PLL or PCLK-Dividers you may try the setting 38400 instead of 9600 in
your terminal program. This should match UDL 0x18 at PCLK 14,7..MHz IRC.

For your simple example with a few characters the FIFO might offer
enough buffering. If you will send more characters than the UART FIFO
can hold make sure to check if the FIFO is not full before sending as
Clifford already suggested.

von Adem K. (swer)


Rate this post
useful
not useful
Martin Thomas wrote:
>> It gives some output but they are totally nonsense ! I have never seen
>> "Philips LPC" line at output.
>
> If "nonsense" gets send the problem is most probably caused by a wrong
> assumption of the UART PCLK and so the Baud-Registers do not match the
> expected settings.
>
> You did not even write which controller you use so it's difficult to
> help since the "default" clocking is not the same for also LPCs. Check
> the startup-code, maybe there are some settings for the clocking-system
> inside (PLL, PCLK-Dividers etc).
>
> If it's a "older" LPC (not LPC23xx/24xx) and you do not set up anything
> in PLL or PCLK-Dividers you may try the setting 38400 instead of 9600 in
> your terminal program. This should match UDL 0x18 at PCLK 14,7..MHz IRC.
>
> For your simple example with a few characters the FIFO might offer
> enough buffering. If you will send more characters than the UART FIFO
> can hold make sure to check if the FIFO is not full before sending as
> Clifford already suggested.


I am sorry, I thought I wrote that. I use lpc2132 and keil uvision3.I
have compiled a few example, and they worked well.I mean I don't have
any problem my eval board or stuff like that.

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
Adem Kaya wrote:
> I am sorry, I thought I wrote that. I use lpc2132 and keil uvision3.I
> have compiled a few example, and they worked well.I mean I don't have
> any problem my eval board or stuff like that.

Do you use uVision as IDE for a GNU-Toolchain or the Realview Tools that
come with MDK-ARM?

I expect that use are using the startup-code-template from Keil for
Realview which the IDE offers to copy in new projects (startup.s). The
one for LPC213x has functions to setup PLL and VPB. I still think that
your problems is cause by wrong settings of the clock-sources and
dividers.

- The clocking-system is explained in the manual.
- Learn how XTAL, PLL, VPB and UART-Prescalers interact and other "stuff
like that"
- Read the description on UART baud-settings in the manual
- Learn what is done during the startup.
- In the Keil startup-code there are some comments and the IDE offers a
wizard-like tool to change settings in the startup assembler-file.
- You may use the uVision Simulator to verify your setup of
clock-sources and UART

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.