Uart String buffer size. Almost there ! Need assistance

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Uart String buffer size. Almost there ! Need assistance

939 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Wed Jun 06 10:35:43 MST 2012
Hey everyone,

I have this issue here.
Supposed i have a long string sent from a device to my LPC 1769, something like

>>Hello, nice to meet you.How are you today ?

However, i supposed the UART buffer size is limited or not configured properly, as i only received something like

>>Hello, nice to m

on my LPC console.

Also, i find it strange that i cannot see my printf statement using this
[LEFT]for(i=0;i<64;i++)
{
printf("%c", line);
Timer0_Wait(20);
}[/LEFT]
Yet, i could see printf statement with \n. Any ideas anyone ?

for(i=0;i<64;i++)
{
printf("%c[B][COLOR=Magenta]\n[/COLOR][/B]", line);
Timer0_Wait(20);
}


Any ideas people ?

Regards.
0 Kudos
15 Replies

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Sun Apr 14 12:59:12 MST 2013
How did you manage to read the full string?
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yongchang05 on Wed Oct 10 11:05:31 MST 2012
Hi JJClyne,

you are using an AT Command to read from your GSM right? may i know how did u do it in the end? through polling or interrupt?


Quote: JJClyne
Hi Zero,

Thanks for the link.
Do you have a way to receive longer strings ?

+CMGR: "REC READ","+6591xxxxx","","12/06/06,16:10:45+32"

was received as

+CMGR: "REC RE

I need to receive the entire string to perform some function.


Would you mind giving me some advice on this ?

if (LPC_UART3->LSR & UART_LSR_RDR) //To modify, perhaps a better way.

        {
            do
            {
                UART_Receive(LPC_UART3, &data, 3, BLOCKING);
                //Timer0_Wait(500);
                if (data !=
                        '\r')
                {
                    len++;
                    line[len-1] = data;
                }
            } while ((len<64) && (LPC_UART3->LSR & UART_LSR_RDR));
        }

        line[len]=0;


Zero,any ideas why i'm not receiving the full string
+CMGR: "REC READ","+65913xxxxx","","12/06/06,16:10:45+32" ?

and got
+CMGR: "REC RE instead ?

0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jun 07 11:02:32 MST 2012

Quote: JJClyne
What does the above do, and is it critical ?




See User manual 10360 :eek:

Don't know what your code is doing, but the usual way to read UART strings is a large ring buffer ;)

UART interrupt handler is filling this buffer and increasing a produce counter and something in your main is comparing this produce counter with a consume counter and reading buffered data, if available :)

http://en.wikipedia.org/wiki/Circular_buffer
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Thu Jun 07 09:11:47 MST 2012
Zero and Frame,

I have gotten myself the full string read.
Thanks Zero for the guidance, the sense of satisfaction is great :p

A Question

1)   LPC_UART1->DLM = Fdiv / 256;
    LPC_UART1->DLL = Fdiv % 256;

switch ( pclkdiv )
{
  case 0x00:
  default:
pclk = SystemFrequency/4;
break;
  case 0x01:
pclk = SystemFrequency;
break;
  case 0x02:
pclk = SystemFrequency/2;
break;
  case 0x03:
pclk = SystemFrequency/8;
break;
}

What does the above do, and is it critical ?



Quote: JJClyne
:p

Yes Zero, i am new at this.

-Just an update, i have since, gotten Uart0 interrupt, up and running.

Will update with questions


To Frame

Thank you for the reply, you are very kind.

0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Thu Jun 07 07:44:42 MST 2012
:p
Quote: Zero
You've copied UART stuff in your main, that has to punished :)

In uart.c (or included uart.h header file) everything you need is included, so it's not very smart to change that (especially if you are not familiar with C) :eek:



Yes Zero, i am new at this.

-Just an update, i have since, gotten Uart0 interrupt, up and running.

Will update with questions


To Frame

Thank you for the reply, you are very kind.
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jun 07 07:35:24 MST 2012
You've copied UART stuff in your main, that has to punished :)

In uart.c (or included uart.h header file) everything you need is included, so it's not very smart to change that (especially if you are not familiar with C) :eek:
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Thu Jun 07 07:14:45 MST 2012
[LEFT]Hello Zero,

Thanks for staying with me and being patient.
I have setup interrupts accordingly.


Quote: Zero
UM is your friend :)



No, why :confused:



You've to enable your Interrupt, as shown in sample with UART0  ;)




That's a copy & paste job, just change UART0 to UART3 :eek:



[/LEFT]
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Thu Jun 07 07:13:26 MST 2012
One suggestion is to dissect the examples mentioned here.


The other is to familiarize with the concept of asynchronuous and concurrent events and code threads.

An interrupt (in this case a UART interrupt) happens at an unpredictable time, and, as the name suggests, interrupts the currently processed code, and places you in the interrupt routine.
In case of the UART receive interrupt, you find the received character ready to use in a register, and just need to store it away. Once you leave the interrupt, the controller continues where he was interrupted.

However, there are two important issues.

First, you should finish your interrupt processing before the next interrupt of the same type occurs, so avoid complex and lengthy calculations in interrupt routines. Otherwise the next interrupt fires as soon as you leave the routine, and you are in an endless loop.

Second, you need to keep in mind that an interrupt can fire if you are about to process data that where delivered by the last interrupt. You need to synchronize the data access from the main code and the interrupt code.
If you, for instance, wait for a buffer to be filled in the interrupt, and process it then in a main loop, you need to keep the interrupt from writing in the same buffer again, or you get corrupted data.
That's a very short introduction to interrupts in a nutshell.
It is a little more difficult to understand at first, but much more efficient than polling.

For interrupt processing on ARM cortex, I suggest to download and study the Cortex M0/M3/M4 core reference manuals from the ARM webpage :
http://infocenter.arm.com/help/index.jsp

And, for the controller in use, check the respective reference manual - see especially the NVIC section.
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jun 07 07:01:42 MST 2012

Quote: JJClyne
I have trouble understanding and building the UART interrupt example.



UM is your friend :)


Quote: JJClyne
Am i supposed to copy the Uart0 IRQ handler code into my main.c ?



No, why :confused:


Quote: JJClyne
Set up the necessary NVIC enable parameters?



You've to enable your Interrupt, as shown in sample with UART0  ;)



Quote: JJClyne
I need some additonal help with this UART interrupt.
Any kind soul around to offer some guidance ?



That's a copy & paste job, just change UART0 to UART3 :eek:
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Thu Jun 07 06:16:40 MST 2012

Quote: Zero
There are several samples in your example folder, ie UART in NXP_LPCXpresso1769_MCB1700_2011-02-11.zip :)



I have trouble understanding and building the UART interrupt example.

I need some additonal help with this UART interrupt.
Any kind soul around to offer some guidance ?
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jun 06 11:36:50 MST 2012
There are several samples in your example folder, ie UART in NXP_LPCXpresso1769_MCB1700_2011-02-11.zip :)
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Wed Jun 06 11:16:15 MST 2012

Quote: Zero
That's no secret. Use Interrupt UART sample and write UART FIFO in your buffer there :)

Your code looks like polling, that neither smart nor fast :eek:



Yep :), this is my first time doing anything related to LPC.

I could have swore i got it working last night, and i was able to decode the whole string even with polling method.

Could I trouble you to point me alittle clearer in the right direction for this UART interrupt sample you were talking about ?

Much Thanks
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jun 06 10:54:30 MST 2012

Quote:
Do you have a way to receive longer strings ?

That's no secret. Use Interrupt UART sample and write UART FIFO in your buffer there :)

Your code looks like polling, that neither smart nor fast :eek:
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by JJClyne on Wed Jun 06 10:47:37 MST 2012

Quote: Zero
User manual:



Hi Zero,

Thanks for the link.
Do you have a way to receive longer strings ?

+CMGR: "REC READ","+6591xxxxx","","12/06/06,16:10:45+32"

was received as

+CMGR: "REC RE

I need to receive the entire string to perform some function.


Would you mind giving me some advice on this ?

if (LPC_UART3->LSR & UART_LSR_RDR) //To modify, perhaps a better way.

{
do
{
UART_Receive(LPC_UART3, &data, 3, BLOCKING);
//Timer0_Wait(500);
if (data !=
'\r')
{
len++;
line[len-1] = data;
}
} while ((len<64) && (LPC_UART3->LSR & UART_LSR_RDR));
}

line[len]=0;


Zero,any ideas why i'm not receiving the full string
+CMGR: "REC READ","+65913xxxxx","","12/06/06,16:10:45+32" ?

and got
+CMGR: "REC RE instead ?
0 Kudos

799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jun 06 10:41:07 MST 2012
User manual:

Quote:

15.2 Features
• Full modem control handshaking available
• Data sizes of 5, 6, 7, and 8 bits.
• Parity generation and checking: odd, even mark, space or none.
• One or two stop bits.
• [B][COLOR=Red]16 byte[/COLOR][/B] Receive and Transmit FIFOs

0 Kudos