UART - problem


#1

Hi ,

I have problem with UART. When I try to send string from q2406B to PC(Hyperterminal) via RS 232 port, then I found the problem. I can’t receive anything. I’m sending my code below:

#include “adl_global.h”
#include “adl_fcm.h”
#include “adl_at.h”

u32 wm_apmCustomStack[256];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);

bool MyCtrlHandler(u8 Event){
switch(Event){
case ADL_FCM_EVENT_FLOW_OPENNED:
{
// Related to adl_fcmSubscribe
adl_atSendResponse(ADL_AT_UNS, “\r\nADL_FCM_EVENT_FLOW_OPENED\r\n”);
TRACE ((1, “ADL_FCM_EVENT_FLOW_OPENED”));

    }
    break;
    
    case ADL_FCM_EVENT_FLOW_CLOSED:
    {
		// Related to adl_fcmUnsubscribe
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_FLOW_CLOSED\r\n");
		TRACE ((1, "ADL_FCM_EVENT_FLOW_CLOSED")); 
        
    }
    break;

	case ADL_FCM_EVENT_V24_DATA_MODE:
    {
		// Related to adl_fcmSwitchV24State
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_V24_DATA_MODE\r\n");
		TRACE ((1, "ADL_FCM_EVENT_V24_DATA_MODE")); 
        
    }
    break;

	case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
    {
		// 
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_V24_DATA_MODE_EXT\r\n");
		TRACE ((1, "ADL_FCM_EVENT_V24_DATA_MODE_EXT")); 
        
    }
    break;

	case ADL_FCM_EVENT_V24_AT_MODE:
    {
		// Related to adl_fcmSwitchV24State
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_V24_AT_MODE\r\n");
        TRACE ((1, "ADL_FCM_EVENT_V24_AT_MODE")); 

    }
    break;

	case ADL_FCM_EVENT_V24_AT_MODE_EXT:
    {
		// 
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_V24_AT_MODE_EXT\r\n");
		TRACE ((1, "ADL_FCM_EVENT_V24_AT_MODE_EXT")); 
        
    }
    break;

	case ADL_FCM_EVENT_RESUME:
    {
		// Related to adl_SendDate and adl_fcmSendDataExt
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_RESUME\r\n");
		TRACE ((1, "ADL_FCM_EVENT_RESUME")); 
        
    }
    break;

	case ADL_FCM_EVENT_MEM_RELEASE:
    {
		// Related to adl_SendDate and adl_fcmSendDataExt
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_FCM_EVENT_MEM_RELEASE\r\n");
		TRACE ((1, "ADL_FCM_EVENT_MEM_RELEASE")); 
        
    }
    break;
 }
 return TRUE; 

}

bool MyDataHandler(u8 Event){
switch(Event){
case ADL_FCM_EVENT_FLOW_OPENNED:
{
// Event when flow is redy to process
adl_atSendResponse(ADL_AT_UNS, “\r\nEvent when flow is redy to process\r\n”);
TRACE ((1, “Event when flow is redy to process” ));

    }
    break;
    
    case ADL_RET_ERR_PARAM:
    {
		// One parameter has an incorrect value
		adl_atSendResponse(ADL_AT_UNS, "\r\nOne parameter has an incorrect value\r\n");
		TRACE ((1, "One parameter has an incorrect value" )); 
        
    }
    break;

	case ADL_RET_ERR_ALREADY_SUBSCRIBED:
    {
		// The flow is not available
		adl_atSendResponse(ADL_AT_UNS, "\r\nThe flow is not available\r\n");
		TRACE ((1, "The flow is not available" )); 
        
    }
    break;

	case ADL_RET_ERR_NOT_SUBSCRIBED:
    {
		// V24 subscription is made when V24 Master flow is not subscribed
		adl_atSendResponse(ADL_AT_UNS, "\r\nV24 subscription is made when V24 Master flow is not subscribed\r\n");
		TRACE ((1, "V24 subscription is made when V24 Master flow is not subscribed" )); 
        
    }
    break;

	case ADL_FCM_RET_ERROR_GSM_GPRS_ALREADY_OPENNED:
    {
		// GSM or GPRS subscription is made when the other one is already
		adl_atSendResponse(ADL_AT_UNS, "\r\nGSM or GPRS subscription is made when the other one is already\r\n");
		TRACE ((1, "GSM or GPRS subscription is made when the other one is already" )); 
        
    }
    break;

	case ADL_RET_ERR_BAD_STATE:
    {
		// The required Uart flow was not previously opened with the AT+WMFM command
		adl_atSendResponse(ADL_AT_UNS, "\r\nThe required Uart flow was not previously opened with the AT+WMFM command\r\n");
		TRACE ((1, "The required Uart flow was not previously opened with the AT+WMFM command" )); 
        
    }
    break;
 }	
return TRUE; 

}

void Cmd_Handler(adl_atCmdPreParser_t *paras){
switch(paras->Type){
case ADL_CMD_TYPE_TEST:
{
adl_atSendResponse(ADL_AT_UNS, “\r\nADL_CMD_TYPE_TEST\r\n”);
}
break;

    case ADL_CMD_TYPE_READ:
    {
        adl_atSendResponse(ADL_AT_UNS, "\r\nADL_CMD_TYPE_READ\r\n");
    }
    break;

    case ADL_CMD_TYPE_PARA: 
	{
		adl_atSendResponse(ADL_AT_UNS, "\r\nADL_CMD_TYPE_PARA\r\n");
	}
}

}

void adl_main (adl_InitType_e InitType){

// u8 * PacketToSend;
s8 sFcmReturn;
s8 FCM_Handler;
//static const ascii * PacketToSend = “PING”;
u8 * PacketToSend = “PING”;
u16 size;

FCM_Handler = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART1, MyCtrlHandler, MyDataHandler);
adl_atSendResponse(ADL_AT_UNS, "\r\nUART - Flow Control Management\r\n");  

// Switch to data mode
adl_fcmSwitchV24State(FCM_Handler, ADL_FCM_V24_STATE_DATA); 

TRACE ((1, "UART - Flow Control Management")); 
TRACE ((1, __DATE__));
TRACE ((1, __TIME__)); 

size = sizeof(PacketToSend) + 1;

/* Send packet */
sFcmReturn = adl_fcmSendDataExt(FCM_Handler, PacketToSend, size);
if (sFcmReturn < OK){
    TRACE((1, "Problem to send the packet"));    
    adl_atSendResponse(ADL_AT_UNS, "\r\nCannot send the packet\r\n");            
}
else{
    /* OK */
    TRACE((1, "Packet Sent"));
    adl_atSendResponse(ADL_AT_UNS, "OK");
}


adl_fcmUnsubscribe(FCM_Handler);

}

Can you help me to solve my problem? Thank you in advanced!

Best Regards,
belikg


#2

Hi belikg, here’s an example code, note that you can only call adl_fcmSwitchV24State() funtion after ADL_FCM_EVENT_FLOW_OPENNED event:

#include “adl_global.h”

#include “adl_fcm.h”

/***************************************************************************
Mandatory variables

wm_apmCustomStack
wm_apmCustomStackSize

****************************************************************************/

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

/***************************************************************************
Global variables

FCM_Handle				: Handle returned by the adl_fcmSubscribe
command					: Command typied by the use
com						: Pointer for "command"
cont					: Data Length of the command typied by the user

****************************************************************************/

u8 FCM_Handle;

char command[20] = “Digite o comando:\n\r”;
char *com;

int cont;

/***************************************************************************
Function : FcmCtrlHandler

Description: Display the FCM Events

Variable Name     |IN |OUT|GLB|  Utilisation

----------------------±–±--±–±----------------------------------------
Event | | | | FCM Events
----------------------±–±--±–±----------------------------------------
****************************************************************************/

bool FcmCtrlHandler (adl_fcmEvent_e Event){

switch (Event){
case ADL_FCM_EVENT_FLOW_OPENNED:

	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_FLOW_OPENNED\n\r");

	adl_fcmSwitchV24State(FCM_Handle,ADL_FCM_V24_STATE_DATA);

break;

case ADL_FCM_EVENT_FLOW_CLOSED:
	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_FLOW_CLOSED\n\r");
break;

case ADL_FCM_EVENT_V24_DATA_MODE:

	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_V24_DATA_MODE\n\r");

	com = command; // "com" reveice "command" address
	adl_fcmSendData (FCM_Handle,command,20);
	cont=0;

break;

case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_V24_DATA_MODE_EXT\n\r");
break;

case ADL_FCM_EVENT_V24_AT_MODE:
	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_V24_AT_MODE\n\r");

	adl_fcmSendData (FCM_Handle, "Nunes",5);
break;

case ADL_FCM_EVENT_RESUME:
	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_RESUME\n\r");
break;

case ADL_FCM_EVENT_MEM_RELEASE:
	adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_MEM_RELEASE\n\r");
break;

}

return TRUE;

}

/***************************************************************************
Function : FcmDataHandler

Description: Handle with the income data

Variable Name     |IN |OUT|GLB|  Utilisation

----------------------±–±--±–±----------------------------------------
DataLen | | | | Length of “Data”
----------------------±–±--±–±----------------------------------------
Data | | | | Data receveid
----------------------±–±--±–±----------------------------------------
****************************************************************************/

bool FcmDataHandler (u16 DataLen, u8 * Data){

char msg[20]; 
char *msn;

sprintf(msg,"%c",*Data); //Change "Data" from u8 to string

msn = msg;

adl_fcmSendData (FCM_Handle, msg,DataLen);


if (*Data=='\r'){  //Enter pressed

	adl_fcmSendData (FCM_Handle, "\n",1);

	adl_fcmSendData (FCM_Handle,command,cont);

	adl_fcmSendData (FCM_Handle, "\n\r",2);

	com = command;
	cont = 0;

}else{

	*com++ = *msn; //Add the character at the "command" using the pointer "com"
	cont += 1;

}


return TRUE;

}

/***************************************************************************
Function : SimCard

Description: Display the SimCard Events

Variable Name     |IN |OUT|GLB|  Utilisation

----------------------±–±--±–±----------------------------------------
Event | | | | Sim Card Events
----------------------±–±--±–±----------------------------------------
****************************************************************************/

void SimCard (u8 Event){

switch(Event){

//Normal Events
case ADL_SIM_EVENT_PIN_OK:
		adl_atSendResponse ( ADL_AT_UNS, "PIN Code Ok\n\rConectando...");
break;
case ADL_SIM_EVENT_REMOVED:
		adl_atSendResponse ( ADL_AT_UNS, "SimCard Removido\n\r");
break;
case ADL_SIM_EVENT_INSERTED:
		adl_atSendResponse ( ADL_AT_UNS, "SimCard Inserido\n\r");
break;
case ADL_SIM_EVENT_FULL_INIT:

		adl_atSendResponse ( ADL_AT_UNS, "Ok\n\r");

		FCM_Handle = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART1,FcmCtrlHandler,FcmDataHandler);
break;

//Error Events
case ADL_SIM_EVENT_PIN_ERROR:
		adl_atSendResponse ( ADL_AT_UNS, "PIN Code Incorreto\n\r");
break;

/*Erro quando se e necessario inserir o PIN Code.
  Por comandos AT, insera o PIN Code usando
  AT+CPIN="xxxx", onde xxxx e o codigo de 4 digitos*/
case ADL_SIM_EVENT_PIN_WAIT:
		adl_atSendResponse ( ADL_AT_UNS, "Entre com o PIN Code\n\r");
break;

}

}

/***************************************************************************
Function : adl_main

Description: Main function

Variable Name     |IN |OUT|GLB|  Utilisation

----------------------±–±--±–±----------------------------------------
InitType | | | | Application start mode reason
----------------------±–±--±–±----------------------------------------
****************************************************************************/

void adl_main ( adl_InitType_e InitType )
{

TRACE (( 1, "Embedded Application : Main" ));

adl_simSubscribe(SimCard,NULL);	//Executa a funcao SimCard a cada evento que ocorrer

}

Best Regards,
Sergio


#3

Hi Sergio,

Sorry for the delayed answer. Thank you for quickly answer. You solved my problem.

Best regards,
belikg


#4

Hi Sergio/Belikg,

I had written simple application to establish data call and then do transfer. I get all the events properly, the adl_fcmSendData returns OK as well. But the data entered on terminal emulator is not transferred on GSM and data on GSM is not transferred to V24.

I tried your example code, but I do not receive the data on the UART back. But I do receive ADL_FCM_EVENT_MEM_RELEASE for every entry of data on emulator.

I use VC6 and Wavecom terminal emulator.

Any idea about the issue?

Thanks,

-KGN


#5

Hello,
Sorry but I can’t compiling this code, is necessary any plug-in or anything special?

Thankyou

Anna.


#6

Why not?

What is preventing you?

https://forum.sierrawireless.com/t/fcm/5237/9

The example project that I mentioned to you previously has detailed instructions to build it:
https://forum.sierrawireless.com/t/simple-uart-echo-program/4739/1


#7

It works on remote mode using TMT+TE, and doesn’t works on terget mode.