F133 RTSCTS LINE
-
Hi. I couldn't activate the RTS and CTS lines on the Mango pi sparrow F133 board. If I activate RTSCTS from the termios properties in the program (attr.c_cflag |= CRTSCTS;), it doesn't send data from the Tx line either.
If I deactivate RTSCTS (attr.c_cflag &= ~CRTSCTS;), it sends data but doesn't make the RTS line 0.I'm watching the lines with a logic analyzer. I see that the CTS line is 0. But RTS doesn't change at all.
What am I missing?
board.dts
&uart1 { uart-has-rtscts; pinctrl-names = "default", "sleep"; pinctrl-0 = <&uart1_pins_a>; pinctrl-1 = <&uart1_pins_b>; status = "okay"; };
sun8iw20p1.dtsi
code uart1: uart@2500400 { compatible = "allwinner,sun8i-uart"; device_type = "uart1"; reg = <0x0 0x02500400 0x0 0x400>; interrupts = <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>; sunxi,uart-fifosize = <256>; clocks = <&ccu CLK_BUS_UART1>; clock-names = "uart1"; resets = <&ccu RST_BUS_UART1>; uart1_port = <1>; uart1_type = <4>; status = "okay";_text
code
#include <stdio.h> #include <stdlib.h> #include <termios.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> static struct termios oldterminfo; void closeserial(int fd) { tcsetattr(fd, TCSANOW, &oldterminfo); if (close(fd) < 0) perror("closeserial()"); } int openserial(char *devicename) { int fd; struct termios attr; if ((fd = open(devicename, O_RDWR)) == -1) { perror("openserial(): open()"); return 0; } if (tcgetattr(fd, &oldterminfo) == -1) { perror("openserial(): tcgetattr()"); return 0; } attr = oldterminfo; attr.c_cflag |= B19200 | CRTSCTS | CLOCAL | CS7 | CSTOPB | PARENB; attr.c_cflag &= ~PARODD; //attr.c_cflag &= ~CRTSCTS; attr.c_oflag = 0; if (tcflush(fd, TCIOFLUSH) == -1) { perror("openserial(): tcflush()"); return 0; } if (tcsetattr(fd, TCSANOW, &attr) == -1) { perror("initserial(): tcsetattr()"); return 0; } return fd; } int setRTS(int fd, int level) { int status; if (ioctl(fd, TIOCMGET, &status) == -1) { perror("setRTS(): TIOCMGET"); return 0; } if (level) status |= TIOCM_RTS; else status &= ~TIOCM_RTS; if (ioctl(fd, TIOCMSET, &status) == -1) { perror("setRTS(): TIOCMSET"); return 0; } return 1; } int main() { unsigned char msg1[] = { 'G','0','1', '\r', '\n' }; unsigned char msg0[] = { 'G','0','0', '\r', '\n' }; int fd; char *serialdev = "/dev/ttyS1"; fd = openserial(serialdev); if (!fd) { fprintf(stderr, "Error while initializing %s.\n", serialdev); return 1; } setRTS(fd, 0); write(fd, &msg1, sizeof(msg1)); printf("1\r\n"); sleep(1); /* pause 1 second */ setRTS(fd, 1); write(fd, &msg0, sizeof(msg0)); printf("0\r\n"); sleep(1); /* pause 1 second */ closeserial(fd); return 0; }
-
check device tree first, check uart1_pins_a with RTS/CTS pin control
pinctrl-0 = <&uart1_pins_a>;
-
此回复已被删除! -
@kunyi
Thank you for your answer,
I am attaching board.dts file's relevant section, there is PG6 to PG9, Rx Tx RTS and CTS lines,uart1_pins_a: uart1_pins@0 { /* For EVB1 board */ pins = "PG6", "PG7", "PG8", "PG9"; function = "uart1"; drive-strength = <10>; bias-pull-up; }; uart1_pins_b: uart1_pins { /* For EVB1 board */ pins = "PG6", "PG7", "PG8", "PG9"; function = "gpio_in"; };
-
Okay, Maybe you can try the below code
#include <stdio.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include <unistd.h> #include <sys/ioctl.h> #include <linux/serial.h> #include <string.h> int main(int argc, char *argv[]) { // Open serial port ttyS1 const char *device = "/dev/ttyS1"; int fd = open(device, O_RDWR | O_NOCTTY); if (fd < 0) { perror("Error opening serial port"); return -1; } // Get the current serial port settings struct termios tty; if (tcgetattr(fd, &tty) < 0) { perror("Error getting port attributes"); close(fd); return -1; } // Configure the serial port settings // Clear all settings first tty.c_cflag = 0; tty.c_iflag = 0; // Enable receiver, ignore modem control lines tty.c_cflag |= CREAD | CLOCAL; // Enable hardware flow control (RTS/CTS) tty.c_cflag |= CRTSCTS; // Set baud rate to 19200 cfsetispeed(&tty, B19200); cfsetospeed(&tty, B19200); // Set 7 bits per byte tty.c_cflag |= CS7; // Enable even parity bit, without PARODD tty.c_cflag |= PARENB; // Set 2 stop bits tty.c_cflag |= CSTOPB; // Apply the new settings if (tcsetattr(fd, TCSANOW, &tty) < 0) { perror("Error setting port attributes"); close(fd); return -1; } printf("Serial port configured successfully\n"); printf("Port configuration:\n"); printf("- Device: %s\n", device); printf("- Baud rate: 19200\n"); printf("- Data bits: 7\n"); printf("- Parity: Even\n"); printf("- Stop bits: 2\n"); printf("- Flow control: RTS/CTS\n"); // Test string to send const char *test_string = "Hello! This is UART1\n"; ssize_t bytes_written = write(fd, test_string, strlen(test_string)); if (bytes_written < 0) { perror("Error writing to serial port"); } else { printf("\nSent %zd bytes: %s", bytes_written, test_string); } // Keep the port open briefly to ensure transmission sleep(1); // Close the serial port close(fd); return 0; }
-
This is the output of your code, when the flow control enabled, there is no UART1 output even if CTS=0,
=============================================================
if I disable CRTSCTS flow control, it pushes data to UART1 but no RTS
-
SOLVED,
I used a device to sniff UART between F133 and slave device,
Its RTS CTS line corrupted, so I removed it and everything ok now,thanks for your kind help
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号