Hi
We are using Philips LPC2138 ARM Controller in our proto board with 10 MHz external Crystal.
We tried to make use of UART0 with baudrate 2400. For that, the code is:
#define UART_CLK (10000000UL) //10MHz Crystal const unsigned char ABC[26]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; void uart0Init(void) { baud_val = ( (UART_CLK / 2400) / 16UL); U0IER = 0X00; U0IIR = 0X01; U0SCR = 0X00; U0FCR = 0X00; U0LCR = 0X00; U0MCR = 0X00; U0LSR = 0X60; U0LCR = 0X80; U0DLL = 0X00; U0DLM = 0X00; U0LCR = 0X00; U0LCR = 0x83;/* 8-bit bata, 1 stop bit, parity none */ U0DLL = (baud_val & 0xFF); U0DLM = (baud_val >> 8); U0LCR = 0X03; U0TER = 0X80; } void sendDataToUart0(const unsigned char i) { while(!(U0LSR & 0x20));/* If The Transmitter Ready Flag Is Set */ U0THR = i; /* Data Is Loaded Into The Transmitting Register */ } void delay(void) { unsigned int i; unsigned char k; for(k=0;k<75;k++) { for(i=0;i<50000;i++); } } void main(void) { unsigned char a=0; PCONP = 0X0000020A; /* Power Control for Peripherals register */ /* PCTIM0 = 1, PCUART0 = 1, PCRTC = 1 */ PINSEL0 |= 0X00000005; /* Pin Function Select Register 0 */ /* Select TXD (UART0) & RXD (UART0) */ uart0Init(); while(1) { delay(); sendDataToUart0(ABC[a]); a++; if(a == 25) a = 0; } }
The problem is the characters are being printed wrongly on serial com port.
Is there any missing in the above coding?
thanks in advance.
transmit 'U' (capital U) and put a scope on. You will see a square wave with a frequency of half the baudrate. Once you know what you get, the debug is easy.
Erik