보드에서 시리얼통신을 하는데 printf()가 동작을 방해합니다.

dksoul의 이미지

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>

#define LINESPEED B19200

int main (void)
{
   int fd, res;
   struct termios oldterm, newterm;
   char buf='w';

   fd= open ("/dev/ttyS2", O_RDWR | O_NOCTTY );
   if (fd < 0) {
      perror ("/dev/ttyS2");
      exit (-1);
   }

   tcgetattr (fd, &oldterm);

   bzero (&newterm, sizeof (newterm));
   newterm.c_cflag= LINESPEED | CS8 | CLOCAL | CREAD;
   newterm.c_cflag&=~CRTSCTS;
   newterm.c_cflag&=~CSTOPB;
   newterm.c_cflag&=~(PARENB|PARODD);
  
   newterm.c_iflag = IGNPAR;
   newterm.c_oflag = 0;

   tcflush (fd, TCIFLUSH);
   tcsetattr (fd, TCSANOW, &newterm);
  
   res = write (fd, &buf, sizeof(char));
   if(res==1)
	   printf("success.\n");   
   tcsetattr (fd, TCSANOW, &oldterm);
   exit (1);
}

ARM보드에서 시리얼을 통해 원하는 캐릭터를 넘겨주려고 합니다. 이상하게도 캐릭터를 시리얼에 라이트하기전에 printf()함수를 넣으면 이상한 캐릭터가 전달됩니다. 혹시 왜 그런지 아시는 분 답변주시면 감사하겠습니다. ^^

익명 사용자의 이미지

printf 문도 시리얼을 통해 값이 전달 될 것이고, printf문 수행 후에 rs232디바이스의 버퍼(하드웨어) 에 그 값이 남아 있어서 발생한는 문제 같습니다.