# Reading data from uart2

**URL:** <https://forum.sierrawireless.com/t/reading-data-from-uart2/3843>\
**Category:** Legacy AirPrime modules\
**Created:** [November 10, 2009, 5:52am UTC](https://forum.sierrawireless.com/t/reading-data-from-uart2/3843 "2009-11-10T05:52:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akhil](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@akhil](https://forum.sierrawireless.com/u/akhil)\
**Post date:** [November 10, 2009, 5:52am UTC](https://forum.sierrawireless.com/t/reading-data-from-uart2/3843/1 "2009-11-10T05:52:40Z")

</div>

hi,  
This is my code for reading data from UART2, while downloading the application on q2687, m2m is taking very long time.Later iam getting xmodem error.But while downloading from hyperterminal it is easily downloadable, Please comment whether the application is sufficient to read data from uart.

```auto
#include "adl_global.h"
#include "adl_fcm.h"

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

bool tec_CtrlHandler(u8 event);
bool tec_DataHandler(u16 datlength,u8* data);
bool ipr_rsphdl (adl_atResponse_t *Params);
s8 uart_handler;
ascii result;

/ *************************************************************************** /
/* Uart Callbacks */
/ *************************************************************************** /

bool tec_CtrlHandler(u8 event){
	switch(event){
	case ADL_FCM_EVENT_FLOW_OPENNED:
		adl_atCmdCreate("AT+IPR=9600;&w", ADL_AT_PORT_TYPE ( ADL_PORT_UART2, ADL_AT_RSP ),(adl_atRspHandler_t)ipr_rsphdl,NULL);
		TRACE((1,"UART2 HAS BEEN OPENNED"));
		adl_fcmSwitchV24State(uart_handler,ADL_FCM_V24_STATE_DATA);//to receive data
		break;
	case ADL_FCM_EVENT_FLOW_CLOSED:
		TRACE((1,"UART2 HAS BEEN CLOSED"));
		break;
	case ADL_FCM_EVENT_V24_DATA_MODE:
		TRACE((1,"ALREADY IN DATA MODE"));
		break;
	default:
		TRACE((2,"UNKNOWN EVENT OCCURED"));
		break;
	}
}

// this is to read data.

bool tec_DataHandler(u16 datlength,u8* data){
	TRACE((6,"IN TO DATA MODE,IF DATA IS ,COMING WILL READ NOW"));

	ascii NewText [20],txt[20];
		u16 i;
		result=*data;
	    for ( i = 0 ; i < datlength ; i++ )
	    {
	        if ( data [i] == '~' )
	        {
				adl_fcmUnsubscribe(uart_handler);
	        }
		else
			{
			txt[i]=data[i];
			wm_sprintf ( NewText, "%c", txt[i] );

		//	adl_atSendResponse(ADL_AT_UNS, NewText);//to send received data and display using uart1.
			//adl_fcmSendData ( FCM_Handler, NewText, datlength );
			}
		}
	return TRUE;
	}

bool ipr_rsphdl(adl_atResponse_t *Params)
{
	TRACE((5,"IN IPR RESPONSE HANDLER"));
         return;
}

// main function

adl_main(adl_InitType_e InitType)
{
	if(adl_fcmIsAvailable( ADL_FCM_FLOW_V24_UART2)==TRUE)
	{
		TRACE((1,"IN MAIN FUNCTION\n"));
		uart_handler=adl_fcmSubscribe ( ADL_FCM_FLOW_V24_UART2, (adl_fcmCtrlHdlr_f) tec_CtrlHandler, (adl_fcmDataHdlr_f) tec_DataHandler );
	}
	else
	{
		TRACE((2,"UART2 IS NOT AVAILABLE"));
    }
}
```

---

<div class="post-metadata">

**Author:** ![akhil](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@akhil](https://forum.sierrawireless.com/u/akhil)\
**Post date:** [November 10, 2009, 12:28pm UTC](https://forum.sierrawireless.com/t/reading-data-from-uart2/3843/2 "2009-11-10T12:28:04Z")

</div>

i am initializing uart2 using ,

at+wmfm=0,1,2

and i am changing baud rate of UART2 using

```
adl_atCmdCreate(), api to 9600.

```

Please comment as am unable to see the traces and my application does not starts even.

---

<div class="post-metadata">

**Author:** ![akhil](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@akhil](https://forum.sierrawireless.com/u/akhil)\
**Post date:** [November 12, 2009, 10:42am UTC](https://forum.sierrawireless.com/t/reading-data-from-uart2/3843/3 "2009-11-12T10:42:53Z")

</div>

😃 ,i READ it. Yes I read IT.The Problem was my firmware, once i upgraded it,data is just flowing in with ease.

Thanks to all those who read my post and even to those who wished they could help but couldn’t. 8)

---

<div class="post-metadata">

**Author:** ![Kapustin](https://avatars.discourse-cdn.com/v4/letter/k/ac8455/32.png) [@Kapustin](https://forum.sierrawireless.com/u/Kapustin)\
**Post date:** [January 20, 2010, 8:35am UTC](https://forum.sierrawireless.com/t/reading-data-from-uart2/3843/4 "2010-01-20T08:35:20Z")

</div>

> [@akhil](#):
>
> 😃 ,i READ it. Yes I read IT.The Problem was my firmware, once i upgraded it,data is just flowing in with ease.
> 
> Thanks to all those who read my post and even to those who wished they could help but couldn’t. 8)

Can you explane me why you commented this in your code?  
//adl\_atSendResponse(ADL\_AT\_UNS, NewText);//to send received data and display using uart1.  
//adl\_fcmSendData ( UARTHandle, NewText, DataLen );

And does result = \*data means that you put receiving data in result? If it does why you use “for”?

I’m a Newbie
