UART2, FCM, sending and receiving

I wrote a simple application to test the FCM. I wanted to send and receive a string to and from a terminal on my PC.

#include "adl_global.h"
#include "generated.h"

bool fcmCtrlHandler (adl_fcmEvent_e event);
bool fcmDataHandler (u16 dataLen, u8 * data);
void TimerHandler1Second (u8 ID, void * Context);
ascii* string = "string";
s8 fcmHandle;

void main_task (void)
{
	TRACE((1,"Hello world"));

	// at+wmfm

    fcmHandle = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART2, fcmCtrlHandler, fcmDataHandler);
    if (fcmHandle < 0) TRACE((1,"fail"));
    else adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_DATA);

    //ascii * string = "";
    // wm_itoa(fcmHandle, string);
    //TRACE((1,string));
    adl_tmrSubscribe ( TRUE, 10, ADL_TMR_TYPE_100MS, TimerHandler1Second );
}

void TimerHandler1Second (u8 ID, void * Context)
{
	s8 ret = adl_fcmSendData(fcmHandle, (u8 *)"wtf nigga", 4);
	switch(ret)
	{
		case OK: break;
		case ADL_FCM_RET_OK_WAIT_RESUME: 	TRACE((1,"1")); break;
		case ADL_RET_ERR_PARAM:				TRACE((1,"2")); break;
		case ADL_RET_ERR_UNKNOWN_HDL:		TRACE((1,"3")); break;
		case ADL_RET_ERR_BAD_STATE: 		TRACE((1,"4")); break;
		case ADL_FCM_RET_ERR_WAIT_RESUME:	TRACE((1,"5")); break;
		///case ADL_FCM_RET_XXX_WAIT_RESUME: 	TRACE((1,"6")); break;
	}
}

bool fcmCtrlHandler (adl_fcmEvent_e event)
{
	switch(event)
	{
		case ADL_FCM_EVENT_FLOW_OPENNED: 	TRACE((1,"Openned")); 		break;
		case ADL_FCM_EVENT_FLOW_CLOSED: 	TRACE((1,"Closed")); 		break;
		case ADL_FCM_EVENT_RESUME:			TRACE((1,"Resume")); 		break;
		case ADL_FCM_EVENT_V24_DATA_MODE: 	TRACE((1,"DataMode")); 	 	break;
		case ADL_FCM_EVENT_MEM_RELEASE: 	TRACE((1,"MemRelease")); 	break;
		case ADL_FCM_EVENT_V24_AT_MODE:		TRACE((1,"atmode")); 		break;
	}

	return true;
}

bool fcmDataHandler (u16 dataLen, u8 * data)
{
	TRACE((1, "DataHandler"));
	TRACE((1,(ascii *) data));
	return true;
}

Every second it tries to send something through the UART, while the Datahandler waits for incomming data.
When I open a terminal and connect it with the UART (Im using the Q26 development kit, UART2 is enabled, also used AT+WMFM=0,1,2) I can neither receive or send data.

After a while I get the ADL_FCM_RET_ERR_WAIT_RESUME error. I can spend many hours breaking my head over this :imp: but I hope one of you can point out what I’m doing wrong.

Sounds like a Flow Control issue?

Note: that’s “flow control” in the normal, RS232 sense - nothing to do with “flow control” in the Open-AT FCM sense.
Trust Wavecom to come up with such a confusing name! :unamused:

I also get the “ADL_FCM_RET_ERR_WAIT_RESUME” even when my terminal is not connected. But I’ll try to figure out if it has to do with flow control.

I doubt that it has to do with flow control

This is wrong:

fcmHandle = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART2, fcmCtrlHandler, fcmDataHandler);

if (fcmHandle < 0) TRACE((1,"fail"));
else adl_fcmSwitchV24State(fcmHandle, ADL_FCM_V24_STATE_DATA);

You need to wait for the ADL_FCM_EVENT_FLOW_OPENNED event.

Have you looked at any of the SDK examples?
Or this example: https://forum.sierrawireless.com/t/simple-uart-echo-program/4739/1 :question:

I have looked at examples yes, but Ill have another look at that one.

I understand that the way I programmed it is not correct.
However since my traces are in the following order, I figured that it was working fine nevertheless.
Hello world -> Openned -> DataMode

Meanwhile I have also added an echo to the program wich seems to work, its weird that the string that I send in the timer does not appear on my terminal.

Thank you for your help btw :mrgreen:

You were entirely correct awneil, I fixed the code and now its working perfectly. :slight_smile: