티스토리 뷰
반응형
UART2통신을 하는데, RX는 정상인데, TX가 깨진다.
원인을 알 수 없다.
아래처럼 특정 서비스를 중지해봤으나, 동일하다.
sudo systemctl disable nvgetty
통신속도도 변경해봤지만 동일함.
다른 장치에와 연결하면 정상임.
문제의 코드
#define BAUD_RATE B115200
int uart2_fd;
int UART2_open() {
int bok=0;
struct termios options;
// Access modes (use 1 of these):
// O_RDONLY - Open for reading only.
// O_RDWR - Open for reading and writing.
// O_WRONLY - Open for writing only.
// O_NDELAY / O_NONBLOCK (same function)
// - Enables nonblocking mode. When set read requests on the file can return immediately with a failure status
// if there is no input immediately available (instead of blocking). Likewise, write requests can also return
// immediately with a failure status if the output can't be written immediately.
// Caution: VMIN and VTIME flags are ignored if O_NONBLOCK flag is set.
// O_NOCTTY - When set and path identifies a terminal device, open() shall not cause the terminal device to become the controlling terminal for the process.fid = open("/dev/ttyTHS1", O_RDWR | O_NOCTTY | O_NDELAY); //Open in non blocking read/write mode
uart2_fd = open(UART_DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
if (!UART2_is_open()) {
perror("Error opening UART");
}
else
{
// 통신 속도 및 기타 설정 초기화
// Baud rate:- B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B500000, B576000, B921600, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000
// CSIZE:- CS5, CS6, CS7, CS8
// CLOCAL - Ignore modem status lines
// CREAD - Enable receiver
// IGNPAR = Ignore characters with parity errors
// ICRNL - Map CR to NL on input (Use for ASCII comms where you want to auto correct end of line characters - don't use for bianry comms!)
// PARENB - Parity enable
// PARODD - Odd parity (else even)
tcgetattr(uart2_fd, &options);//GET
cfsetispeed(&options, BAUD_RATE);
cfsetospeed(&options, BAUD_RATE);
//options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;//no parity
options.c_cflag &= ~CSTOPB;//1STOP
//options.c_cflag = CSTOPB;//2STOP
options.c_cflag &= ~CSIZE;// Clears the mask for setting the data size
options.c_cflag |= CS8;//8bit
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);// Non Cannonical mode
options.c_iflag &= ~(IXON | IXOFF | IXANY); //Disable XON/XOFF flow control both input & output
options.c_oflag &= ~OPOST;// No Output Processing
options.c_lflag = 0; // enable raw input instead of canonical,
options.c_cc[VMIN] = VMIN; // Read at least 1 character
options.c_cc[VTIME] = 0; // Wait indefinetly
// 설정 적용
if (tcsetattr(uart2_fd, TCSANOW, &options) != 0) {//SET
perror("Error configuring UART");
close(uart2_fd);
uart2_fd=0;
}
else
{
bok=1;
}
}
return bok;
}
|
아래와 같이 "VER?\r\n"를 ECHO BACK한 경우 아래와 같이 PC에서는 깨져서 수신이 된다.
우분투에서는 정상적으로 수신이 됨.
우분투에서 TX할떄 데이터가 꺠지는듯 함.
PC쪽은 USB-232를 사용했고, 배선 길이는 약 70cm정도
오실로 스코프로 보니, 파형에 노이즈가 많이 낀다.
다른 보드와 UART 통신은 정상적으로 되는듯함.
아래와 같이 통신 테스트를 해보니, 깨지는데이터가 많음.
RX:=UART2 test RX:=01234567890123456789052345678901234567890123456789��������ʂ��������ʂ��������ꂊ�������ʂ���������j RX:=0123456789012745678901234567890123456789012345678901234567890123456789012345678901234567890123456789 RX:=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 RX:=01234577890L�&S��ʂ��������ʂ��������ʂ��������ʂ����������������ʂ��������ʂ��������ʂ���������j RX:=012345678901234567890123456789012345678901234567890123456789012345678901234567ʂ��������ʂ���������j RX:=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345689 RX:=0123456789012365678901234567890123456789012345678=01234567890123456789012345678903234567890123456789 RX:=01234567890123456789012345678901234567890123456789012345678901234567890123456w890133456789012345679 RX:=0123456789012345678901634567890123456789012345678901234567890123456789012345678901234567890123456789 RX:=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 RX:=012345678901234567890123456789012345678901234567890123456789012345v789012345678901234567890123456789 RX:=012345678901234567890123456789012345678901234567890�234567890123456789012�4567890123456789012345679 RX:=01234567890123456789012345678;012345678901234567890123456789012345>78901234567890123456789012345789 RX:=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345679 RX:=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 RX:=01234567890123456789012345678901234567890123<567890123456789012345678901234567890123456789012345679 RX:=012345678901235567890123456789012345678N��������ʂ��������ʂ��������ʂ��������ʂ��������ʂ���������j RX:=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ... |
PC와 테스트보드간 통신 테스트에서는 깨지는 데이터가 없음
(젯슨나노에서 UART 송신이 제대로 안되는듯함)
100msec딜레이를 주어도 깨짐...
반응형
'초보 우분투(리눅스)' 카테고리의 다른 글
USB로 파일 복사 쉘스크립트 (1) | 2024.02.25 |
---|---|
작성중 - 젯슨나노 - 우분투 - GPIO 제어 테스트 (1) | 2024.02.25 |
안됨 - #include 오류가 검색되었습니다. includePath를 업데이트하세요. 이 변환 단위(/home/a/Desktop/xxxx/sample1.c)에는 물결선을 사용할 수 없습니다. (0) | 2024.02.25 |
우분투에서 exFAT USB인식하기 (1) | 2024.02.25 |
우분투에서 txt파일을 마우스로 더블클릭하여 myprogram.exe 프로그램으로 여는 방법 (0) | 2024.02.25 |