기존 이솝 임베디드 포럼의 지식인 서비스가 게시판 형태로 변경되었습니다.
아래와 같이 시험중인데
UART baud rate를 9600 일때는 수신데이타가 소실되는 경우가 없고
115200,일때는 데이타가 소실됩니다.
위와같은 현상은 왜일어나는것인가요..??
아래는 테스트 소스입니다.
int main(void)
{
#ifdef Debug
printf("main --> Start !!\n");
printf("SerialRead Call !!\n");
#endif
SerialRead();
return 0;
}
void SerialRead()
{
static int rx_size = 0, r_total = 0, success_count = 0;
char buf[1]={0}, buf1[BUFSIZE]={0};
int fd=0, r=0; // file descript
int i = 0, cnt = 0;
#ifdef Debug
printf("SerialRead ---> Start !!\n");
printf("TouchPort Open !!\n");
#endif
fd = open(TOUCHPORT, O_RDWR | O_NOCTTY | O_NONBLOCK);
if ( fd < 0 )
{
perror(TOUCHPORT);
//close(fd);
exit(-1);
}
#ifdef SerialSet
#ifdef Debug
printf("SerialSet .. Start !!\n");
#endif
struct termios tio;
tcgetattr(fd,&tio);
tio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | HUPCL;
//tio.c_iflag = IGNPAR | ICRNL; //non-parity
tio.c_iflag = IGNPAR; //non-parity
tio.c_oflag = 0;
/* set input mode (non-canonical, no echo...) */
tio.c_lflag = 0;
/* See Serial Programming How-To Documents */
tio.c_cc[VTIME] = 1;
tio.c_cc[VMIN] = 0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&tio);
#ifdef Debug
printf("SerialSet .. End !!\n");
#endif
#endif // SerialSet
#ifdef Debug
printf("TouchPort descript ==> %d\n",fd);
printf("Read Call !! \n");
#endif
while(1)
{
r = read (fd, buf, sizeof(buf));
if( r <= 0)
{
//perror("read() fail !!");
//close(r);
//exit(-1);
continue;
}
r_total += r;
for ( i = 0; i < r; i++ )
{
buf1[rx_size] = buf[i];
printf("buf[%d]=%d\n", rx_size, buf1[rx_size]);
if(rx_size != buf1[rx_size])
{
while(1){}
}
rx_size++;
if(rx_size==99)
{
success_count++;
printf("Count:%d\n", (success_count/11));
rx_size = 0;
}
}
memset(buf,0,sizeof(buf));
} // while
} // SerialRead()
답답하네요 고수님들 조언좀 부탁드립니다.
uart chip의 clock이 baud rate로 정확히 나누어 떨어지지 않는 경우에 발생할 수 있습니다