# WP7608 -- RS232 Communication problems

**URL:** <https://forum.legato.io/t/wp7608-rs232-communication-problems/4032>\
**Category:** Uncategorized\
**Created:** [January 18, 2019, 6:57am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032 "2019-01-18T06:57:52Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [January 18, 2019, 6:57am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/1 "2019-01-18T06:57:52Z")

</div>

Hi:

Legato version:  
18.03.0\_b463e04cf08fb8d8f1ea5ee00d7894c0

question :  
Through RS232 sent to WP76 development board, received the first message is scrambled or missing

Thank you for your reply.

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [January 18, 2019, 7:27am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/2 "2019-01-18T07:27:00Z")

</div>

WP8548(18.06.4\_a2b118ed13919cebd20f9d71e8810748\_modified) no problem.

---

<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:** [January 18, 2019, 8:50am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/3 "2019-01-18T08:50:58Z")

</div>

Do you mean the first character is missing?  
You can try my code see if this fixed the issue:

```
#define TIMER_INTERVAL_SEC 1
#define TIMER_INTERVAL_uSEC 100000
static void tmrHandler(le_timer_Ref_t timerRef) {
	 //LE_INFO("INSIDE TIMER");
	 tcflow(fd1,TCION );

}
COMPONENT_INIT
{

		LE_INFO("UART_TCP_DEMO");
#if 1
		fd1=OpenPort("/dev/ttyHS0");

		le_clk_Time_t clk = { .sec = TIMER_INTERVAL_SEC, .usec = TIMER_INTERVAL_uSEC };
		    le_timer_Ref_t adxlPollingTimer = le_timer_Create("ADXL_TIMER");
		    le_timer_SetRepeat(adxlPollingTimer, 1000);
		    le_timer_SetInterval(adxlPollingTimer, clk);
		    le_timer_SetHandler(adxlPollingTimer, tmrHandler);
		    le_timer_Start(adxlPollingTimer);

```

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [January 21, 2019, 3:33am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/4 "2019-01-21T03:33:58Z")

</div>

Thank you for your reply.

Your code is incomplete. Here’s my code.

#include “rs232.h”  
#include “LEDLightUpComponent.h”  
#include “CloudIF\_VendOut.h”

int fd;  
struct termios opt;  
char rs232readbuf[MSG\_LEN\_MAX] = {0};

#if 1  
static tty\_Speed\_t SpeedTestTable[\*] =  
{  
LE\_TTY\_SPEED\_0,  
LE\_TTY\_SPEED\_50,  
LE\_TTY\_SPEED\_75,  
LE\_TTY\_SPEED\_110,  
LE\_TTY\_SPEED\_134,  
LE\_TTY\_SPEED\_150,  
LE\_TTY\_SPEED\_200,  
LE\_TTY\_SPEED\_300,  
LE\_TTY\_SPEED\_600,  
LE\_TTY\_SPEED\_1200,  
LE\_TTY\_SPEED\_1800,  
LE\_TTY\_SPEED\_2400,  
LE\_TTY\_SPEED\_4800,  
LE\_TTY\_SPEED\_9600,  
LE\_TTY\_SPEED\_19200,  
LE\_TTY\_SPEED\_38400,  
LE\_TTY\_SPEED\_57600,  
LE\_TTY\_SPEED\_115200,  
LE\_TTY\_SPEED\_230400,  
LE\_TTY\_SPEED\_460800,  
LE\_TTY\_SPEED\_500000,  
LE\_TTY\_SPEED\_576000,  
LE\_TTY\_SPEED\_921600,  
LE\_TTY\_SPEED\_1000000,  
LE\_TTY\_SPEED\_1152000,  
LE\_TTY\_SPEED\_1500000,  
LE\_TTY\_SPEED\_2000000,  
LE\_TTY\_SPEED\_2500000,  
LE\_TTY\_SPEED\_3000000,  
LE\_TTY\_SPEED\_3500000,  
LE\_TTY\_SPEED\_4000000,  
};  
#endif

static void\* read\_thread(void\* context)  
{  
char buf[1024];  
ssize\_t read\_NUM = 0;

```
memset(buf, 0, sizeof(buf));

while(1)
{
	read_NUM = read(fd, buf, sizeof(buf));
	if(read_NUM > 0)
	{
		printf("Windows: %s\n", buf);

		strncpy(rs232readbuf, buf, strlen(buf));
		if(rs232readbuf[0] == '{')
		{
			check_VendOut(rs232readbuf);
		}
		//rs232_LEDbuf(rs232readbuf);
	}

	memset(buf, 0, sizeof(buf));
}

return NULL;

```

}

int open\_init(void)  
{  
le\_thread\_Ref\_t readThreadPtr;

```
fd = le_tty_Open("/dev/ttyHS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
	perror("open /dev/ttyHS0: ");
}

le_tty_SetBaudRate(fd, SpeedTestTable[17]); //17
le_tty_SetFraming(fd, 'N', 8, 1);
le_tty_SetFlowControl(fd, LE_TTY_FLOW_CONTROL_NONE);
le_tty_SetRaw(fd, 2048, 0);

readThreadPtr = le_thread_Create("read_thread", read_thread, NULL);
le_thread_Start(readThreadPtr);

return fd;

```

}

---

<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:** [January 21, 2019, 3:46am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/5 "2019-01-21T03:46:32Z")

</div>

you don’t need to have my full code.  
my idea is to start a periodic timer and call the tcflow(fd1,TCION ) every second.

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [January 22, 2019, 5:17am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/6 "2019-01-22T05:17:43Z")

</div>

```
indent preformatted text by 4 spaces

```

Jan 6 00:04:31 | rs232\_wp76[2329]/rs232\_wp76\_exe T=main | \_main.c main() 60 | == Starting Event Processing Loop ==  
Jan 6 00:04:31 | rs232\_wp76[2329]/RS232\_wp76Component T=main | RS232\_wp76Component.c \_RS232\_wp76Component\_COMPONENT\_INIT() 50 | UART\_TCP\_DEMO  
Jan 6 00:04:31 | rs232\_wp76[2329]/framework `Preformatted text`T=main | LE\_FILENAME le\_tty\_Open() 247 | Serial device ‘/dev/ttyHS0’ acquired by pid 2329.  
Jan 6 00:04:31 | rs232\_wp76[2329]/framework T=main | LE\_FILENAME le\_timer\_Start() 1260 | threadRecPtr-\>timerFD=9

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [January 22, 2019, 5:21am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/7 "2019-01-22T05:21:29Z")

</div>

I don’t see any useful information.  
I suspect WP76’s wake-up call has something to do with it, but I don’t know how to investigate it.

---

<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:** [January 22, 2019, 5:56am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/8 "2019-01-22T05:56:03Z")

</div>

I thought you are having same problem as this topic:

> **[Problem with Reading UART](https://forum.sierrawireless.com/t/problem-with-reading-uart/13322/2)**
>
> Which module are you using ? I remember in WP77 R8, the UART will go to sleep mode after some time. Maybe you can have a try on R9 FW. Or you can try using a timer to periodically wake up the UART; #define TIMER\_INTERVAL\_SEC 1 #define...

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [January 22, 2019, 6:03am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/9 "2019-01-22T06:03:39Z")

</div>

thank you.  
I take a look.

---

<div class="post-metadata">

**Author:** ![plu](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@plu](https://forum.legato.io/u/plu)\
**Post date:** [January 31, 2019, 2:39pm UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/10 "2019-01-31T14:39:07Z")

</div>

hi @taojiafu,  
do you need more information on this topic?  
best regards,

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [February 2, 2019, 2:06am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/11 "2019-02-02T02:06:06Z")

</div>

I suspect wp76 is in sleep mode, but I don’t know how to turn it off.

---

<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 2, 2019, 8:59am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/12 "2019-02-02T08:59:16Z")

</div>

That is why in my workaround, i need to set up a timer to wake up uart

---

<div class="post-metadata">

**Author:** ![taojiafu](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@taojiafu](https://forum.legato.io/u/taojiafu)\
**Post date:** [February 2, 2019, 9:02am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/13 "2019-02-02T09:02:13Z")

</div>

Can I set it without AT instruction?

---

<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 2, 2019, 9:48am UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/14 "2019-02-02T09:48:56Z")

</div>

What do you mean by AT instruction?

---

<div class="post-metadata">

**Author:** ![JayM2M](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JayM2M](https://forum.legato.io/u/JayM2M)\
**Post date:** [February 4, 2019, 5:03pm UTC](https://forum.legato.io/t/wp7608-rs232-communication-problems/4032/15 "2019-02-04T17:03:13Z")

</div>

Hi,

In order to prevent the WP76 module to enter sleep mode then you need to acquire a wakeup source in your application:

> **[Power Management - Legato Docs](https://docs.legato.io/latest/conceptsPwrMgmt.html#conceptsPwrMgmt_wakeupSources)**
>
> legato™ is an open source Linux-based embedded platform designed to simplify connected IoT application development

If you want to turn off the whole power suspend mechanism (for testing) then you can use this command:

```auto
echo off > /sys/power/autosleep
```

BR  
Jay
