# UART flow control with WP7608

**URL:** <https://forum.legato.io/t/uart-flow-control-with-wp7608/4597>\
**Category:** Uncategorized\
**Created:** [July 29, 2019, 8:57am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597 "2019-07-29T08:57:04Z")\
**Posts on this page:** 16\
**Page:** 3

<div class="post-metadata">

**Author:** ![TAK\_G](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TAK\_G](https://forum.legato.io/u/TAK_G)\
**Post date:** [September 3, 2019, 6:47am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/41 "2019-09-03T06:47:19Z")

</div>

Hi jyijyi,@jyijyi

Please answer Tanoue-san’s questions.

Thank you.

–TAK

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 3, 2019, 6:50am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/42 "2019-09-03T06:50:58Z")

</div>

didn’t i already answer?

---

<div class="post-metadata">

**Author:** ![TAK\_G](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TAK\_G](https://forum.legato.io/u/TAK_G)\
**Post date:** [September 3, 2019, 7:11am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/43 "2019-09-03T07:11:36Z")

</div>

Hi jyijyi,

Sorry for missing read since my browse still not be updated.

I think your answer is only for “how to read GPIO pins from Legato API”.  
And also, you suggestion is based on adding GPIO by the modification of “yocto/kernel/driver/gpio/gpiolib.c.”

Is my understanding correct?

If so , the customer needs to know all GPIO numbers of following pins.

RTS, DTR, DCD, RI, TxD , CTS, DSR, RxD

We know only DCD,DTR and DSR.

And, if you provide above information, I think we can read them by “cat” commands.

Thank you.

–TAK

---

<div class="post-metadata">

**Author:** ![TAK\_G](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TAK\_G](https://forum.legato.io/u/TAK_G)\
**Post date:** [September 3, 2019, 7:13am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/44 "2019-09-03T07:13:11Z")

</div>

Hi Tanoue-san,

> I think the best way to check all 8-wire UART’s pins with just one command.  
> It means I want to avoid mixing some type commands(echo/) on a program, if possible.

If we can provide GPIO numbers, I think you can read it by “cat” that I and jyijyi mentioned before.  
If you’d like to read it on command, you should make C source or shell like usual Linux application.

Thank you.

–TAK

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 3, 2019, 7:14am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/45 "2019-09-03T07:14:38Z")

</div>

I don’t recommend your suggestion.  
Here I have tried to put RTS/CTS/TXD/RXD inside “yocto/kernel/driver/gpio/gpiolib.c", after that if you turn them into GPIO, later you cannot use it to communicate as UART in legato application.  
That is why i suggest another way for accessing RTS (i.e. using AT comnand) and CTS (i.e. ioctl())pins.

---

<div class="post-metadata">

**Author:** ![TAK\_G](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TAK\_G](https://forum.legato.io/u/TAK_G)\
**Post date:** [September 3, 2019, 7:17am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/46 "2019-09-03T07:17:33Z")

</div>

Hi @jyijyi

> Here I have tried to put RTS/CTS/TXD/RXD inside “yocto/kernel/driver/gpio/gpiolib.c",  
> after that if you turn them into GPIO, later you cannot use it to communicate as UART in legato application.  
> That is why i suggest another way for RTS and CTS pins.

I wait this information !!!  
I understand why you suggested AT command to read RTS/CTS.

Hmm, is there any ways else to read RTS and CTS?  
There is no description of your suggested command in the latest AT command manual.  
So, we are not sure which parameter of return is read value.

Thank you.

–TAK

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 3, 2019, 8:51am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/47 "2019-09-03T08:51:12Z")

</div>

I cannot find another way to access RTS and CTS other than my previous suggestion.

I think using ioctl() to set CTS is the most proper way and standard way.  
Currently I have no idea why RTS cannot be read by ioctl().  
Below is the code to read the RTS status by AT command, let me know if you accept this.  
If no, we need a FW fix on this so that we can read RTS status by ioctl().

```
int get_RTS_status()
{

	 int fd_rts;
	 int sel,len,i;
	 int wrote = 0;
	 char * pch;

	 fd_set rfds;
	 unsigned char buf[1024];
	 unsigned char cmd[100];
	 struct timeval timeout;
	 fd_rts = open ("/dev/ttyAT", O_RDWR | O_NOCTTY | O_NDELAY);
      struct termios options;
      fcntl (fd_rts, F_SETFL, 0);
      tcgetattr (fd_rts, &options);
	  options.c_cflag |= (CLOCAL | CREAD);
	  options.c_cflag &= ~PARENB;
	  options.c_cflag &= ~CSTOPB;
	  options.c_cflag &= ~CSIZE;
	  options.c_cflag |= CS8;
	  options.c_cflag |= CRTSCTS;
	  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
	  options.c_iflag &= ~(INLCR | ICRNL | IGNCR);
	  options.c_oflag &= ~OPOST;
	  options.c_oflag &= ~OLCUC;
	  options.c_oflag &= ~ONLRET;
	  options.c_oflag &= ~ONOCR;
	  options.c_oflag &= ~OCRNL;
	  tcsetattr (fd_rts, TCSANOW, &options);

	  memset(cmd,0,sizeof(cmd));
	  strncpy(cmd,"AT!entercnd=\"A710\";!BSGPIO?6\r\n",30);
	  wrote = write (fd_rts, cmd, strlen (cmd));
	  LE_INFO("wrote %d ",wrote);
	  if (wrote<0)
	  {
		  LE_INFO("RTS = -1 ");
              close(fd_rts);
		  return -1;
	  }

	  tcdrain (fd_rts);
	   usleep (100000);

	   for (i = 0; i < 100; i++) {

	     FD_ZERO (&rfds);
	     FD_SET (fd_rts, &rfds);

	     timeout.tv_sec = 0;
	     timeout.tv_usec =10000 ;

	     if ((sel = select (fd_rts + 1, &rfds, NULL, NULL, &timeout)) > 0)
	     {
	       if (FD_ISSET (fd_rts, &rfds)) {
				memset (buf, 0, sizeof (buf));
				len = read (fd_rts, buf, sizeof (buf));
	       }

	     }
	   }

	     close(fd_rts);

	 	pch = strstr(buf, "State: 0");
	 	if (pch != NULL)
	 		{
	 		 	 LE_INFO("RTS =0 ");
	 		 	return 0;
	 		}
	 		else /* Substring not found */
	 		{
	 			LE_INFO("RTS =1 ");
	 			return 1;
	 		}

}

```

---

<div class="post-metadata">

**Author:** ![tanoue](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@tanoue](https://forum.legato.io/u/tanoue)\
**Post date:** [September 18, 2019, 3:17am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/48 "2019-09-18T03:17:56Z")

</div>

Hi, jyijyi

Thank you for suggesting a way to control CTS/RTS.  
I have two question.

According to “AirPrime\_WP76xx\_Product\_Technical\_Specification\_Rev9\_3.pdf”, There is the following note.

> Note: UART signals are named with respect to the host device, and directions are listed with  
> respect to the module. For example, UART1\_RX is an output from the module to the host.

1. 

I think that RTS is output and CTS is input.  
Is it correct?

1. 

If RTS is output, how to modify the following sentence?

> strncpy(cmd,“AT!entercnd="A710";!BSGPIO?6\r\n”,30);

BR,  
Tanoue

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 18, 2019, 3:58am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/49 "2019-09-18T03:58:29Z")

</div>

From the description of here about UART serial communication:

> **[UART - Serial communication](https://www.mikroe.com/blog/uart-serial-communication)**
>
> Universal Asynchronous Receiver/Transmitter or UART for short represents the hardware - integrated circuit,...

If “UART1\_RX is an output from the module to the host”, that means the PTS is assuming the module to be DCE.

For your question 1, it is not correct.  
According to the pinout table in PTS, UART1\_RTS is input and UART1\_CTS is output.

For your question 2, actually the RTS is input as stated above.

---

<div class="post-metadata">

**Author:** ![tanoue](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@tanoue](https://forum.legato.io/u/tanoue)\
**Post date:** [September 19, 2019, 12:35pm UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/50 "2019-09-19T12:35:27Z")

</div>

Hi, jyijyi

Thank you for kind explanation.

I could solve how to control RS232C’s pin about DTR, DSR, DCD and RI.

But CTS and RTS remain.

At first, I checked CTS control by reference to the following topic.

> [@\[Solved\]16.10.1 ioctl ttyHS0 CTS is an output but can I control it like this?](https://forum.legato.io/t/solved-16-10-1-ioctl-ttyhs0-cts-is-an-output-but-can-i-control-it-like-this/2451):
>
> Hi I’m trying to use legacy serial port code within a Legato app. I need to be able to control the state of the CTS OP pin (on a PC or USB tty this would be RTS out). ctx-\>s is a FILE pointer to /dev/ttyHS0 static void set\_OpLocal\_cbh(modbus\_t \*ctx , int on) { int fd = ctx-\>s; int flags; LE\_INFO("CTS set : %d", on); LE\_INFO("device %s", ctx-\>device); ioctl(fd, TIOCMGET, &flags); if (on) { flags |= TIOCM\_CTS; } else { flags &= ~TIOCM\_CTS; } ioctl(fd, TIOCMSET, &flags); } H…

However, I could not see changing voltage of CTS output.

Could you check my program?

> #include \<stdio.h\>  
> #include \<stdlib.h\>  
> #include \<termios.h\>  
> #include \<fcntl.h\>  
> #include \<sys/ioctl.h\>  
> #include \<unistd.h\>  
> #include \<string.h\>
> 
> int fd;
> 
> void ttyHS0\_Init()  
> {  
> struct termios options;
> 
> fd = open(“/dev/ttyHS0”, O\_RDWR | O\_NOCTTY);  
> if(fd \< 0) {  
> printf(“open /dev/ttyHS0 ERROR…\n”);  
> }
> 
> fcntl (fd, F\_SETFL, 0);  
> tcgetattr (fd, &options);  
> options.c\_cflag |= (CLOCAL | CREAD);  
> options.c\_cflag &= ~PARENB;  
> options.c\_cflag &= ~CSTOPB;  
> options.c\_cflag &= ~CSIZE;  
> options.c\_cflag |= CS8;  
> options.c\_cflag &= ~CRTSCTS;  
> options.c\_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);  
> options.c\_iflag &= ~(INLCR | ICRNL | IGNCR);  
> options.c\_oflag &= ~OPOST;  
> options.c\_oflag &= ~OLCUC;  
> options.c\_oflag &= ~ONLRET;  
> options.c\_oflag &= ~ONOCR;  
> options.c\_oflag &= ~OCRNL;  
> tcsetattr (fd, TCSANOW, &options);  
> }
> 
> void set\_CTS\_High()  
> {  
> int serialStatus = 0;
> 
> ioctl(fd, TIOCMGET, &serialStatus);
> 
> serialStatus |= TIOCM\_RTS;  
> ioctl(fd, TIOCMSET, &serialStatus);  
> }
> 
> void set\_CTS\_Low()  
> {  
> int serialStatus = 0;
> 
> ioctl(fd, TIOCMGET, &serialStatus);
> 
> serialStatus &= ~TIOCM\_RTS;  
> ioctl(fd, TIOCMSET, &serialStatus);  
> }
> 
> int main(void) {
> 
> // 5s CTS high low change  
> while(1) {  
> ttyHS0\_Init();  
> set\_CTS\_High();  
> printf(“============[HIGH] CTS========================\n”);  
> printf(“**[HIGH → LOW] after 5s**\n”);  
> sleep(5);  
> close(fd);  
> ttyHS0\_Init();  
> set\_CTS\_Low();  
> printf(“============[LOW] CTS=========================\n”);  
> printf(“**[LOW → HIGH] after 5s**\n”);  
> sleep(5);  
> close(fd);  
> }  
> return 0;  
> }

BR,  
Tanoue

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [September 20, 2019, 2:14am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/51 "2019-09-20T02:14:44Z")

</div>

Maybe you can run my sample application attached here.  
It will change the status of CTS every three seconds.  
It is working on my WP7608 FW R12.[UART\_Test1.rar](https://forum.legato.io/uploads/short-url/4AvEFawZzHvfUcT1URfB8G3VPHu.rar) (99.5 KB)

---

<div class="post-metadata">

**Author:** ![tanoue](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@tanoue](https://forum.legato.io/u/tanoue)\
**Post date:** [September 20, 2019, 10:51am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/52 "2019-09-20T10:51:03Z")

</div>

Hi, jyijyi

I could see changing voltage of CTS output with your program.  
Next, I will check RTS input signal by AT command.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![lwhblue](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/lwhblue/32/944_2.png) [@lwhblue](https://forum.legato.io/u/lwhblue)\
**Post date:** [February 15, 2020, 9:17am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/53 "2020-02-15T09:17:46Z")

</div>

Hi, jyijyi  
From your reply, I think using ioctl() can set the CTS pin。  
But if I want to get RTS pin status, Can I use the output of ioctl(fd1, TIOCMGET, &arg) ？  
Or the only way I can do is using AT command?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 15, 2020, 10:40am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/54 "2020-02-15T10:40:54Z")

</div>

I think so, i remember only AT command works for RTS.

---

<div class="post-metadata">

**Author:** ![lwhblue](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/lwhblue/32/944_2.png) [@lwhblue](https://forum.legato.io/u/lwhblue)\
**Post date:** [February 17, 2020, 6:26am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/55 "2020-02-17T06:26:00Z")

</div>

Hi, jyijyi  
Thanks for your answer 。  
But I still don’t know the following AT command’s meanings

> [@tanoue](#):
>
> strncpy(cmd,“AT!entercnd=“A710”;!BSGPIO?6\r\n”,30);

I find nothing with “!BSGPIO?” in the file named 【4118047 WPx5xx-76xx-77xx AT Command Reference\_r7.1.pdf】  
Can you tell me more information about this AT command？  
Thanks！

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 17, 2020, 6:39am UTC](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597/56 "2020-02-17T06:39:19Z")

</div>

I don’t have full information.  
But you can refer to UART\_Test1.rar on how to read the status.

[Previous page](https://forum.legato.io/t/uart-flow-control-with-wp7608/4597.md?page=2)
