Hi, I wanted to write a simple program that doesn’t use interrupts or check any of the possible error flags, but that shows a simple UART application for receiving data. This is a part of the code I wrote.
int uart0Getch(void)
{
if (LPC_UART->LSR & LSR_RDR) // check if character is available
{ return LPC_UART->RBR; // return character
}
return -1;
#include "includes.h"
#include "uart.h"
int value;
extern int main( void )
system_init();
screen1[0]='a';
screen1[1]='b';
screen1[2]='c';
while(1)
//KeyScanProc(buf,screen1);
if ((value = uart0Getch()) >= 0)
send_to_uart(screen1,3);
Very well, I am understanding a lot more about the uart in the LPC111.XX. I
am going to implement the interrupts and see what happens
2015-01-15 2:50 GMT-04:30 jensbauer <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24366?et=watches.email.thread#24366>
<http://community.arm.com/?et=watches.email.thread> Receiving Data
Using the UART CORTEX M0
reply from jensbauer
<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARM
Processors* - View the full discussion
<http://community.arm.com/message/24366?et=watches.email.thread#24366>
Yes, I can confirm the timezone.
-And you're right, it's much better to either use interrupts, or setting up the DMA and putting the CPU to sleep using __WFI(); -Then it's more efficient both power- and performance-wise.
(The LPC11xx does not have DMA, I guess I've gotten too used to working with the LPC175x and LPC176x; if you at some point use a device that contains a DMA, I highly recommend digging into it and using it - you can get very high performance boosts when using this feature).
I'd like to explain a little detail on the subject, which other readers will also benefit from.
When you use 'polling', if you're waiting for a character from the uart and then sending a string of characters back, then you could be unlucky and miss out some characters now and then. You would be confused why.
The reason is that while you're sending - say 16 characters - you're not checking for incoming data. The data arrives at the same speed as the data you're sending out, so since you're not reading while you're writing, you will lose up to N - FIFO_SIZE characters, where N is the number of characters you're sending and FIFO_SIZE is the size of the FIFO on the chip.
The FIFO size may be 1, it may be 16 or 32, depending on your chip, but even if you're only sending two characters for every single character you receive, at some point, the FIFO will get full, and you'll lose half the transmission.
Using interrupts will fix this problem, because the interrupts will transmit data you've scheduled for transmission, and it'll also be able to have a receive-buffer, which can be of a size of your choice, as long as there's enough RAM for it.
In addition to these two benefits, your program will no longer need to stall in the part of your code that transmits data.
hi, thanks!! let me check that link then.
2015-01-14 10:28 GMT-04:30 jensbauer <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24359?et=watches.email.thread#24359>
<http://community.arm.com/message/24359?et=watches.email.thread#24359>
Hello alerico90,
Sorry for my late entry to the discussion. Jensbauer has a reply advantage at GMT+1, probably
Thanks for digging into the depths of the UART registers, but I also want to point out that NXP provides a free software driver at our lpcware.com site at this link. Granted, this example is an interrupt mode, but it will work very efficiently for you.
-arw
Yes, in fact I just ran the program with the flush function and the output
was something like: "HEL W". Thank you very much for your help!!! It has
been very useful
2015-01-13 15:32 GMT-04:30 jensbauer <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24333?et=watches.email.thread#24333>
<http://community.arm.com/message/24333?et=watches.email.thread#24333>
Just in case you were wondering why flushing is probably not what you want:
fflush(stdout); for printf will send all cached characters to the current output device.
flushing the transmit-buffer in a UART, means to throw away any data that has not yet been sent.
That means if you send the string:
"Hello World"
and you flush the transmit-buffer immediately after, you'll probably end up receiving only the first few charaters, perhaps only "He" or "Hel".
Ok, let me try that and see if it works. Thanks for all!
2015-01-13 12:45 GMT-04:30 jensbauer <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24330?et=watches.email.thread#24330>
<http://community.arm.com/message/24330?et=watches.email.thread#24330>
Have you tried not calling uart0TxFlush ?
(it should not be necessary to flush the outgoing data, and is not recommended).
these are thesub routines
if (LPC_UART->LSR & LSR_RDR)
{ return LPC_UART->RBR;
void uart0TxFlush(void)
LPC_UART->FCR |= (1 << 2); // Borra TX FIFO
2015-01-13 11:10 GMT-04:30 jensbauer <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24328?et=watches.email.thread#24328>
<http://community.arm.com/message/24328?et=watches.email.thread#24328>
OK, then we know this happens inside the while(1){ ... } loop, because we never leave the while loop.
We also know that it won't happen inside uart0Getch, as there are no loops in there.
So two functions are left:
send_to_uart and uart0TxFlush.
What do those two subroutines look like ?
well, this is the main function
EVENT_T evt;
//SysTick_Config(SystemFrequency/100000);
// No se utliza OSTimeDly en esta sección
__disable_irq();
if(1)
{//uint8_t buf[6];
uint8_t buf[SPEC12832RowNum*SPEC12832ColumnNum/8];
uint8_t c;
SPEC12832Select(LCD_SELECT_USER | LCD_SELECT_CUSTOM);
memset(buf, 0x00, sizeof(buf));
SPEC12832DisplayPattern(buf);
memset(screen1,'0',sizeof(screen1));
{ screen1[1]=value;
uart0TxFlush();
However I run the program and after sending data several times the program
stops working,
2015-01-13 10:12 GMT-04:30 jensbauer <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24326?et=watches.email.thread#24326>
<http://community.arm.com/message/24326?et=watches.email.thread#24326>
Looking at the code snippet you posted, I think your 'while(1)' could be the problem.
-But something is wrong with the snippet; it does not contain a balanced set of curly braces, so it's difficult to guess where they are in your original code.
You should make sure that there is a starting brace right after your 'while(1)'
For instance...
int main(void)
// some initialization code here.
// your code here.
// no code here.
Notice: the 'extern' keyword in front of 'int main(void)' should also be removed.
I forgot to ask something else, I send data through the uart to the PC and
the PC responds sending some other data, well after I send the data, my LPC
seems to stop working, it doesn't respond anymore, why that happens?.
2015-01-13 9:32 GMT-04:30 Alejandra Angulo Rico <alerico90@gmail.com>:
I am using a ARM M0 Cortex LPC1114, let me check the baud rate to see ifthat's the problem. Thank you!2015-01-13 8:44 GMT-04:30 jensbauer <community@arm.com>:
I am using a ARM M0 Cortex LPC1114, let me check the baud rate to see if
that's the problem. Thank you!
2015-01-13 8:44 GMT-04:30 jensbauer <community@arm.com>:
>> <http://community.arm.com/?et=watches.email.thread> Receiving Data
>> Using the UART CORTEX M0
>>
>> reply from jensbauer
>> <http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARM
>> Processors* - View the full discussion
>> <http://community.arm.com/message/24308?et=watches.email.thread#24308>
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from jensbauer<http://community.arm.com/people/jensbauer?et=watches.email.thread> in *ARMProcessors* - View the full discussion<http://community.arm.com/message/24308?et=watches.email.thread#24308>
<http://community.arm.com/message/24308?et=watches.email.thread#24308>
View all questions in Cortex-M / M-Profile forum