为什么我的串口总丢数据

漫步月夜 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;
}
}
...全文
367 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sherlock_lai 2008-11-29
  • 打赏
  • 举报
回复
硬件有没有问题?用示波器看看,看你的电平是不是很直? 还是有干扰?
CoSoDoNo 2008-11-28
  • 打赏
  • 举报
回复
学习。
yxlorange 2008-11-23
  • 打赏
  • 举报
回复
先看看丢掉的字符数据有和规律,1楼说的很有可能。
beyondma 2008-11-23
  • 打赏
  • 举报
回复
顶一楼的,从你现在的代码看,不像是缓存区的问题
Gdatasheet 2008-11-16
  • 打赏
  • 举报
回复
流控问题,即如果buffer满了的情况程序可能不再接受数据或可能出现溢出
CedarDiao 2008-11-15
  • 打赏
  • 举报
回复
可能是流控问题,即如果buffer满了的情况程序可能不再接受数据或可能出现溢出
yinjinzhong 2008-08-06
  • 打赏
  • 举报
回复
贴出来的代码不是很全,看你现在的代码,去除注释掉的部分后,可以看出,如果gprs接收到的是换行回车,那么你都认为是接受到数据了!但是据我知道的,一帮情况下,接受函数会考虑如何过滤掉这样的没有实际意义的字符,包括在接收的过程中间过滤转义字符!

3,849

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 无线
社区管理员
  • 无线
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧