Disabling AT Mode on UART1

Hello,

I am trying to use UART1 for a serial connection with a card reader with a baud rate of 9600. But I couldn’t make it work properly since it is using that port for AT commands.

This is where I set the fcm:

void UART1_Enable(void)
{
    if (!adl_fcmIsAvailable(ADL_PORT_UART1))
    {
    	TRACE((13, "UART1 FCM NOT Available"));
    //ATRSP("Setting UART1\r\n");
    //adl_atCmdCreate("AT+WMFM=0,1,2", FALSE, (adl_atRspHandler_t) Res_WMFM1_Handler, "*", NULL);
    }
    else
    {
    	TRACE((13, "UART1 FCM Available"));
        adl_atCmdCreate("AT+IPR=9600", ADL_AT_PORT_TYPE( ADL_AT_UART1, FALSE ), (adl_atRspHandler_t) Res_IPR_Handler, "*", NULL);
        adl_atCmdCreate("AT&W", ADL_AT_PORT_TYPE( ADL_AT_UART1, FALSE ),(adl_atRspHandler_t) Res_IPR_Handler, "*", NULL);
        fcm1_handle = adl_fcmSubscribe(ADL_PORT_UART1, (adl_fcmCtrlHdlr_f) fcmCtrlU1, (adl_fcmDataHdlr_f) fcmDataU1);
        TRACE((13, "FCM1 HANDLE RESULT: %d",fcm1_handle));
    }
    return;
}

(I compiled the code on Release mode, so that the TRACE’s wouldn’t be sent, but I’m still seeing some responses on the TRACE section of Developer Studio on ADL Level 25)

And this is the controller function for that FCM

bool fcmCtrlU1(u8 event)
{
    switch (event)
    {
    case ADL_FCM_EVENT_FLOW_OPENNED:
    	adl_fcmSwitchV24State(fcm1_handle, ADL_FCM_V24_STATE_DATA);
    	TRACE((13, "ADL_FCM_EVENT_FLOW_OPENNED"));
    	break;
    case ADL_FCM_EVENT_FLOW_CLOSED:
    	TRACE((13, "ADL_FCM_EVENT_FLOW_CLOSED"));
    	break;
    case ADL_FCM_EVENT_V24_DATA_MODE:
    	Uart1CurrentState = DATA_MODE;
    	TRACE((13, "ADL_FCM_EVENT_V24_DATA_MODE"));
    	break;
    case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
    	TRACE((13, "ADL_FCM_EVENT_V24_DATA_MODE_EXT"));
    	break;
    case ADL_FCM_EVENT_V24_AT_MODE:
    	Uart1CurrentState = AT_MODE;
    	//adl_fcmReleaseCredits(fcm1_handle, 0xFF);
    	TRACE((13, "ADL_FCM_EVENT_V24_AT_MODE"));
    	break;
    case ADL_FCM_EVENT_V24_AT_MODE_EXT:
    	//adl_fcmReleaseCredits(fcm1_handle, 0xFF);
    	TRACE((13, "ADL_FCM_EVENT_V24_AT_MODE_EXT"));
    	break;
    case ADL_FCM_EVENT_RESUME:
    	TRACE((13, "ADL_FCM_EVENT_RESUME"));
    	break;
    case ADL_FCM_EVENT_MEM_RELEASE:
    	TRACE((13, "ADL_FCM_EVENT_MEM_RELEASE"));
    	break;
    case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
    	TRACE((13, "ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL"));
    	break;
    case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
    	TRACE((13, "ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL"));
    	break;
    }
    return TRUE;
}

I also added a timer to check if it is in the data mode every x miliseconds:

if (!Uart1ATState && (Uart1CurrentState != Uart1ATState))
    	adl_fcmSwitchV24State(fcm1_handle, ADL_FCM_V24_STATE_DATA);
    else if (Uart1CurrentState != Uart1ATState)
    	adl_fcmSwitchV24State(fcm1_handle, ADL_FCM_V24_STATE_AT);

Uart1ATState = FALSE
Uart1CurrentState = TRUE
These variables are initialized as above,
So it will at least set the DATA mode for once.

I also set the ATRSP commands to be sent only if the device is in the AT mode:

s32 ATRSP(ascii *buffer)
{
	s32 retVal = 0;
	if (Uart1ATState)
	{
		retVal = adl_atSendResponse(ADL_AT_RSP, buffer);
	}
	return retVal;
}

The data handler for this FCM works without any problem if I use UART2:

void UART2_Enable(void)
{
    if (!adl_fcmIsAvailable(ADL_PORT_UART1))
    {
    	TRACE((13, "UART2 FCM NOT Available"));
    //ATRSP("Setting UART1\r\n");
    //adl_atCmdCreate("AT+WMFM=0,1,2", FALSE, (adl_atRspHandler_t) Res_WMFM1_Handler, "*", NULL);
    }
    else
    {
    	TRACE((13, "UART2 FCM Available"));
        adl_atCmdCreate("AT+IPR=9600", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t) Res_IPR_Handler, "*", NULL);
        adl_atCmdCreate("AT&W", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ),(adl_atRspHandler_t) Res_IPR_Handler, "*", NULL);
        fcm1_handle = adl_fcmSubscribe(ADL_PORT_UART2, (adl_fcmCtrlHdlr_f) fcmCtrlU1, (adl_fcmDataHdlr_f) fcmDataU1);
        TRACE((13, "FCM1 HANDLE RESULT: %d",fcm1_handle));
    }
    return;
}

As you can see everything is the same as the one at the beginning except the UART1 part. So I’m thinking there are other parameters on Open AT that is getting in the way of the communcation between the card reader and our openAT device (which has a Q2687 in it)

I heard that when a response is sent from the OpenAT, it automatically returns to AT MODE. But does it inform the FCM Control Handler? How do i know if the device is in AT mode or DATA mode, except from the handler?

I also found out this by monitoring the uart1 serial port from my PC:

.+WIND: 10,"SM",0,"FD",0,"ON",0,"SN",0,"EN",0
.
.+WIND: 11,,,,,"1B803B4009CB2BEC24D241F3F129E1B1",

.+WIND: 15,3,"+08",4,"10/11/05,12:35:00+08",6,"0"

.+CREG: 1,"507D","3DEE"
.
.+CGREG: 1,"507D","3DEE"

.+CREG: 1,"507D","048B"
.
.+CGREG: 1,"507D","048B"

.+CREG: 1,"507D","3DEE"
.
.+CGREG: 1,"507D","3DEE"

Is it possible to disable these responses on DATA mode?

I’m going to get crazy :slight_smile:

This is a standard communication procedure between the card reader and computer/client:

client: 0x23
reader: 0x45
client: hex command
reader: 0x67
client: 0x89
reader: answer to command

I connected to the reader and tried to send the client commands manually, and I was successful.
(I also monitored the communication between me and the reader)

I connected to the openAT device from UART1 and responded to client commands with the same responses I got from the reader above. I was also successful.

I set openAT device to communicate with the card reader from UART2. And it was also successful.

But when I set the openAT device to communicate via UART1, I get no response.

I also monitored UART1 device from the boot, I know that the UART1 channel sends only the data I want it to send except the one below at the beginning (so there is not much interference):

You should check flow rate setting (IFC) and set AT+IFC=0,0. Don’t forget to save settings to flash (AT&W) :wink: