ARM_Newer 发表于 2007-11-17 01:31:08

4510下的UART的问题

大家帮帮忙,我在4510下写了一个用UART口来实现printf的功能的函数,可是不知道为什么总是在红色的那一行上循环,总是检测不到可写状态。我看了半天4510的手册,可是还是没有搞懂。望大家指点。下面是代码
/*
* Serial settings.......................
*/

#ifndef SYSCFG
#define SYSCFG      0x03FF0000
#endif

#define UART0_BASE (SYSCFG + 0xD000)

/* add 19200 for test uue */
#define BAUD_19200 (80 << 4)

#define ULCON 0x00
#define UCON 0x04
#define USTAT 0x08
#define UTXBUF 0x0C
#define URXBUF 0x10
#define UBRDIV 0x14

/*
* Line control register bits............
*/

#define ULCR8bits (3)

/*
* UART Control Register bits............
*/

#defineUCRRxM (1)
#defineUCRRxSI (1 << 2)
#defineUCRTxM (1 << 3)
#defineUCRLPB (1 << 7)

/*
* UART Status Register bits
*/

#define USRTxHoldEmpty(1 << 6)
#define USRTxEmpty      (1 << 7)


// UART registers are on word aligned, D8

/* UART primitives */
#define GET_STATUS(p)(*(volatile unsigned*)((p) + USTAT))
#define RX_DATA(s)      ((s) & USRRxData)
#define GET_CHAR(p)      (*(volatile unsigned*)((p) + URXBUF))
#define TX_READY(s)      ((s) & USRTxHoldEmpty)
#define PUT_CHAR(p,c)   (*(unsigned*)((p) + UTXBUF) = (unsigned )(c))

void uart_init( unsigned int UART_BASE, unsigned int baud )
{
   /* Disable interrupts*/
   *(volatile unsigned *) (UART_BASE + UCON) = 0;
   /* Set port for 8 bit, one stop, no parity*/
   *(volatile unsigned *) (UART_BASE + ULCON) = (ULCR8bits);
   /* Enable interrupt operation on UART */
   *(volatile unsigned *) (UART_BASE + UCON) = UCRRxM | UCRTxM;
   /* Set baud rate*/
   *(volatile unsigned *) (UART_BASE + UBRDIV) = baud;
}

int uart_putchar( unsigned int UART_BASE, char ch )
{
/* read tx ready flag, when =1 break */
while(TX_READY( GET_STATUS( UART_BASE ) ) ==0 );

PUT_CHAR(UART_BASE, ch);

return ch;
}
页: [1]
查看完整版本: 4510下的UART的问题