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);
-Your uart0Getch() function seems to be fine. The problem is most likely that your baud rate has not been set correctly.
Your baud rate must be set to the same on both ends; eg. both the transmitter and receiver.
So if you're sending data from a computer, and you're using 1200 baud, set the baud rate to 1200 on both the computer and the microcontroller.
Which microcontroller (vendor + model) are you using ?
-If you are using a LPC11xx, then you might be able to use this snippet to set the baud rate, before trying to receive:
void setupUART()
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_6, IOCON_FUNC1); /* Pin 31: RxD */
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_7, IOCON_FUNC1); /* Pin 32: TxD */
Chip_UART_Init(LPC_USART);
Chip_UART_SetBaud(LPC_USART, 38400);
Note: You'll need to configure the first two lines, so they match your own setup. You'll of course also need to change the baud rate so it matches your needs.
To send a character, you can use this function:
void UART_sendCharacter(char aCharacter)
while(!(Chip_UART_ReadLineStatus(LPC_USART) & UART_LSR_THRE)){}
Chip_UART_SendByte(LPC_USART, (uint8_t) aCharacter);
For completeness (you already have a function that resembles it); to wait for a character, you can use this:
int16_t UART_receiveByte()
while(!(Chip_UART_ReadLineStatus(LPC_USART) & UART_LSR_RDR)){}
return(Chip_UART_ReadByte(LPC_USART));
The 'sendCharacter' function can be rewritten to your style, if you need to; here I've chosen to send a 'byte' instead of a character:
void UART_sendByte(uint8_t aByte)
while(!(LPC_USART->LSR & UART_LSR_THRE)){}
LPC_USART->THR = aByte;
Hi, yes the code works wrong, I try to show the character sent from the
computer port on an LCD, but it shows nothing.
Best regards,
Alerico 90
2015-01-13 6:17 GMT-04:30 yasuhikokoumoto <community@arm.com>:
<http://community.arm.com/?et=watches.email.thread> Receiving DataUsing the UART CORTEX M0reply from yasuhikokoumoto<http://community.arm.com/people/yasuhikokoumoto?et=watches.email.thread>in ARM Processors - View the full discussion<http://community.arm.com/message/24313?et=watches.email.thread#24313>
<http://community.arm.com/?et=watches.email.thread> Receiving Data
Using the UART CORTEX M0
reply from yasuhikokoumoto
<http://community.arm.com/people/yasuhikokoumoto?et=watches.email.thread>
in ARM Processors - View the full discussion
<http://community.arm.com/message/24313?et=watches.email.thread#24313>
Hi alerico90,
there are several UART implementations. Waht part or device do you use? Also what is your question? Does the code work wrong?
Best regards,Yasuhiko Koumoto.
View all questions in Cortex-M / M-Profile forum