We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a problem with uart interface , I tried to start program " hello wold " but on the serial dont display it please I need help . I will post the code : SERIAL.C : #include <LPC17xx.H>
#define CR 0x0D int sendchar (int ch) {
if (ch == '\n') { while (!(LPC_UART1->LSR & 0x20)); LPC_UART1->THR = CR; /* output CR */ } while (!(LPC_UART1->LSR & 0x20)); return (LPC_UART1->THR = ch); }
int getkey (void) { /* Read character from Serial Port */
while (!(LPC_UART1->LSR & 0x01));
return (LPC_UART1->RBR); }
:::::::::::::::::::::::::::::::::: RETARGET.C
#include <stdio.h> #include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
extern int sendchar(int ch); /* in serial.c */
struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout;
int fputc(int ch, FILE *f) { return (sendchar(ch)); }
int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; }
void _ttywrch(int ch) { sendchar(ch); }
void _sys_exit(int return_code) { label: goto label; /* endless loop */ } ::::::::::::::::::::::::::::::::::::::::::::
HELLO.C #include <stdio.h> /* prototype declarations for I/O functions */ #include <LPC17xx.H> /* LPC21xx definitions */
/****************/ /* main program */ /****************/ int main (void) { /* execution starts here */ uint32_t Fdiv; /* initialize the serial interface */ LPC_PINCON->PINSEL0 &= ~0x000000F0; LPC_PINCON->PINSEL0 |= 0x00000050; /* Enable RxD1 and TxD1 */ LPC_UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ LPC_UART1->DLL = Fdiv % 256; /* 9600 Baud Rate @ 15MHz VPB Clock */ LPC_UART1->LCR = 0x03; /* DLAB = 0 */
printf ("Hello World\n");
while (1) { ; /* ... */ }}
::::::::::::::::::::::::::::::::::::::::::