串口接收数据不完整
本帖最后由 lzm 于 2010-09-08 16:48:08 编辑
/*********************************************
UART1初始化程序
*********************************************/
STATUS UART1P_Init(void)
{
sfd = open("/tyCo/1",O_RDWR,0);
if(sfd!=ERROR)
{
ioctl(sfd, FIOSETOPTIONS, OPT_RAW);/*RAW模式*/
ioctl(sfd, FIOBAUDRATE, 9600);/*9600 bps*/
ioctl(sfd, SIO_HW_OPTS_SET, CS8|PARENB);
return OK;
};
return ERROR;
}
//主要接收代码
while(1)
{
stat = *((unsigned int *)(USTAT1));
if((stat&UART1_TC)==UART1_TC) break;
};
*((unsigned int *)(UCON1)) |= 0x20;
for(i=0,sum=0;i<100;i++)
{
ioctl(sfd,FIONREAD,(int)&len);
if(len>0)
{
len = read(sfd,rbuf+sum,1023-sum);
sum += len;
};
taskDelay(10);
};