xpress_embedo
Advanced Member level 4
- Joined
- Jul 5, 2011
- Messages
- 1,154
- Helped
- 161
- Reputation
- 396
- Reaction score
- 189
- Trophy points
- 1,353
- Location
- India
- Activity points
- 10,591
Hello!! I am using Keil IDE along with MDK Compiler for ARM LPC1343 Programming.
I want to send some data on UART using LPC1343, i write a code but it is not working on Real Hardware, when i tried to debug it in Keil Simulator it works fine, what might be the problem, can anyone please help me.
Here is my Code:-
NOTE:- My Development Board is Ok, as i had tested it with Code written in CoIDE and GNU ARM Compiler, but it consist of UART drivers.
I want to send some data on UART using LPC1343, i write a code but it is not working on Real Hardware, when i tried to debug it in Keil Simulator it works fine, what might be the problem, can anyone please help me.
Here is my Code:-
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 #include <LPC13xx.h> #define TEST_LED1 (1 << 11) #define TEST_LED2 (1 << 10) void UART_Init(void); void UART_Write(unsigned char value); void UART_Write_Text(unsigned char *msg); unsigned char UART_Read(void); void Delay_ms(unsigned int time) { unsigned int i,j; for(i=0;i<time;i++) { for(j=0;j<1005;j++) ; } } int main() { unsigned char msg[] = "EDA BOARD\r\n"; SystemCoreClockUpdate(); /*Update SystemCoreClock according to register settings */ UART_Init(); Delay_ms(100); UART_Write_Text(msg); while(1) { UART_Write(UART_Read()); } } /****************Function Definition**********/ void UART_Init(void) { LPC_IOCON->PIO1_6 &= ~0x07; /*UART I/O config*/ LPC_IOCON->PIO1_6 |= 0x01; /*UART RXD*/ LPC_IOCON->PIO1_7 &= ~0x07; LPC_IOCON->PIO1_7 |= 0x01; /*UART TXD*/ /*Enable UART clock*/ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->UARTCLKDIV = 0x4; /*divided by 4*/ /*Core is Operating at 72MHz Hence UART is Operating at 72/4=18MHz*/ LPC_UART->LCR = 0x83; /*8 bits, no Parity, 1 Stop bit*/ LPC_UART->DLM = 0x00; LPC_UART->DLL = 0x75; /*9600 bps Baud Rate*/ LPC_UART->LCR = 0x03; /*DLAB = 0*/ LPC_UART->FCR = 0x07; /*Enable and reset TX and RX FIFO*/ } void UART_Write(unsigned char value) { /* THRE bit can be extracted by this U0LSR & 0x20 THRE = 0 means data is present. THRE = 1 means register is empty. In order to transmit data, we have to wait will the THRE = 1, then only we can transmit data. */ while(!(LPC_UART->LSR&0x20)); //THRE = 0 stay here LPC_UART->THR = value; } void UART_Write_Text(unsigned char *msg) { while(*msg) { UART_Write(*msg); msg++; } } unsigned char UART_Read(void) { /* Receiver Data Ready = U0LSR.0 bit RDR bit can be extracted by this U0LSR & 0x01 RDR = 0 means no Data is Received in U0RBR RDR = 1 means that Data is present in U0RBR */ while(!(LPC_UART->LSR & 0x01)); //RDR = 0 stay here return (LPC_UART->RBR); } /*********************************************/
NOTE:- My Development Board is Ok, as i had tested it with Code written in CoIDE and GNU ARM Compiler, but it consist of UART drivers.
Last edited: