EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LPC2378 UART 1 problem!!!

Started by DeV March 13, 2012
hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
communicate...im having problem in receiving data...wat i want to do is
till valid data is not available the lcd will display "no data"...only wen
some data EXCEPT Carriage Return is sent, it will display "data
entered"...now once the Carriage Return key is pressed the lcd will display
"Carriage Return" till again a new character is received and the process is
repeated...

but wat im getting is that everything is working ok untill carriage return
key...once i press the carriage return key the loop is entered only once
and the complete process stops!! Thanks in advance!!

int main ()
{
char *rec;
PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
PINSEL0 |= 0X40000000;//Select Pins for PWM1.6

PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
U1LCR = 0X83;
U1DLL = 4;
U1DLM = 0;
U1FDR = 0X00000085;

U1FCR = 7;

PCONP |= (1<<3);

InitLcd();

while(1)
{
if ((U1LSR & 1) == 1)
{
U1LCR &= 0x7F;

while(U1RBR == 13)
{
LCDClearScreen();
U1LCR &= 0x7F;
LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
*rec = U1RBR;
rec++;
U1LCR &= 0x7F;
}
LCDClearScreen();
LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
U1LCR |= 0x80;
}

else
{
LCDClearScreen();
LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
}
}
}


An Engineer's Guide to the LPC2100 Series

You have created a char pointer *rec, but have not initialized it, it will
be on the stack as it's local and probably zero since the startup code
usually zero's memory.

When a CR is pressed you write to memory using it then increment it.

It's likely that writing to memory using an uninitialized pointer is
crashing the processor at that point.

Regards

Phil.

From: l... [mailto:l...] On Behalf Of
DeV
Sent: 13 March 2012 08:22
To: l...
Subject: [lpc2000] LPC2378 UART 1 problem!!!

hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
communicate...im having problem in receiving data...wat i want to do is
till valid data is not available the lcd will display "no data"...only wen
some data EXCEPT Carriage Return is sent, it will display "data
entered"...now once the Carriage Return key is pressed the lcd will display
"Carriage Return" till again a new character is received and the process is
repeated...

but wat im getting is that everything is working ok untill carriage return
key...once i press the carriage return key the loop is entered only once
and the complete process stops!! Thanks in advance!!

int main ()
{
char *rec;
PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
PINSEL0 |= 0X40000000;//Select Pins for PWM1.6

PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
PINSEL1 |= 0X00000001;//Select Pins for PWM1.6

U1LCR = 0X83;
U1DLL = 4;
U1DLM = 0;
U1FDR = 0X00000085;

U1FCR = 7;

PCONP |= (1<<3);

InitLcd();

while(1)
{
if ((U1LSR & 1) == 1)
{
U1LCR &= 0x7F;

while(U1RBR == 13)
{
LCDClearScreen();
U1LCR &= 0x7F;
LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
*rec = U1RBR;
rec++;
U1LCR &= 0x7F;
}
LCDClearScreen();
LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
U1LCR |= 0x80;
}

else
{
LCDClearScreen();
LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
}
}
}





Actually, it is slightly worse, as automatics are not usually zeroed on
startup, or at least I haven't seen a compiler do this, unless it is also
declared as static, so it could point to anything.

Mike
-----Original Message-----
From: l... [mailto:l...]On Behalf
Of Phil Young
Sent: Tuesday, March 13, 2012 1:19 PM
To: l...
Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
You have created a char pointer *rec, but have not initialized it, it will
be on the stack as it's local and probably zero since the startup code
usually zero's memory.

When a CR is pressed you write to memory using it then increment it.

It's likely that writing to memory using an uninitialized pointer is
crashing the processor at that point.

Regards

Phil.

From: l... [mailto:l...] On Behalf Of
DeV
Sent: 13 March 2012 08:22
To: l...
Subject: [lpc2000] LPC2378 UART 1 problem!!!

hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
communicate...im having problem in receiving data...wat i want to do is
till valid data is not available the lcd will display "no data"...only wen
some data EXCEPT Carriage Return is sent, it will display "data
entered"...now once the Carriage Return key is pressed the lcd will display
"Carriage Return" till again a new character is received and the process is
repeated...

but wat im getting is that everything is working ok untill carriage return
key...once i press the carriage return key the loop is entered only once
and the complete process stops!! Thanks in advance!!

int main ()
{
char *rec;
PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
PINSEL0 |= 0X40000000;//Select Pins for PWM1.6

PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
PINSEL1 |= 0X00000001;//Select Pins for PWM1.6

U1LCR = 0X83;
U1DLL = 4;
U1DLM = 0;
U1FDR = 0X00000085;

U1FCR = 7;

PCONP |= (1<<3);

InitLcd();

while(1)
{
if ((U1LSR & 1) == 1)
{
U1LCR &= 0x7F;

while(U1RBR == 13)
{
LCDClearScreen();
U1LCR &= 0x7F;
LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
*rec = U1RBR;
rec++;
U1LCR &= 0x7F;
}
LCDClearScreen();
LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
U1LCR |= 0x80;
}

else
{
LCDClearScreen();
LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
}
}
}





thanks guys for your reply...im still a begginer in c program...hence, i
request you if you can make the required changes in my program itself for
my better understanding...i tried wat u told but still the scenario remains
the same...pls help me..

On Wed, Mar 14, 2012 at 9:15 AM, Michael Anton wrote:

> **
> Actually, it is slightly worse, as automatics are not usually zeroed on
> startup, or at least I haven't seen a compiler do this, unless it is also
> declared as static, so it could point to anything.
>
> Mike
> -----Original Message-----
> From: l... [mailto:l...]On Behalf
> Of Phil Young
> Sent: Tuesday, March 13, 2012 1:19 PM
> To: l...
> Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
>
> You have created a char pointer *rec, but have not initialized it, it will
> be on the stack as it's local and probably zero since the startup code
> usually zero's memory.
>
> When a CR is pressed you write to memory using it then increment it.
>
> It's likely that writing to memory using an uninitialized pointer is
> crashing the processor at that point.
>
> Regards
>
> Phil.
>
> From: l... [mailto:l...] On Behalf
> Of
> DeV
> Sent: 13 March 2012 08:22
> To: l...
> Subject: [lpc2000] LPC2378 UART 1 problem!!!
>
> hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
> communicate...im having problem in receiving data...wat i want to do is
> till valid data is not available the lcd will display "no data"...only wen
> some data EXCEPT Carriage Return is sent, it will display "data
> entered"...now once the Carriage Return key is pressed the lcd will display
> "Carriage Return" till again a new character is received and the process is
> repeated...
>
> but wat im getting is that everything is working ok untill carriage return
> key...once i press the carriage return key the loop is entered only once
> and the complete process stops!! Thanks in advance!!
>
> int main ()
> {
> char *rec;
> PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
>
> PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
>
> U1LCR = 0X83;
> U1DLL = 4;
> U1DLM = 0;
> U1FDR = 0X00000085;
>
> U1FCR = 7;
>
> PCONP |= (1<<3);
>
> InitLcd();
>
> while(1)
> {
> if ((U1LSR & 1) == 1)
> {
> U1LCR &= 0x7F;
>
> while(U1RBR == 13)
> {
> LCDClearScreen();
> U1LCR &= 0x7F;
> LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
> *rec = U1RBR;
> rec++;
> U1LCR &= 0x7F;
> }
> LCDClearScreen();
> LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
> U1LCR |= 0x80;
> }
>
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
> }
> }
> }
>
>
>
>
>
>
Hi Dev,

I'm not sure what you're trying to do with rec, just comment out the lines
that use it.

Or declare

char rec;

and

rec = U1RBR;

since it looks like all you are trying to do is discard the carriage return.

Regards

Phil.

From: l... [mailto:l...] On Behalf Of
Michael Anton
Sent: 14 March 2012 05:15
To: l...
Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!

Actually, it is slightly worse, as automatics are not usually zeroed on
startup, or at least I haven't seen a compiler do this, unless it is also
declared as static, so it could point to anything.

Mike

-----Original Message-----
From: l...
[mailto:l... ]On
Behalf
Of Phil Young
Sent: Tuesday, March 13, 2012 1:19 PM
To: l...
Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!

You have created a char pointer *rec, but have not initialized it, it will
be on the stack as it's local and probably zero since the startup code
usually zero's memory.

When a CR is pressed you write to memory using it then increment it.

It's likely that writing to memory using an uninitialized pointer is
crashing the processor at that point.

Regards

Phil.

From: l...
[mailto:l... ] On
Behalf Of
DeV
Sent: 13 March 2012 08:22
To: l...
Subject: [lpc2000] LPC2378 UART 1 problem!!!

hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
communicate...im having problem in receiving data...wat i want to do is
till valid data is not available the lcd will display "no data"...only wen
some data EXCEPT Carriage Return is sent, it will display "data
entered"...now once the Carriage Return key is pressed the lcd will display
"Carriage Return" till again a new character is received and the process is
repeated...

but wat im getting is that everything is working ok untill carriage return
key...once i press the carriage return key the loop is entered only once
and the complete process stops!! Thanks in advance!!

int main ()
{
char *rec;
PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
PINSEL0 |= 0X40000000;//Select Pins for PWM1.6

PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
PINSEL1 |= 0X00000001;//Select Pins for PWM1.6

U1LCR = 0X83;
U1DLL = 4;
U1DLM = 0;
U1FDR = 0X00000085;

U1FCR = 7;

PCONP |= (1<<3);

InitLcd();

while(1)
{
if ((U1LSR & 1) == 1)
{
U1LCR &= 0x7F;

while(U1RBR == 13)
{
LCDClearScreen();
U1LCR &= 0x7F;
LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
*rec = U1RBR;
rec++;
U1LCR &= 0x7F;
}
LCDClearScreen();
LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
U1LCR |= 0x80;
}

else
{
LCDClearScreen();
LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
}
}
}





Hi Phil,

U1RBR is the receiver register of uart1..so it stores the last byte
received..now wat i want to do is that using hyper terminal on my pc, i
want to send a string...e.g.e hello...so after i type the string, i should
press enter...so this same thing the uC needs to understand...that wen i
press enter key (carriage return key), it should sense the end of
string..hence for this case i am using the pointer...which will store
character after character like an array...hence after carriage return key,
the pointer will stop storing further characters and then we can display
all the characters like a string...hope i have been able to explain
well...so pls guide me wat to do next..

thanks,
Dev

On Wed, Mar 14, 2012 at 11:19 AM, Phil Young wrote:

> **
> Hi Dev,
>
> I'm not sure what you're trying to do with rec, just comment out the lines
> that use it.
>
> Or declare
>
> char rec;
>
> and
>
> rec = U1RBR;
>
> since it looks like all you are trying to do is discard the carriage
> return.
> Regards
>
> Phil.
>
> From: l... [mailto:l...] On Behalf
> Of
> Michael Anton
> Sent: 14 March 2012 05:15
>
> To: l...
> Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
>
> Actually, it is slightly worse, as automatics are not usually zeroed on
> startup, or at least I haven't seen a compiler do this, unless it is also
> declared as static, so it could point to anything.
>
> Mike
>
> -----Original Message-----
> From: l...
> [mailto:l... ]On
> Behalf
> Of Phil Young
> Sent: Tuesday, March 13, 2012 1:19 PM
> To: l...
> Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
>
> You have created a char pointer *rec, but have not initialized it, it will
> be on the stack as it's local and probably zero since the startup code
> usually zero's memory.
>
> When a CR is pressed you write to memory using it then increment it.
>
> It's likely that writing to memory using an uninitialized pointer is
> crashing the processor at that point.
>
> Regards
>
> Phil.
>
> From: l...
> [mailto:l... ] On
>
> Behalf Of
> DeV
> Sent: 13 March 2012 08:22
> To: l...
> Subject: [lpc2000] LPC2378 UART 1 problem!!!
>
> hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
> communicate...im having problem in receiving data...wat i want to do is
> till valid data is not available the lcd will display "no data"...only wen
> some data EXCEPT Carriage Return is sent, it will display "data
> entered"...now once the Carriage Return key is pressed the lcd will display
> "Carriage Return" till again a new character is received and the process is
> repeated...
>
> but wat im getting is that everything is working ok untill carriage return
> key...once i press the carriage return key the loop is entered only once
> and the complete process stops!! Thanks in advance!!
>
> int main ()
> {
> char *rec;
> PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
>
> PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
>
> U1LCR = 0X83;
> U1DLL = 4;
> U1DLM = 0;
> U1FDR = 0X00000085;
>
> U1FCR = 7;
>
> PCONP |= (1<<3);
>
> InitLcd();
>
> while(1)
> {
> if ((U1LSR & 1) == 1)
> {
> U1LCR &= 0x7F;
>
> while(U1RBR == 13)
> {
> LCDClearScreen();
> U1LCR &= 0x7F;
> LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
> *rec = U1RBR;
> rec++;
> U1LCR &= 0x7F;
> }
> LCDClearScreen();
> LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
> U1LCR |= 0x80;
> }
>
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
> }
> }
> }
>
>
>
>
>
>
Hi,

You are trying to use a pointer without first pointing it to a defined location.
Normally you would point a pointer to a variable (or array).
Like this:
char someArray[25]; // Make an array
char* somePointer = someArray; // make a pointer and point it to the array

I would advise you to find a tutorial or a book on C programming.

--
Kevin
--- In l..., DeV wrote:
>
> Hi Phil,
>
> U1RBR is the receiver register of uart1..so it stores the last byte
> received..now wat i want to do is that using hyper terminal on my pc, i
> want to send a string...e.g.e hello...so after i type the string, i should
> press enter...so this same thing the uC needs to understand...that wen i
> press enter key (carriage return key), it should sense the end of
> string..hence for this case i am using the pointer...which will store
> character after character like an array...hence after carriage return key,
> the pointer will stop storing further characters and then we can display
> all the characters like a string...hope i have been able to explain
> well...so pls guide me wat to do next..
>
> thanks,
> Dev
>

Hi Dev,
Then there are a number of problems with the code, since you don't store
anything unless you get the carriage return, and when you do store it you
use an uninitialized pointer.
There are many ways to code this, but using pointers try the following

Try first allocating an array to store the characters, i.e.
char InString[101];

then place the pointer to the start of the string
char *rec = InString;

count the characters received as you must stay in the string boundaries you
have allocated, you could simply output the data when you get to the full
buffer or get a carriage return

char InString[101]; // 101 characters, we use 100 but allocate 101 for safe
termination with 0
char * rec = InString; // initialize rec, same as rec = &InString[0]
bool OutString = false; // flag when to output data
while(1) {
if ((U1LSR & 1) == 1) { // check if a character received
*rec = U1RBR; // the only access to RBR, copies the character so
don't access RBR again
U1LCR &= 0x7F;
if (*rec == 13) {
OutString = true; // when received just flag output
} else {
rec++; // increment pointer
if (rec == 100 + InString){ // same as if (rec == &InString[101])
OutString = true; // flag to output data as buffer is full
}
}
If(OutString){
// when buffer is full, or CR received output the data and reset
the buffer pointers and flags
*rec = 0; // terminate the received string with 0
LCDClearScreen();
LCDPutStr(InString, 0, 0, LARGE, RED, WHITE);
rec = InString;
OutString = false;
}
}
}
Regards

Phil.
-----Original Message-----
From: l... [mailto:l...] On Behalf Of
DeV
Sent: 14 March 2012 07:26
To: l...
Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!

Hi Phil,

U1RBR is the receiver register of uart1..so it stores the last byte
received..now wat i want to do is that using hyper terminal on my pc, i want
to send a string...e.g.e hello...so after i type the string, i should press
enter...so this same thing the uC needs to understand...that wen i press
enter key (carriage return key), it should sense the end of string..hence
for this case i am using the pointer...which will store character after
character like an array...hence after carriage return key, the pointer will
stop storing further characters and then we can display all the characters
like a string...hope i have been able to explain well...so pls guide me wat
to do next..

thanks,
Dev

On Wed, Mar 14, 2012 at 11:19 AM, Phil Young
wrote:

> **
> Hi Dev,
>
> I'm not sure what you're trying to do with rec, just comment out the
> lines that use it.
>
> Or declare
>
> char rec;
>
> and
>
> rec = U1RBR;
>
> since it looks like all you are trying to do is discard the carriage
> return.
> Regards
>
> Phil.
>
> From: l... [mailto:l...] On
> Behalf Of Michael Anton
> Sent: 14 March 2012 05:15
>
> To: l...
> Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
>
> Actually, it is slightly worse, as automatics are not usually zeroed
> on startup, or at least I haven't seen a compiler do this, unless it
> is also declared as static, so it could point to anything.
>
> Mike
>
> -----Original Message-----
> From: l...
> [mailto:l... ]On
> Behalf Of Phil Young
> Sent: Tuesday, March 13, 2012 1:19 PM
> To: l...
> Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
>
> You have created a char pointer *rec, but have not initialized it, it
> will be on the stack as it's local and probably zero since the startup
> code usually zero's memory.
>
> When a CR is pressed you write to memory using it then increment it.
>
> It's likely that writing to memory using an uninitialized pointer is
> crashing the processor at that point.
>
> Regards
>
> Phil.
>
> From: l...
> [mailto:l... ]
> On
>
> Behalf Of
> DeV
> Sent: 13 March 2012 08:22
> To: l...
> Subject: [lpc2000] LPC2378 UART 1 problem!!!
>
> hello all...i own a lpc2378-stk olimex board...im trying to use uart1
> to communicate...im having problem in receiving data...wat i want to
> do is till valid data is not available the lcd will display "no
> data"...only wen some data EXCEPT Carriage Return is sent, it will
> display "data entered"...now once the Carriage Return key is pressed
> the lcd will display "Carriage Return" till again a new character is
> received and the process is repeated...
>
> but wat im getting is that everything is working ok untill carriage
> return key...once i press the carriage return key the loop is entered
> only once and the complete process stops!! Thanks in advance!!
>
> int main ()
> {
> char *rec;
> PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
>
> PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
>
> U1LCR = 0X83;
> U1DLL = 4;
> U1DLM = 0;
> U1FDR = 0X00000085;
>
> U1FCR = 7;
>
> PCONP |= (1<<3);
>
> InitLcd();
>
> while(1)
> {
> if ((U1LSR & 1) == 1)
> {
> U1LCR &= 0x7F;
>
> while(U1RBR == 13)
> {
> LCDClearScreen();
> U1LCR &= 0x7F;
> LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE); *rec = U1RBR;
> rec++;
> U1LCR &= 0x7F;
> }
> LCDClearScreen();
> LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE); U1LCR |= 0x80; }
>
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } } }
>
>
>
>
>
>
Thanks so much Phil, U guys are amazing...so lucky for beginners like me to
have tutors like you..thanks again and cheers!

On Wed, Mar 14, 2012 at 12:22 PM, Phil Young wrote:

> **
> Hi Dev,
> Then there are a number of problems with the code, since you don't store
> anything unless you get the carriage return, and when you do store it you
> use an uninitialized pointer.
> There are many ways to code this, but using pointers try the following
>
> Try first allocating an array to store the characters, i.e.
> char InString[101];
>
> then place the pointer to the start of the string
> char *rec = InString;
>
> count the characters received as you must stay in the string boundaries you
> have allocated, you could simply output the data when you get to the full
> buffer or get a carriage return
>
> char InString[101]; // 101 characters, we use 100 but allocate 101 for safe
> termination with 0
> char * rec = InString; // initialize rec, same as rec = &InString[0]
> bool OutString = false; // flag when to output data
> while(1) {
> if ((U1LSR & 1) == 1) { // check if a character received
> *rec = U1RBR; // the only access to RBR, copies the character so
> don't access RBR again
> U1LCR &= 0x7F;
> if (*rec == 13) {
> OutString = true; // when received just flag output
> } else {
> rec++; // increment pointer
> if (rec == 100 + InString){ // same as if (rec == &InString[101])
> OutString = true; // flag to output data as buffer is full
> }
> }
> If(OutString){
> // when buffer is full, or CR received output the data and reset
> the buffer pointers and flags
> *rec = 0; // terminate the received string with 0
> LCDClearScreen();
> LCDPutStr(InString, 0, 0, LARGE, RED, WHITE);
> rec = InString;
> OutString = false;
> }
> }
> }
>
> Regards
>
> Phil.
>
> -----Original Message-----
> From: l... [mailto:l...] On Behalf
> Of
> DeV
> Sent: 14 March 2012 07:26
> To: l...
> Subject: Re: [lpc2000] LPC2378 UART 1 problem!!!
>
> Hi Phil,
>
> U1RBR is the receiver register of uart1..so it stores the last byte
> received..now wat i want to do is that using hyper terminal on my pc, i
> want
> to send a string...e.g.e hello...so after i type the string, i should press
> enter...so this same thing the uC needs to understand...that wen i press
> enter key (carriage return key), it should sense the end of string..hence
> for this case i am using the pointer...which will store character after
> character like an array...hence after carriage return key, the pointer will
> stop storing further characters and then we can display all the characters
> like a string...hope i have been able to explain well...so pls guide me wat
> to do next..
>
> thanks,
> Dev
>
> On Wed, Mar 14, 2012 at 11:19 AM, Phil Young
> wrote:
>
> > **
>
> >
> >
> > Hi Dev,
> >
> > I'm not sure what you're trying to do with rec, just comment out the
> > lines that use it.
> >
> > Or declare
> >
> > char rec;
> >
> > and
> >
> > rec = U1RBR;
> >
> > since it looks like all you are trying to do is discard the carriage
> > return.
> >
> >
> > Regards
> >
> > Phil.
> >
> > From: l... [mailto:l...] On
> > Behalf Of Michael Anton
> > Sent: 14 March 2012 05:15
> >
> > To: l...
> > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > Actually, it is slightly worse, as automatics are not usually zeroed
> > on startup, or at least I haven't seen a compiler do this, unless it
> > is also declared as static, so it could point to anything.
> >
> > Mike
> >
> > -----Original Message-----
> > From: l...
> > [mailto:l... ]On
> > Behalf Of Phil Young
> > Sent: Tuesday, March 13, 2012 1:19 PM
> > To: l...
> > Subject: RE: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > You have created a char pointer *rec, but have not initialized it, it
> > will be on the stack as it's local and probably zero since the startup
> > code usually zero's memory.
> >
> > When a CR is pressed you write to memory using it then increment it.
> >
> > It's likely that writing to memory using an uninitialized pointer is
> > crashing the processor at that point.
> >
> > Regards
> >
> > Phil.
> >
> > From: l...
> > [mailto:l... ]
> > On
> >
> > Behalf Of
> > DeV
> > Sent: 13 March 2012 08:22
> > To: l...
> > Subject: [lpc2000] LPC2378 UART 1 problem!!!
> >
> > hello all...i own a lpc2378-stk olimex board...im trying to use uart1
> > to communicate...im having problem in receiving data...wat i want to
> > do is till valid data is not available the lcd will display "no
> > data"...only wen some data EXCEPT Carriage Return is sent, it will
> > display "data entered"...now once the Carriage Return key is pressed
> > the lcd will display "Carriage Return" till again a new character is
> > received and the process is repeated...
> >
> > but wat im getting is that everything is working ok untill carriage
> > return key...once i press the carriage return key the loop is entered
> > only once and the complete process stops!! Thanks in advance!!
> >
> > int main ()
> > {
> > char *rec;
> > PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> > PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
> >
> > PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> > PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> >
> > U1LCR = 0X83;
> > U1DLL = 4;
> > U1DLM = 0;
> > U1FDR = 0X00000085;
> >
> > U1FCR = 7;
> >
> > PCONP |= (1<<3);
> >
> > InitLcd();
> >
> > while(1)
> > {
> > if ((U1LSR & 1) == 1)
> > {
> > U1LCR &= 0x7F;
> >
> > while(U1RBR == 13)
> > {
> > LCDClearScreen();
> > U1LCR &= 0x7F;
> > LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE); *rec = U1RBR;
> > rec++;
> > U1LCR &= 0x7F;
> > }
> > LCDClearScreen();
> > LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE); U1LCR |= 0x80; }
> >
> > else
> > {
> > LCDClearScreen();
> > LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE); } } }
> >
> >
> >
> >
> >
> >
> >
> >
Hi DeV,

--- In l..., DeV wrote:
>
> hello all...i own a lpc2378-stk olimex board...im trying to use uart1 to
> communicate...im having problem in receiving data...wat i want to do is
> till valid data is not available the lcd will display "no data"...only wen
> some data EXCEPT Carriage Return is sent, it will display "data
> entered"...now once the Carriage Return key is pressed the lcd will display
> "Carriage Return" till again a new character is received and the process is
> repeated...
>
> but wat im getting is that everything is working ok untill carriage return
> key...once i press the carriage return key the loop is entered only once
> and the complete process stops!! Thanks in advance!!
>
> int main ()
> {
> char *rec;
> PINSEL0 &= 0X3FFFFFFF;//Select Pins for PWM1.6
> PINSEL0 |= 0X40000000;//Select Pins for PWM1.6
>
> PINSEL1 &= 0XFFFFFFFC;//Select Pins for PWM1.6
> PINSEL1 |= 0X00000001;//Select Pins for PWM1.6
> U1LCR = 0X83;
> U1DLL = 4;
> U1DLM = 0;
> U1FDR = 0X00000085;
>
> U1FCR = 7;
>
> PCONP |= (1<<3);
>
> InitLcd();
>
> while(1)
> {
> if ((U1LSR & 1) == 1)
> {
> U1LCR &= 0x7F;
>
> while(U1RBR == 13)
> {
> LCDClearScreen();
> U1LCR &= 0x7F;
> LCDPutStr("Carriage Return", 0, 0, LARGE, RED, WHITE);
> *rec = U1RBR;
> rec++;
> U1LCR &= 0x7F;
> }
> LCDClearScreen();
> LCDPutStr("data entered", 32, 0, LARGE, RED, WHITE);
> U1LCR |= 0x80;
> }
>
> else
> {
> LCDClearScreen();
> LCDPutStr("No Data", 110, 0, LARGE, GREEN, WHITE);
> }
> }
> }
>
>
Why you are playing with U1LCR all the time???
The Divisor Latch Enable bit should be set when you configure the divisor latches and then just cleared. For example:

U1LCR = 0x83;
U1DLL = 4;
U1DLM = 0;
U1LCR = 0x03;

This is not the actual problem of course. But it is some how related to the mess in your code.

You are pooling the UART status but do you realize how match time you spend in the LCD routines meanwhile?
It is very probable that you miss some UART events.

Regards
Zdravko


The 2024 Embedded Online Conference