UART2 can't send data


#1

hi all,
firts i use uart2 as GPIO to generate the desired wave,then use uart2 to send data.The first step is ok now.But uart2 is always not send any data.
the code is below.And the taget monitoring tool results are as follows:
Trace IP 1 Embedded Application : Main
Trace IP 1 K Line
Trace IP 1 value w_fcm : 0
Trace IP 1 cmd_RspHandler_IPR
Trace IP 1 HandleWmfmUart2Disable
Trace IP 1 iowrite return value is 5
Trace IP 1 iowrite return value is 5
Trace IP 1 HandleWmfmUart2Enable
Trace IP 1 Event Handler : 0
Trace IP 1 V24 Flow Opened
Trace IP 1 Event Handler : 2
Trace IP 1 Switched to data mode
Trace IP 1 SenddataReturn value is 0 //the return value is ok!!
Trace IP 1 Send data
Trace IP 1 Event Handler : 7
Trace IP 1 V24 Flow Closed

If anyone can give me a hand ,i will really appreciate it.

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );
u32 i=0;
char* string[100];
s8 GPIO1_Handle; 
s8 writereturn;
s8 SenddataReturn;
s8 w_fcm;
s8 StartCommun[5]={0x81,0x10,0xf1,0x81,0x03};
adl_ioProductTypes_e productype;
s32 GetTime(void);
void OATSleep (u16 msec);

bool FCM_V24_data_Handler(u16 datalength, u8 *data);
bool FCM_V24_ctrl_Handler(u8 event);
bool cmd_RspHandler_IPR(adl_atResponse_t * params); 
bool HandleWmfmUart2Enable(adl_atResponse_t *response);
bool HandleWmfmUart2Disable(adl_atResponse_t *response);
void SendData(void);
//const wm_ioConfig_t myconfig[]={WM_IO_Q24PLUS_GPO_1,0,0,1};

/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/


/***************************************************************************/
/*  Local functions                                                        */
/***************************************************************************/



/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : Customer application initialisation                       */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  InitType          |   |   |   |  Application start mode reason         */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
	
	  s8 bUARTok = -1;
	TRACE (( 1, "Embedded Application : Main" ));
	TRACE (( 1, "K Line" ));
	productype =adl_ioGetProductType();

	 bUARTok = adl_atCmdCreate("AT+WMFM=0,0,2", FALSE, HandleWmfmUart2Disable, "*", NULL);    //disable uart2

                bUARTok = adl_atCmdCreate("AT+WMFM=0,1,2", FALSE, HandleWmfmUart2Enable, "*", NULL);// enable uart2
               adl_atCmdCreate("AT+IPR=10400", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t) cmd_RspHandler_IPR, "*", NULL); 
               adl_atCmdCreate("AT+ICF=3,4", ADL_AT_PORT_TYPE(ADL_AT_UART2, FALSE), (adl_atRspHandler_t) cmd_RspHandler_IPR, "*", NULL );
               if(!bUARTok)
                {
     
                 TRACE (( 1, "value w_fcm : %d ", w_fcm ));   
                 if(w_fcm < 0)
                 {
                  TRACE (( 1, "UART2 can't opened" ));//ErroR
                 }
               }

}



s32 GetTime(void)
{ 
adl_rtcTime_t time; 
s32 milliseconds; 
adl_rtcGetTime(&time); 

milliseconds = (s32)1000*time.SecondFracPart/32768; 
milliseconds += (s32)1000*time.Second; 
milliseconds += (s32)(60*1000)*time.Minute; 
milliseconds += (s32)(60*60*1000)*time.Hour; 
milliseconds += (s32)(24*60*60*1000)*time.Day; 

return milliseconds; 
} 

void OATSleep (u16 msec) 
{ 
s32 initial_time; 
u16 diff = 0; 

initial_time = GetTime(); 

while (diff<msec) 
{ 
diff = GetTime() - initial_time; 
} 
} 
bool FCM_V24_data_Handler(u16 datalength, u8 *data)
{

	s8 returnValue;
   char string1[100];
   wm_sprintf(string1, "(Uart1DataHandler)Bytes Received: %d\r\n", datalength);
   TRACE((1,string1));
   //adl_fcmSendData(w_fcm, string1, datalength);
   //adl_atSendResponse(ADL_AT_RSP,string1);

   returnValue = adl_fcmSendData(w_fcm, data, datalength);
   if (returnValue < 0)
   {
      wm_sprintf(string1, "(Uart1DataHandler) adl_fcmSendData() failed. returnValue=%d\r\n", returnValue);
      TRACE((1,string1));
	  adl_atSendResponse(ADL_AT_RSP,string1);
   }
	
	
	return TRUE;
}
bool FCM_V24_ctrl_Handler(u8 event)
{
    TRACE (( 1, "Event Handler : %d", event ));
	switch (event)
	{

	case ADL_FCM_EVENT_FLOW_OPENNED:
		{
			TRACE (( 1, "V24 Flow Opened" ));
			
			adl_fcmSwitchV24State(w_fcm, ADL_FCM_V24_STATE_DATA);
			
		}	
		break;
	case ADL_FCM_EVENT_V24_DATA_MODE :
		{
			TRACE (( 1, "Switched to data mode" ));
			 //wm_sprintf(string, "%d", 1);
            //adl_fcmSendData(w_fcm, (u8 *)StartCommun, 5);
			adl_tmrSubscribe(FALSE,1,ADL_TMR_TYPE_100MS,SendData);
			

		}
		break;

	case ADL_FCM_EVENT_V24_AT_MODE :
		TRACE (( 1, "Switched to at mode" ));

		// Unsubscribe V24 flow
		adl_fcmUnsubscribe(w_fcm);
		break;

	case ADL_FCM_EVENT_FLOW_CLOSED:
		
		// adl_memRelease(RECEIVE_DATA);
        adl_fcmUnsubscribe(w_fcm);
		TRACE (( 1, "V24 Flow Closed" ));
		break;
	case 7:
		adl_fcmUnsubscribe(w_fcm);
		TRACE (( 1, "V24 Flow Closed" ));
		break;
	}
	return TRUE;
}

bool cmd_RspHandler_IPR(adl_atResponse_t * params) 
{ 
TRACE (( 1, "cmd_RspHandler_IPR" )); 
return FALSE; 
} 


bool HandleWmfmUart2Enable(adl_atResponse_t *response)
{
TRACE (( 1, "HandleWmfmUart2Enable" )); 
 w_fcm = adl_fcmSubscribe(ADL_PORT_UART2,FCM_V24_ctrl_Handler,FCM_V24_data_Handler);   
   return(FALSE);
}

bool HandleWmfmUart2Disable(adl_atResponse_t *response)
{
    TRACE (( 1, "HandleWmfmUart2Disable" )); 
    GPIO1_Handle = adl_ioSubscribe ( ADL_IO_Q24PLUS_GPO_2, 0,0xFFFFFFFF,0,NULL); // GpioHandler ,output,value=1
	TRACE((1,"iowrite return value is %d",GPIO1_Handle));
	OATSleep(300);
    adl_ioUnsubscribe(GPIO1_Handle);
	OATSleep(20);
	GPIO1_Handle = adl_ioSubscribe ( ADL_IO_Q24PLUS_GPO_2, 0,0xFFFFFFFF,0,NULL); // GpioHandler ,output,value=1
	TRACE((1,"iowrite return value is %d",GPIO1_Handle));
	OATSleep(18);
    adl_ioUnsubscribe(GPIO1_Handle);

   return(FALSE);
}
void SendData(void)
{
	SenddataReturn=adl_fcmSendData(w_fcm, (s8*)"23", 2);
	TRACE((1,"SenddataReturn value is %d",SenddataReturn));
	TRACE (( 1, "Send data" ));
}

#2

How have you verified that?

ie, how do you know that it’s the UART that’s not sending the data - as opposed to the attached device not receiving or not recognising it?

Have you checked what FCM Event Number 7 is?


#3

Hi,
I oberserve the wave from the oscilloscope.
FCM Event Number 7 is ADL_FCM_EVENT_MEN_RELEASE,which is caused by adl_fcmSendData().If FCM Event Number 7 happened,the data should have be sent from uart2.But the wave did not change .That is the weird point. :angry:
regards
zhuzhiwei


#4

Check the post “Thu Jul 02, 2009 10:12 am” on: http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?f=5&t=3423&start=30
If you are working with a Q26 that could be your problem.


#5

hi,
finally i found out the problem,that is the uart2 can’t support the baudrate 10400.When i change the baudrate from 10400 to the default 9600 or 115200,the uart2 can send data and work well.

adl_atCmdCreate("AT+IPR=10400", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t) cmd_RspHandler_IPR, "*", NULL);

i wonder how can the uart2 support the baudrate beyond the default setting?


#6

The supported rates are listed in the AT Commands Guide - and 10400 isn’t one of them.

In fact, 10400 isn’t a “standard” rate for any “standard” RS232 port that I’ve ever seen - so what made you think it did support that rate?