EmbeddedRelated.com
Forums

UART LPC2138

Started by dsourgen August 1, 2006
Hello,

I am new at LPC2000.
I have downloaded eval version of KEIL vision3. I will have to
develop an application with LPC2138.
After studying examples, I am trying to create a simple project that
displays a character on serial 2 of the simulator (This is very
close to the "Hello" example).
The program should display a single character once only.
Here is the code (very simple):

---------------------------------
#include /* prototype declarations for I/O functions */
#include /* LPC213x definitions */

void init_uart1(void);

/****************/
/* main program */
/****************/
int main (void) {
init_uart1();
putchar('a');
return(0);
}

/***********************/
/* fonction init_uart1 */
/***********************/
void init_uart1(void) { /* initialize the serial interface */
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 78; /* 9600 Baud Rate @ 12MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}
--------------------------------

When executing under simulator, instead of displaying once the
character 'a', the program seems to be in an infinite loop and
indefinitely displays characters 'a'.

Can anyone tell what's wrong? Is it a problem in the program, in the
UART configuration, in the compilation process configuration, or in
the simulator configuration?

Thank you,

dsourgen



An Engineer's Guide to the LPC2100 Series

Where does main() return to?
Is main() being called again from wherever that is?

-- Dave
--- In l..., "dsourgen" wrote:
>
> Hello,
>
> I am new at LPC2000.
> I have downloaded eval version of KEIL vision3. I will have to
> develop an application with LPC2138.
> After studying examples, I am trying to create a simple project that
> displays a character on serial 2 of the simulator (This is very
> close to the "Hello" example).
> The program should display a single character once only.
> Here is the code (very simple):
>
> ---------------------------------
> #include /* prototype declarations for I/O functions */
> #include /* LPC213x definitions */
>
> void init_uart1(void);
>
> /****************/
> /* main program */
> /****************/
> int main (void) {
> init_uart1();
> putchar('a');
> return(0);
> }
>
> /***********************/
> /* fonction init_uart1 */
> /***********************/
> void init_uart1(void) { /* initialize the serial interface */
> PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
> U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
> U1DLL = 78; /* 9600 Baud Rate @ 12MHz VPB Clock */
> U1LCR = 0x03; /* DLAB = 0 */
> }
> --------------------------------
>
> When executing under simulator, instead of displaying once the
> character 'a', the program seems to be in an infinite loop and
> indefinitely displays characters 'a'.
>
> Can anyone tell what's wrong? Is it a problem in the program, in the
> UART configuration, in the compilation process configuration, or in
> the simulator configuration?
>
> Thank you,
>
> dsourgen
>



Hello Dave,

You are right: part of the solution is there.
If I write:

int main (void) {
init_uart1();
putchar('a');
while(1){};
}

instead of:

int main (void) {
init_uart1();
putchar('a');
return(0);
}

Then, the program works. It outputs character 'a' once.

But this is only part of the solution. What I really want to do is
to understand how to properly output characters and strings:

1/ The following main() function outputs nothing:

int main (void) {
init_uart1();
printf("hello!");
while(1){};
}

2/ The following main() function outputs undefinitely "hello":

int main (void) {
init_uart1();
puts("hello\n");
while(1){};
}

3/ The following main() function outputs undefinitely 'a':

int main (void) {
init_uart1();
putchar('a');
printf("hello!");
while(1){};
}

Could you please tell me if these are basic problems of beginners in
LPC21xx programmation and where may I find accurate information
about this?
thank you

dsourgen
--- In l..., "derbaier" wrote:
>
>
> Where does main() return to?
> Is main() being called again from wherever that is?
>
> -- Dave
>
>
> --- In l..., "dsourgen" wrote:
> >
> > Hello,
> >
> > I am new at LPC2000.
> > I have downloaded eval version of KEIL vision3. I will have to
> > develop an application with LPC2138.
> > After studying examples, I am trying to create a simple project
that
> > displays a character on serial 2 of the simulator (This is very
> > close to the "Hello" example).
> > The program should display a single character once only.
> > Here is the code (very simple):
> >
> > -----------------------------
----
> > #include /* prototype declarations for I/O
functions */
> > #include /* LPC213x
definitions */
> >
> > void init_uart1(void);
> >
> > /****************/
> > /* main program */
> > /****************/
> > int main (void) {
> > init_uart1();
> > putchar('a');
> > return(0);
> > }
> >
> > /***********************/
> > /* fonction init_uart1 */
> > /***********************/
> > void init_uart1(void) { /* initialize the serial
interface */
> > PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
> > U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
> > U1DLL = 78; /* 9600 Baud Rate @ 12MHz VPB Clock */
> > U1LCR = 0x03; /* DLAB = 0 */
> > }
> > -----------------------------
---
> >
> > When executing under simulator, instead of displaying once the
> > character 'a', the program seems to be in an infinite loop and
> > indefinitely displays characters 'a'.
> >
> > Can anyone tell what's wrong? Is it a problem in the program, in
the
> > UART configuration, in the compilation process configuration, or
in
> > the simulator configuration?
> >
> > Thank you,
> >
> > dsourgen
>