# Problems with WP85 UART-2

**URL:** https://mangoh.discourse.group/t/problems-with-wp85-uart-2/1399
**Category:** mangOH Green
**Created:** [May 9, 2018, 12:33pm UTC](https://mangoh.discourse.group/t/problems-with-wp85-uart-2/1399 "2018-05-09T12:33:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jaison\_Ollukkaran](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Jaison\_Ollukkaran](https://mangoh.discourse.group/u/Jaison_Ollukkaran)
#### Post date: [May 9, 2018, 12:33pm UTC](https://mangoh.discourse.group/t/problems-with-wp85-uart-2/1399/1 "2018-05-09T12:33:35Z")

</div>

I am using WP8548 UART 1 & 2 ports to communicate with two sensors . The serial communication is for polling Modbus parameter registers 3 times in 30 sec delay.The polled data is then uploaded to Airvantage cloud.

In my code I am using tty channels as mentioned below-

#define UART1 “/dev/ttyHS0” // Aquagate Serial Port 1  
#define UART2 “/dev/ttyHSL1” //Aquagate Serial Port 2

port setup code-  
static void setupSerialUART\_MOdbus(char \* port)  
{  
// Open the serial port.

fd = open(port, O\_RDWR| O\_NONBLOCK | O\_NDELAY ); //Debug port

if (fd == -1)//check if device opened properly  
{  
LE\_INFO(“AutoWPtoAV:Open failed with error no: %d (%m)”, errno);  
}  
else  
{  
struct termios options; //config structure

if( tcgetattr(fd , &options) != 0)  
{  
LE\_INFO(“AutoWPtoAV:Read attributes failed with error no: %d (%m)”, errno);  
}  
/\* Set Baud Rate \*/

if(!strcmp(port,UART1)){

cfsetispeed (&options, B19200);  
cfsetospeed (&options, B19200);

LE\_INFO(“Opened Aquagate UART1 with 9600 baud rate”);

}

else if(!strcmp(port,UART2)){

cfsetispeed (&options, B19200);  
cfsetospeed (&options, B19200);

LE\_INFO(“Opened Aquagate UART2 with 19200 baud rate”);

}  
/\* Setting other Port Stuff \*/

```
    // Disable break and EOL character conversions.

```

options.c\_iflag &= ~(BRKINT | IGNCR | INLCR | ICRNL);

// Disable canonical, signal handling and local echo.  
options.c\_lflag &= ~(ICANON | IEXTEN | ISIG | ECHO);

// Disable post-processing and character conversion.  
options.c\_oflag &= ~(OPOST | ONLCR | OCRNL);

options.c\_cflag &= ~PARENB; // Make 8n1  
options.c\_cflag &= ~CSTOPB;  
options.c\_cflag &= ~CSIZE;  
options.c\_cflag |= CS8;  
options.c\_cflag &= ~CRTSCTS; // no flow control  
options.c\_cc[VMIN] = 1; // read doesn’t block : Interchar timer used  
options.c\_cc[VTIME] = 5; // 1 seconds read timeout : Inter character timeout (TIME is exceeded (t = TIME \*0.1 s).  
options.c\_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines  
cfmakeraw(&options); // Make raw  
tcflush( fd, TCIFLUSH ); //Flush Port, then applies attributes

if( tcsetattr(fd ,TCSANOW , &options) != 0)  
{  
LE\_INFO(“AutoWPtoAV:Set attributes failed with error no: %d (%m)”, errno);  
}  
}  
// Create a File Descriptor Monitor object for the serial port’s file descriptor.  
// Monitor for data available to read.  
fdSerial = le\_fdMonitor\_Create(“Serial Port”, // Name for diagnostics  
fd, // fd to monitor  
SerialPortHandler, // Handler function  
POLLOUT); // Monitor readability

}

when I am running my legato App code for UART polling with USB connected to my PC (Developer Studio), I am able to receive data from both the UART (1 & 2) without any problems.

 ![sierra_support_1L](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/ff2faea09022d5b3336bdc7fff51dc0f6e994784.PNG)

but when I am disconnecting USB from PC and running the same code, I am missing data from WP8548 UART2, same time UART 1 is working normally.

I had already configured both wp8548 UART’s for Linux applications.  
My Current WP8548 UART Configuration

![sierra_support_uart](https://us1.discourse-cdn.com/flex016/uploads/mangoh/original/1X/50e9f99223aa0473b99cda3f8e76cf8949ffebe1.PNG)

How do I can access my UART 2 of wp8548 same as USB connected even when USB is disconnected from PC…?  
Do I need to configure UART 2 differently…?

---

<div class="post-metadata">

### Author: ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)
#### Post date: [May 9, 2018, 9:27pm UTC](https://mangoh.discourse.group/t/problems-with-wp85-uart-2/1399/2 "2018-05-09T21:27:45Z")

</div>

I wonder if the device is going to sleep when you remove the USB cable. Take a look at the [legato.io docs on power management](http://legato.io/legato-docs/latest/conceptsPwrMgmt.html)
