Content originally posted in LPCWare by yateesh_me on Tue Oct 12 03:49:00 MST 2010
Hi unnati,
I'm doing serial communication test,the following is my code.
#include "LPC11xx.h"
#define IER_RBR 0x01
#define IER_THRE 0x02
#define IER_RLS 0x04
#define LSR_RDR 0x01
#define LSR_THRE 0x20
#define BUFSIZE 0x40
#define SystemFrequency SystemCoreClock
#define SystemCoreClock 12000000UL
void UARTInit(unsigned int Baudrate);
void UARTSend(void);
void UARTRecv(void);
volatile unsigned char UARTBuffer[40],RECV;
int main (void) { UARTInit(9600);
while (1)
{
UARTRecv(); UARTSend();
}
}
/*=========================================================================================*/
void UARTInit(unsigned int baudrate)
{
unsigned int regVal; unsigned int Fdiv;
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 */
LPC_GPIO0->DIR |= (1<<1);
LPC_IOCON->PIO0_1 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO0_1 |= 0x01; /* clock out*/
LPC_SYSCON->SYSPLLCLKSEL = 0x00; //0-IRC,1-SYS Osc
LPC_SYSCON->SYSPLLCLKUEN = 0x01;
LPC_SYSCON->SYSPLLCLKUEN = 0x00;
LPC_SYSCON->SYSPLLCLKUEN = 0x01;
LPC_SYSCON->MAINCLKSEL = 0x00; //0-IRC Osc,1-PLL i/p,2-WDT,3-PLL o/p
LPC_SYSCON->MAINCLKUEN = 0x01;
LPC_SYSCON->MAINCLKUEN = 0x00;
LPC_SYSCON->MAINCLKUEN = 0x01;
while (!(LPC_SYSCON->MAINCLKUEN & 0x01));
LPC_SYSCON->CLKOUTCLKSEL = 0x00; // 0-IRC,1-Sys Osc,2-WD Osc,3-Main clk
LPC_SYSCON-j>CLKOUTCLKSEL = 0x01;
LPC_SYSCON->CLKOUTCLKSEL = 0x00;
LPC_SYSCON->CLKOUTCLKSEL = 0x01;
LPC_SYSCON->SYSPLLCTRL = 0x00000180;
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); // UART CLK enable
LPC_SYSCON->UARTCLKDIV = 0x01; /* divided by 1 , like pre-scaler*/
LPC_UART->LCR = 0x83; /* DLB=1, 8 bits, no Parity, 1 Stop bit */ regVal =
LPC_SYSCON->UARTCLKDIV;
Fdiv = (((SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ;
LPC_UART->DLM = Fdiv / 256; LPC_UART->DLL = Fdiv % 256;
LPC_UART->LCR = 0x03; /* DLAB = 0 ,Disable access to divisor latches*/
LPC_UART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
regVal = LPC_UART->LSR; /* Read to clear the line status. */ return;
}
void UARTSend()
{
LPC_UART->THR = RECV;
while ( !(LPC_UART->LSR & 0x40) //wait until TEMT=0,i.e. U0THR contains valid data
}
void UARTRecv()
{
while(!(LPC_UART->LSR & (0x01)));
RECV=LPC_UART->RBR;
}
The following are my problems:
1. Is this code correct, in using clocks?
2. I'm not getting 12Mhz signal at P0.1,why?
3. Using this snippet I want to test serial communication,but I'm getting simulation o/p only. I am not getting o/p from micro controller after dumping. why?
Any suggestions from you are of great help to me.....
In advance Thank you...