# Unable to use UART2

**URL:** <https://forum.sierrawireless.com/t/unable-to-use-uart2/3113>\
**Category:** Legacy AirPrime modules\
**Created:** [April 8, 2009, 12:13pm UTC](https://forum.sierrawireless.com/t/unable-to-use-uart2/3113 "2009-04-08T12:13:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cabail](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@cabail](https://forum.sierrawireless.com/u/cabail)\
**Post date:** [April 8, 2009, 12:13pm UTC](https://forum.sierrawireless.com/t/unable-to-use-uart2/3113/1 "2009-04-08T12:13:24Z")

</div>

Hi,

I’m beginner with Q2686 and i need to use the second UART on my software.

I have already read the forum and check my code with “ADL User Guide for Open AT® OS v6.20” doc but I’m unable to access to the UART(read or write data).  
I use M2MStudio to developp/compile my code and have a Q2686 dev kit to run software.

This is my code:

```auto
#include "adl_global.h"
#include "adl_OpenDevice.h"
#include "wm_uart.h"

/ *************************************************************************** /
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/ *************************************************************************** /
const u16 wm_apmCustomStackSize = 1024*3;

/ *************************************************************************** /
/* Function : adl_main */
/ *************************************************************************** /
void adl_main ( adl_InitType_e InitType )
{
    u32 handle;
    sUartSettings_t Settings;

    sUartLc_t uartLc;
    psGItfCont_t pinterface;

    /* Device */
    Settings.identity = "UART2";
    Settings.role = UART_ROLE_DCE;
    Settings.event_handlers = NULL;

    /* To retrieve the UART SP Interface */
    Settings.interface = &pinterface;

    /* Line Coding */
    uartLc.valid_fields = UART_LC_ALL;
    uartLc.rate = UART_RATE_9600;
    uartLc.stop = UART_STOP_BIT_1;
    uartLc.parity = UART_PARITY_NONE;
    uartLc.data = UART_DATALENGTH_8;

    Settings.line_coding = &uartLc;

    adl_atSendResponse( ADL_AT_UNS, "UART Struct define\n");
    /*------------------*/
    /* open UART device */
    /*------------------*/
    if( 0 <= (handle = adl_OpenDevice( DF_UART_CLID, &Settings)) )
    {
 	  adl_atSendResponse( ADL_AT_UNS, "successfully opened\n");
       TRACE(( 1, "UART successfully opened" ));

       pinterface->write( handle, "Tx Some bytes", 13 );

       adl_atSendResponse( ADL_AT_UNS, "Close UART\n");
       pinterface->close( handle );
    }
    else
   	  adl_atSendResponse( ADL_AT_UNS, "opening error\n");

    adl_atSendResponse( ADL_AT_UNS, "end software\n");
}
```

Need help to understand why that doesn’t work …  
The board/software always reset at “pinterface-\>write()” function.

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [April 8, 2009, 12:28pm UTC](https://forum.sierrawireless.com/t/unable-to-use-uart2/3113/2 "2009-04-08T12:28:04Z")

</div>

Does this help: [viewtopic.php?f=15&t=3314&p=12580&hilit=wmfm#p12580](http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?f=15&t=3314&p=12580&hilit=wmfm#p12580)❓

---

<div class="post-metadata">

**Author:** ![cabail](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@cabail](https://forum.sierrawireless.com/u/cabail)\
**Post date:** [April 8, 2009, 1:23pm UTC](https://forum.sierrawireless.com/t/unable-to-use-uart2/3113/3 "2009-04-08T13:23:56Z")

</div>

No …  
Before running software, UART2 is close.

It’s confirm by the at command +WWFM :

AT+WMFM?  
+WMFM: 0,2,1,1  
+WMFM: 0,2,2,0  
+WMFM: 0,2,3,0  
+WMFM: 1,2,4,0  
+WMFM: 1,2,4,1

And I don’t have problem to open the UART2 with this command :  
AT+WMFM=0,1,2  
OK  
AT+WMFM?  
+WMFM: 0,2,1,1  
+WMFM: 0,2,2,1  
+WMFM: 0,2,3,0  
+WMFM: 1,2,4,0  
+WMFM: 1,2,4,1  
OK

The command +WWFM always indicated the UART2 as close.

---

<div class="post-metadata">

**Author:** ![ecoprocess](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@ecoprocess](https://forum.sierrawireless.com/u/ecoprocess)\
**Post date:** [April 8, 2009, 2:38pm UTC](https://forum.sierrawireless.com/t/unable-to-use-uart2/3113/4 "2009-04-08T14:38:24Z")

</div>

Hello,  
I have experience the same pb, until I had “Settings.capabilities = NULL;” in the sample code.  
I deduct capabilities must be initialised.

---

<div class="post-metadata">

**Author:** ![cabail](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@cabail](https://forum.sierrawireless.com/u/cabail)\
**Post date:** [April 9, 2009, 9:09am UTC](https://forum.sierrawireless.com/t/unable-to-use-uart2/3113/5 "2009-04-09T09:09:47Z")

</div>

Thank’s for your answer but that doesn’t solve my problem.

But when I change the role setting:

```auto
/* Device */
    Settings.identity = "UART2";
    Settings.role = UART_ROLE_DCE;
    Settings.event_handlers = NULL;
    Settings.capabilities = NULL;
```

to

```auto
/* Device */
    Settings.identity = "UART2";
    Settings.role = UART_ROLE_NM;
    Settings.event_handlers = NULL;
    Settings.capabilities = NULL;
```

UART send data. 😃

➡ Find next complet right code to send a text on UART2 :

```auto
#include "adl_global.h"
#include "adl_OpenDevice.h"
#include "wm_uart.h"

/ *************************************************************************** /
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/ *************************************************************************** /
const u16 wm_apmCustomStackSize = 1024*3;

/ *************************************************************************** /
/* Function : adl_main */
/ *************************************************************************** /
void adl_main ( adl_InitType_e InitType )
{
    u32 handle;
    sUartSettings_t Settings;

    sUartLc_t uartLc;
    psGItfCont_t pinterface;

    /* Device */
    Settings.identity = "UART2";
    Settings.role = UART_ROLE_NM;
    Settings.event_handlers = NULL;
    Settings.capabilities = NULL;

    /* To retrieve the UART SP Interface */
    Settings.interface = &pinterface;

    /* Line Coding */
    uartLc.valid_fields = UART_LC_ALL;
    uartLc.rate = UART_RATE_9600;
    uartLc.stop = UART_STOP_BIT_1;
    uartLc.parity = UART_PARITY_NONE;
    uartLc.data = UART_DATALENGTH_8;

    Settings.line_coding = &uartLc;

    adl_atSendResponse( ADL_AT_UNS, "UART Struct define\n");
    /*------------------*/
    /* open UART device */
    /*------------------*/
    if( 0 <= (handle = adl_OpenDevice( DF_UART_CLID, &Settings)) )
    {
 	  adl_atSendResponse( ADL_AT_UNS, "successfully opened\n");
       TRACE(( 1, "UART successfully opened" ));

       pinterface->write( handle, "Tx Some bytes", 13 );

       adl_atSendResponse( ADL_AT_UNS, "Close UART\n");
       //pinterface->close( handle );
    }
    else
   	  adl_atSendResponse( ADL_AT_UNS, "opening error\n");

    adl_atSendResponse( ADL_AT_UNS, "end software\n");
}
```
