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?