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;
}