我用的单片机是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;
}
}
贴出来的代码不是很全,看你现在的代码,去除注释掉的部分后,可以看出,如果gprs接收到的是换行回车,那么你都认为是接受到数据了!但是据我知道的,一帮情况下,接受函数会考虑如何过滤掉这样的没有实际意义的字符,包括在接收的过程中间过滤转义字符!
可能是流控问题,即如果buffer满了的情况程序可能不再接受数据或可能出现溢出
流控问题,即如果buffer满了的情况程序可能不再接受数据或可能出现溢出
硬件有没有问题?用示波器看看,看你的电平是不是很直? 还是有干扰?