为什么我的串口总丢数据
漫步月夜 2008-08-05 11:23:11 我用的单片机是renesas的r8c/25,和gprs通信接收到的数据总是丢字符,没有规律!接收是用的中断,优先级是最高,另外程序还有个Timer中断
void SendCommandToGPRS( unsigned char *Data )
{
unsigned char count = 0;
while ( Data[count] )
{
PutCharToGPRS(Data[count]);
count++;
}
}
void InitGPRSSerial( void )
{
/* Setting port direction registers */
pd1 = pd1 | 0x10; /* TXD0 port direction = output */
pd1 = pd1 & 0xDF; /* RXD0 port direction = input */
// pu03 = 1;
/* tiosel_traioc = 0;
tmod2_tramr = 0;
tmod1_tramr = 0;
tmod0_tramr =1;
*/
u0mr = 0x05; /* UART mode transfer data 8 bits long */
/* 1 stop bit */
/* Parity disabled */
u0c0 = 0x00; /* BRG count sorce :"f1" */
/* TXD0 pin is for CMOS output */
/* LSB first */
u0c1 = 0x10; /* Disables transmission */
/* Disables reception */
/* Transmission buffer empty causes UART0 transmit interrupt */
u0brg = 0x26; /* 6MHz/16*(38+1)=9615.3846153846 */
s0tic = 0x00; /* Disable UART0 transmit Interrupt */
s0ric = 0x07; /* enable UART0 receive Interrupt */
/*interrupt priority level select is 7*/
te_u0c1 = 1; /* Enables transmission */
re_u0c1 = 1; /* Enables reception */
}
#pragma INTERRUPT RevDataGPRS
void RevDataGPRS(void)
{
/* GPS mode Receive */
unsigned short rcv_work;
// static unsigned char CheckLineBuf[3];
// static unsigned char CheckTimes = 0;
rcv_work = u0rb; /* Read out the U0RB register in 16-bit units */
if ( (unsigned char)rcv_work == '\n' || (unsigned char)rcv_work == '\r' )
{
/* CheckLineBuf[CheckTimes] = (unsigned char)rcv_work;
if ( CheckTimes >= 1 )
{
CheckTimes = 0;
if ( CheckLineBuf[0] == '\r' )
{
if ( CheckLineBuf[1] == '\n' )
{
ReceiveALine = 0x01;
}
}
}
CheckTimes++;*/
ReceiveALine = 0x01;
}
else
{
// CheckTimes = 0;
ReceiveALine = 0x00;
}
REV_GPRS_BUF[RevGPRSCnt] = (unsigned char)rcv_work;
RevGPRSCnt++;
if ( RevGPRSCnt >= REV_GPRS_SIZE )
{
RevGPRSCnt = 0;
}
}