I am trying to send the data to UART1 in LP2148. Given below is the code. But the data displayed is only some junk (mainly ???? is displayed). I am not able to makeout the problem. The terminal software is configured at 9600 baud. pclk is 15 MHz.
#include <lpc214x.h> //Includes LPC2148 register definitions
#define Fosc 12000000 #define Fcclk (Fosc * 5) #define Fcco (Fcclk * 4) #define Fpclk (Fcclk / 4) * 1
#define UART_BPS 9600 //Set Baud Rate here
const unsigned char SEND_STRING[] = "Nex Robotics PVT LTD\nARM7 LPC214x Development Board\nCommunication Test\nSend any character to continue\n"; const unsigned char SEND_STRING1[] = "Test Passed\n";
void Delay_Ticks(unsigned int Delay) //Function to generate finite delay { unsigned int i; for(; Delay>0; Delay--) for(i=0; i<50000; i++); }
void Init_UART1(void) //This function setups UART1 { unsigned int Baud16; U1LCR = 0x83; // DLAB = 1 Baud16 = (Fpclk / 16) / UART_BPS; U1DLM = Baud16 / 256; U1DLL = Baud16 % 256; U1LCR = 0x03; }
void UART1_SendByte(unsigned char data) //A function to send a byte on UART1 { U1THR = data; while( (U1LSR&0x40)==0 ); }
void UART1_SendStr(const unsigned char *str) //A function to send a string on UART1 { while(1) { if( *str == '\0' ) break; UART1_SendByte(*str++); } }
int main(void) { PINSEL0 = 0x00050000; // Enable UART1 Rx and Tx pins PINSEL1 = 0x00000000; PINSEL2 = 0x00000000;
Init_UART1(); UART1_SendStr(SEND_STRING); while((U1LSR&0x01)==0); UART1_SendStr(SEND_STRING1); while(1) {
} // return(0); }
Problem seems to be something else. If I use USB boot loader, I have this problem. If I use serial boot loader, same code works. Not sure where the problem could be. Also I do not have oscilloscope with me. So I have to debug only using serial port/LEDs/LCD.
The divisor (U0DLL) for baudrate is correct and it displayed the character 'a' (97) in LCD.
The data is getting sent to the seral port. Because in main program, statement while((U1LSR&0x01)==0); is coming out. But only ??? is displayed still.