VPBDIV register
2006-02-28 by dodge1955
Can someone help me with this problem? See the code below. I have
UART1 set up to print "Hello Test", but I can't get it to work with a
12Mhz clock, which is what is on the Eval boards. I am using
currently the Embedded Artists board with the 12Mhz clock. If I set
the U1DLL to 0x61, which is a 15Mhz clock, and leave VPBDIV = 0 (1/4
processor clock) it works fine (as in the code below). If I set
VPBDIV = 1 (equal to the processor clock), or if I set the U1DLL to a
value for 12Mhz, it stops working. So, I guess I don't quite
understand how all those registers work. Can someone explain? Is
there something in the Startup code that overrides? Thanks.
char txbuffer[25];
void my_putchar(char c)
{
while((U1LSR & 0x20) == 0); // if not empty, wait
U1THR = c;
}
void myprint()
{
unsigned char i;
i = 0;
while (i < strlen(txbuffer))
{
if (((U1LSR & 0x20) != 0) && txbuffer[i])
{
U1THR = txbuffer[i++];
}
}
}
void set_up_uart1()
{
// VPBDIV = 1; // VPB clk (PCLK) same as processor clock (CCLK)
PLL0CON = 0; // not using PLL, since PCLK = oscillator clock
PLL1CON = 0; // not used
PINSEL0 |= 0x00010000;
PCONP |= 0x00000010;
U1LCR |= 0x80; // enable Divisor Latches
U1FDR = 0x00000010; // MULVAL = 1, DIVVAL = 0
U1DLM = 0; // 15000000 / 9600 / 16 = 97 = 0x61
U1DLL = 0x61; // 9600 baud, but at 15Mhz
U1LCR = 0x03; // 8 bits, 1 stop, no parity, DLAB = 0
U1FCR = 1;
}
void
main()
{
set_up_uart1();
sprintf(txbuffer, "Hello Test\r\n");
while(1)
{
myprint();
}
}