小弟最近在折腾TI的一款串口芯片,现在能够实现数据的接受,而发送却一直出现问题,一直发送D5(无论我想叫它发送什么),下面是我的程序大家帮忙看一下:
// Project Stationery //
//////////////////////////////
#include <stdio.h>
#define hong short
#define BSC_UARTB 0x01
#define BUAD_9K6_L 0x90 //22.1184M changed by asky
#define BUAD_9K6_H 0x00
#define UARTINT_RHR 0x01 /*set rcv int*/
#define UARTINT_THR 0x02 /*set send int*/
#define BSC_UARTA_ADDR 0xfa000080
#define BSC_UARTB_ADDR 0xfa000000
#define TX_ENABLE 0x08
#define RX_ENABLE 0x0B
enum
{
UART_RHR_THR = 0x00, /* 0 */
UART_IER = 0x02, /* 1 */
UART_FCR_IIR = 0x04, /* 2 */
UART_LCR = 0x06, /* 3 */
UART_MCR = 0x08, /* 4 */
UART_LSR = 0x0a, /* 5 */
UART_MSR = 0x0c, /* 6 */
UART_SPR = 0x0e /* 7 */
};
enum
{
UART_DLL = 0x00,
UART_DLH = 0x02,
UART_EFR = 0x04,
UART_NULL = 0x06,
UART_XON1 = 0x08,
UART_XON2 = 0x0a,
UART_XOFF1_TCR = 0x0c,
UART_XOFF2_TLR_FIFORDY = 0x0e
};
asm void system_call();
asm void system_call()
{
nofralloc
sc
blr
}
unsigned char BSC_TL16C752B_WRITE_REG(unsigned char channal,unsigned char reg,unsigned char val);//int val->char val
unsigned char BSC_TL16C752B_READ_REG(unsigned char channal,unsigned char reg);
void TL16C752B_init ();
void TL16C752B_putc (unsigned char c);//int - char
char TL16C752B_getc ();
int TL16C752B_tstc ();
////////////////////////////////////////////////////////////
// tl16c752b init //
////////////////////////////////////////////////////////////
void TL16C752B_init()
{
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_IER, 0x00);
//baud set
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_LCR, 0x80); //divisor_enable 8bit_data 1bit_stop
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_DLL, BUAD_9K6_L); //baud 9600
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_DLH, BUAD_9K6_H);
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_LCR, 0x03); //divisor_disable 8bit_data 1bit_stop
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_FCR_IIR, 0x07); //ADD BY ASKY
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_MCR, 0x00);
}
void TL16C752B_putc (unsigned char c) //int -> char
{
while (( BSC_TL16C752B_READ_REG(BSC_UARTB, UART_LSR) & 0x20) == 0);
BSC_TL16C752B_WRITE_REG(BSC_UARTB, UART_RHR_THR, c); //add by asky
}
char TL16C752B_getc ()
{
while ((BSC_TL16C752B_READ_REG(BSC_UARTB, UART_LSR) & 0x01) == 0) {
}
return (BSC_TL16C752B_READ_REG(BSC_UARTB, UART_RHR_THR)); //add by asky
}
int TL16C752B_tstc ()
{
return ((BSC_TL16C752B_READ_REG(BSC_UARTB, UART_LSR) & 0x01) != 0);
}
unsigned char BSC_TL16C752B_WRITE_REG(unsigned char channal,unsigned char reg,unsigned char val)//int val -> char val
{
volatile unsigned char *temp;
temp = 0; //add by asky
if(channal == 0)
{
temp = (volatile unsigned char*)(BSC_UARTA_ADDR + reg );
}
else if(channal == 1)
{
temp = (volatile unsigned char*)(BSC_UARTB_ADDR + reg );
}
*temp = val;
return 0;
}
unsigned char BSC_TL16C752B_READ_REG(unsigned char channal,unsigned char reg)
{
unsigned char value = 0;
volatile unsigned char *temp;
temp = 0;
if(channal == 0)
{
temp = (volatile unsigned char*)(BSC_UARTA_ADDR + reg );
}
else if(channal == 1)
{
temp = (volatile unsigned char*)(BSC_UARTB_ADDR + reg );
}
value = *temp;
return value;
}
void Delay(unsigned int i)
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<i;k++);
}
void main()
{
printf("Welcome to CodeWarrior!\r\n");
TL16C752B_init();
while(1)
{
m = TL16C752B_getc();
Delay(1000);
TL16C752B_putc(m);
}
}
串口芯片管脚测试过了没有问题,波特率设置没有问题,还可能是什么原因呢? |