Hi
I am new to embedded development
I am trying to write this simple program that reads from UART1 and send to UART0. I wrote the following code but it does not work
I am using a Olimex LPC-P2148 board and the Peripherals Clock Frequency is set to the Processor Clock Frequency
I do not know what I am missing
Thank you in advance
//////////////////////////////////////////////////////////////////////
#define FREQ 12000000
void InitializeUART0(unsigned int baudrate)
{
unsigned int temp;
unsigned int divisor = FREQ / (16 * baudrate);
U0LCR = 0x83; // DLAB = 1, 8 bit, 1 stop bit, no parity
U0DLL = divisor & 0xFF; // LSB
U0DLM = (divisor >> 8 ) & 0xFF; // MSB
U0LCR = 0x03; //DLAB = 0, 8 bit, 1 stop bit, no parity
temp = PINSEL0;
PINSEL0 = (temp | 0x00000005); // Enable RxD0 and TxD0
}
void WriteToUART0(unsigned char c)
{
while ((U0LSR & 0x20) == 0); // wait for completion of previous data
U0THR = c;
}
unsigned char ReadFromUART0(void)
{
while ((U0LSR & 0x01) == 0); // wait for data
return U0RBR;
}
void InitializeUART1(unsigned int baudrate)
{
unsigned int temp;
unsigned int divisor = FREQ / (16 * baudrate);
U1LCR = 0x83; // DLAB = 1, 8 bit, 1 stop bit, no parity
U1DLL = divisor & 0xFF; // LSB
U1DLM = (divisor >> 8 ) & 0xFF; // MSB
U1LCR = 0x03; //DLAB = 0, 8 bit, 1 stop bit, no parity
temp = PINSEL0;
PINSEL0 = (temp | 0x00050000); // Enable RxD1 and TxD1
}
void WriteToUART1(unsigned char c)
{
while ((U1LSR & 0x20) == 0); // wait for completion of previous data
U1THR = c;
}
unsigned char ReadFromUART1(void)
{
while ((U1LSR & 0x01) == 0); // wait for data
return U1RBR;
}
int main(void)
{
unsigned char c;
InitializeUART0(9600);
InitializeUART1(9600);
while(1)
{
c = ReadFromUART1();
WriteToUART0(c);
}
return 0;
}
//////////////////////////////////////////////////////////////////////