Using FCM and UART2 to send data to external Device


#1

Dear Forum,

I using the Q2686 with open AT OS 4.20 with VIsual c++ 6 to develop an application where the module collects data via a zigbee module connected to UART2. I am having some troubles in sending data through the UART2. I have written the code below

I run the init code (below) at startup and send a “HELLO” data string on a 2 second timer interrupt. On probing the Rx and Tx Lines with an oscilloscope I do not see any output on the traces.

--------------------------------------------------FCM Handers for UART2-----------------------------------------

bool uart2_ctrl_handler(adl_fcmEvent_e Event)
{
TRACE((1,“HANDLER: uart2_ctrl_handler”);
switch (Event)
{
case ADL_FCM_EVENT_FLOW_OPENNED:
TRACE((1,“EVENT: FLOW2 OPENNED”));
adl_fcmSwitchV24State(uart2_handle,ADL_FCM_V24_STATE_DATA);
break;
case ADL_FCM_EVENT_V24_DATA_MODE: // Entered data mode - socket has been opened
TRACE((1,“EVENT: uart2_ctrl_handler got ADL_FCM_EVENT_V24_DATA_MODE”));
break;
case ADL_FCM_EVENT_V24_AT_MODE: // Local end quits data mode, socket closes
TRACE((1,“EVENT: uart2_ctrl_handler got ADL_FCM_EVENT_V24_AT_MODE”));
break;
case ADL_FCM_EVENT_V24_AT_MODE_EXT: // Remote end quits data mode, socket closes
TRACE((1,“EVENT: uart2_ctrl_handler got ADL_FCM_EVENT_V24_AT_MODE_EXT”));
}
return TRUE;
}

// UART data handler - called when we receive a data block from
// the uart
bool uart2_data_handler(u16 len, u8* ptr)
{
TRACE((1,“HANDLER: in uart2_data_handler”));
return TRUE;
}
-------------------------------------------------To init UART2-----------------------------------------------------------

void init_uart2(){
s8 res;
//open uart2
res = adl_atCmdCreate( “AT+WMFM=0,1,2”, FALSE, (adl_atRspHandler_t)NULL, NULL );
if(res ==OK)
TRACE((1,“INIT:uart2 opened”));
else
TRACE((1,“INIT:uart2 failed to open”));
//set to 2400 baud
res = adl_atCmdCreate( “AT+IPR=2400”, ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t)NULL, NULL );
if(res ==OK)
TRACE((1,“INIT:uart2 2400 baud”));
else
TRACE((1,“INIT:uart2 cannot change baud”));
//subscribe to port
TRACE((1,“INIT: subscribing to uart2”));
uart2_handle=adl_fcmSubscribe(ADL_PORT_UART2,uart2_ctrl_handler,uart2_data_handler);
}

-------------------------------------------------To send Data on Uart2-------------------------------------------------------

void send_uart2(char *OutString, int Len){
s8 res;
adl_fcmDataBlock_t Uart2_Data;
adl_fcmSwitchV24State(uart2_handle,ADL_FCM_V24_STATE_DATA);
TRACE((1,“DATA: sending data on uart2”));
/
Build block to send */
Uart2_Data = adl_memGet ( ( u16 ) ( sizeof ( adl_fcmDataBlock_t ) + Len ) );
Uart2_Data->DataLength = Len;
wm_memcpy ( Uart2_Data->Data, OutString,Len);
res = adl_fcmSendDataExt(uart2_handle,Uart2_Data);
if(res ==OK)
TRACE((1,“DATA: uart2 data sent”));
}

I would be very grateful if you could you please have a look to see where I am going wrong.

Many Thanks

Kronk


#2

what are the outputs of all your traces?

perhaps these can help you:

  • I think hardware flow control (DCE/DTE) is normally on. have you set these signals on the right levels? you can switch this off with at+ifc=0,0
  • move the adl_fcmSwitchV24State call into uart2_ctrl_handler after ‘case ADL_FCM_EVENT_FLOW_OPENNED’ and ‘case ADL_FCM_EVENT_V24_AT_MODE’ (but you can’t close fcm while it is in data mode!)