UART2 doesn't send data! WHY?


#1

Hi everybody!

I’m triyng to use UART2 to send raw data to a device connected to Q2501b.

I used the following commands:

Turn GPS off and disconnect it from UART2:
AT+WGPSCONF=0,0
AT+WGPSM=0,0

Opens serial port UART2
AT+WMFM=0,1,2"

Configures baud rate
AT+IPR=115200

Associates functions to handle data received from UART2
U2_Handler = adl_fcmSubscribe ( ADL_FCM_FLOW_V24_UART2,SerialControl,SerialData);

Chages into V24 state
adl_fcmSwitchV24State(U2_Handler,ADL_FCM_V24_STATE_DATA);

After that, I started a timer to continuosly (each second) sends data using code below:

char *dados = “testing UART2”.
adl_fcmSendData(U2_Handler, dados, sizeof(dados) );

I’m already triying to make it work for a few hours and nothing happens, that is, I can’t see any data on pins GPS_TXD2 or GPS_TXD_0 of starter kit.

What is wrong with code above?

Does anyone have a little example code to enable UART2, configure it, and send some data? Where can I see this data on the q2501 evaluation board?

Thanks.

Alex Teixeira Benfica.
dcc.ufmg.br/~benfica


#2

Hi,

I have the same problem ! I made a program which send ascii data on UART 2 every second. I previously configure UART 2 with AT+WMFM, AT+IPR, AT+ICF, AT+IFC with adl_atCmdCreate() function :

adl_atCmdCreate(“AT+WMFM=0,1,2”,FALSE, CMEECmdResp, “*”, NULL);

adl_atCmdCreate(“AT+IPR=115200”, ADL_AT_PORT_TYPE(ADL_AT_UART2, FALSE), CMEECmdResp, “*”, NULL);

I also use adl_fcmSubscribe() and adl_fcmSwitchV24State() functions :

adl_fcmSubscribe(ADL_PORT_UART2, MyCtrlHandler, MyUARTDataHandler);

adl_fcmSwitchV24State(FcmHandle_UART2, ADL_FCM_V24_STATE_DATA);

adl_fcmSendData(FcmHandle_UART2,Data_UART2,Data_UART2_len);

But, instead of sending data, OS crashed with the following error :

Trace LAPD 1 ARM Data Abort at 00096C38, Current Task 0x16
Trace RTK 1 ================== RTK STATUS start ==================
Trace RTK 1 ================== RTK STATUS end ==================

What is wrong with code above ? Does anyone have any idea of this error code ? How finding the corresponding task which cause this error (in debug mode, no task 0x16 appear !) ?

Thanks in advance.


#3

While working with the Q24PL with a GPS receiver we built this test code that loops data from one UART to the other UART. Maybe this would help:

#include "adl_global.h"

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStack                                                      */
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

/* Handle used to control UART2 */
s8 uart1FcmHandle = -1;
s8 uart2FcmHandle = -1;

bool uart1AtMode = TRUE;
bool uart2AtMode = TRUE;

#define SEND_TRACE(x)   TRACE(( 1, x )); adl_atSendResponse ( ADL_AT_UNS, x );


void PrintFcmState(int i)
{
/*
    ADL_FCM_EVENT_FLOW_OPENNED,
    ADL_FCM_EVENT_FLOW_CLOSED,
    ADL_FCM_EVENT_V24_DATA_MODE,
    ADL_FCM_EVENT_V24_DATA_MODE_EXT,
    ADL_FCM_EVENT_V24_AT_MODE,
    ADL_FCM_EVENT_V24_AT_MODE_EXT,
    ADL_FCM_EVENT_RESUME,
    ADL_FCM_EVENT_MEM_RELEASE,
    ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL,
    ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL
*/
}

bool Uart1ControlHandler(adl_fcmEvent_e event)
{
   char string[100];
   s8 returnValue;

   wm_sprintf(string, "(Uart1ControlHandler) Event: %d\r\n", event);
   SEND_TRACE(string);
    
   switch(event) 
   {
      case ADL_FCM_EVENT_FLOW_OPENNED:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
         
         returnValue = adl_fcmSwitchV24State(uart1FcmHandle, ADL_FCM_V24_STATE_DATA);
         if (returnValue != OK)
         {
            wm_sprintf(string, "(Uart1ControlHandler) ERROR: adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) failed. returnValue = %d\r\n", returnValue);
            SEND_TRACE(string);
         }
         else
         {
            SEND_TRACE("(Uart1ControlHandler) adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) Success\r\n");
         }
      break;
      
      case ADL_FCM_EVENT_FLOW_CLOSED:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
      break;
      case ADL_FCM_EVENT_V24_DATA_MODE:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE\r\n");
      break;
      case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_EXT\r\n");
      break;
      case ADL_FCM_EVENT_V24_AT_MODE:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE\r\n");
      break;
      case ADL_FCM_EVENT_V24_AT_MODE_EXT:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_EXT\r\n");
      break;
      case ADL_FCM_EVENT_RESUME:
         SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_RESUME\r\n");
      break;
      case ADL_FCM_EVENT_MEM_RELEASE:
          SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_MEM_RELEASE\r\n");
      break;
      case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
          SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL\r\n");
      break;
      case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
          SEND_TRACE("(Uart1ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL\r\n");
      break;
      
      default:
          SEND_TRACE("(Uart1ControlHandler) Error: Unknown Event\r\n");
      break;
    }
    
    return TRUE;
}

bool Uart1DataHandler(u16 dataLen, u8 *data)
{
   s8 returnValue;
   char string[100];
   wm_sprintf(string, "(Uart1DataHandler)Bytes Received: %d\r\n", dataLen);
   SEND_TRACE(string);

   returnValue = adl_fcmSendData(uart2FcmHandle, data, dataLen);
   if (returnValue < 0)
   {
      wm_sprintf(string, "(Uart1DataHandler) adl_fcmSendData() failed. returnValue=%d\r\n", returnValue);
      SEND_TRACE(string);      
   }

   return TRUE;
}

bool Uart2ControlHandler(adl_fcmEvent_e event)
{
   char string[100];
   s8 returnValue;

   wm_sprintf(string, "(Uart2ControlHandler) Event: %d\r\n", event);
   SEND_TRACE(string);
    
   switch(event) 
   {
      case ADL_FCM_EVENT_FLOW_OPENNED:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
         
         returnValue = adl_fcmSwitchV24State(uart2FcmHandle, ADL_FCM_V24_STATE_DATA);
         if (returnValue != OK)
         {
            wm_sprintf(string, "(Uart2ControlHandler) ERROR: adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) failed. returnValue = %d\r\n", returnValue);
            SEND_TRACE(string);
         }
         else
         {
            SEND_TRACE("(Uart2ControlHandler) adl_fcmSwitchV24State(ADL_FCM_V24_STATE_DATA) Success\r\n");
         }
      break;
      
      case ADL_FCM_EVENT_FLOW_CLOSED:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_FLOW_OPENNED\r\n");
      break;
      case ADL_FCM_EVENT_V24_DATA_MODE:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE\r\n");
      break;
      case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_EXT\r\n");
      break;
      case ADL_FCM_EVENT_V24_AT_MODE:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE\r\n");
      break;
      case ADL_FCM_EVENT_V24_AT_MODE_EXT:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_EXT\r\n");
      break;
      case ADL_FCM_EVENT_RESUME:
         SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_RESUME\r\n");
      break;
      case ADL_FCM_EVENT_MEM_RELEASE:
          SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_MEM_RELEASE\r\n");
      break;
      case ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL:
          SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_DATA_MODE_FROM_CALL\r\n");
      break;
      case ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL:
          SEND_TRACE("(Uart2ControlHandler) Handle: ADL_FCM_EVENT_V24_AT_MODE_FROM_CALL\r\n");
      break;
      
      default:
          SEND_TRACE("(Uart2ControlHandler) Error: Unknown Event\r\n");
      break;
    }
    
    return TRUE;
}

bool Uart2DataHandler(u16 dataLen, u8 *data)
{
   s8 returnValue;
   char string[100];
   wm_sprintf(string, "(Uart2DataHandler)Bytes Received: %d\r\n", dataLen);
   SEND_TRACE(string);
   
   returnValue = adl_fcmSendData(uart1FcmHandle, data, dataLen);
   if (returnValue < 0)
   {
      wm_sprintf(string, "(Uart2DataHandler) adl_fcmSendData() failed. returnValue=%d\r\n", returnValue);
      SEND_TRACE(string);      
   }
   
   return TRUE;
}

bool HandleWmfmSetBaudRate(adl_atResponse_t *response)
{
   bool isFcmAvailable;
   
   SEND_TRACE("AT+IPR=115200: %s");
   SEND_TRACE(response->StrData);

   isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART1);
   if (isFcmAvailable)
   {
      SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE\r\n");
   }
   else
   {
      SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART1) == FALSE\r\n");
   }
   
   isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART2);
   if (isFcmAvailable)
   {
      SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE\r\n");
   }
   else
   {
      SEND_TRACE("Before: adl_fcmIsAvailable(ADL_PORT_UART2) == FALSE\r\n");
   }

   uart1FcmHandle = adl_fcmSubscribe(ADL_PORT_UART1, Uart1ControlHandler, Uart1DataHandler);
   if (uart1FcmHandle < 0)
   {
      char string[100];
      wm_sprintf(string, "ERROR: adl_fcmSubscribe(ADL_PORT_UART1)failed. returnValue = %d\r\n", uart1FcmHandle);
      SEND_TRACE(string);
   }
   else
   {
      char string[100];
      wm_sprintf(string, "adl_fcmSubscribe(ADL_PORT_UART1)Success! uart2FcmHandle = %d\r\n", uart1FcmHandle);
      SEND_TRACE(string);
   }

   uart2FcmHandle = adl_fcmSubscribe(ADL_PORT_UART2, Uart2ControlHandler, Uart2DataHandler);
   if (uart2FcmHandle < 0)
   {
      char string[100];
      wm_sprintf(string, "ERROR: adl_fcmSubscribe(ADL_PORT_UART2)failed. returnValue = %d\r\n", uart2FcmHandle);
      SEND_TRACE(string);
   }
   else
   {
      char string[100];
      wm_sprintf(string, "adl_fcmSubscribe(ADL_PORT_UART2)Success! uart2FcmHandle = %d\r\n", uart2FcmHandle);
      SEND_TRACE(string);
   }

   isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART1);
   if (isFcmAvailable)
   {
      SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART1) == TRUE\r\n");
   }
   else
   {
      SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART1) == FALSE\r\n");
   }
   
   isFcmAvailable = adl_fcmIsAvailable(ADL_PORT_UART2);
   if (isFcmAvailable)
   {
      SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART2) == TRUE\r\n");
   }
   else
   {
      SEND_TRACE("After: adl_fcmIsAvailable(ADL_PORT_UART2) == FALSE\r\n");
   }
   
   return(FALSE);
}

void WorkAroundTitmerHandler( u8 whatever)
{
   s8 returnValue;

   /* Set the baud rate for UART 2 */
   SEND_TRACE("AT+IPR=115200: Start\r\n");
   returnValue = adl_atCmdCreate("AT+IPR=115200",
      ADL_AT_PORT_TYPE (ADL_PORT_UART2, FALSE),
      HandleWmfmSetBaudRate, "*", NULL);
   if (returnValue != OK)
   {
      char string[100];
      wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+IPR=115200) returned %d\r\n", returnValue);
      SEND_TRACE(string);
   }
}

#define COMMAND_BUG  1

bool HandleWmfmUart2Enable(adl_atResponse_t *response)
{

   SEND_TRACE("AT+WMFM=0,1,2:");
   SEND_TRACE(response->StrData);

#if COMMAND_BUG
   // For some reason, we never receive the callback after cascading the third
   // AT Command. Wavecom is working on a solution...
   adl_tmrSubscribe(FALSE, 1, ADL_TMR_TYPE_100MS, WorkAroundTitmerHandler);
#else
    WorkAroundTitmerHandler(0);
#endif

   return(FALSE);
}

bool HandleWmfmUart2Disable(adl_atResponse_t *response)
{
   s8 returnValue;
   
   SEND_TRACE("AT+WMFM=0,0,2:");
   SEND_TRACE(response->StrData);
   
   /* For <Physical Port>, <Activate>, <UART 2> */
   SEND_TRACE("AT+WMFM=0,1,2: Start\r\n" );
   returnValue = adl_atCmdCreate("AT+WMFM=0,1,2", FALSE,
      HandleWmfmUart2Enable, "*", NULL);
   if (returnValue != OK)
   {
      char string[100];
      wm_sprintf(string, "ERROR: adl_atCmdCreate(AT+WMFM=0,1,2) returned %d\r\n", returnValue);
      SEND_TRACE(string);
   }
   
   return(FALSE);
}

void AtUart2LoopbackCmdHandler(adl_atCmdPreParser_t *parser)
{
   s8 returnValue;
   char *parameter;
   int startStop;
   
   SEND_TRACE("(AtUart2LoopbackCmdHandler) Enter.\r\n");

   parameter = wm_lstGetItem(parser->ParaList, 0);
   startStop = atoi(parameter);
   if (startStop == 1)
   {
      if ((uart1FcmHandle != -1) || (uart2FcmHandle != -1))
      {
         SEND_TRACE("Application Active: UART1 or UART2 still has active handle.\r\n");
      }
      
      /* Disable UART 2 just in case it wasn't disable in the previous run. */
      SEND_TRACE("AT+WMFM=0,0,2: Start\r\n");
      adl_atCmdCreate("AT+WMFM=0,0,2", FALSE, HandleWmfmUart2Disable, "*", NULL);
   }
   else
   if (startStop == 0)
   {
      char string[100];
      
      if (uart1FcmHandle != -1)
      {
         returnValue = adl_fcmUnsubscribe(uart1FcmHandle);
         if (returnValue < 0)
         {
            wm_sprintf(string, "(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart1FcmHandle) failed. returnValue=%d\r\n", returnValue);
            SEND_TRACE(string);      
         }
         else
         {
            uart1FcmHandle = -1;
         }
      }
      else
      {
         SEND_TRACE("UART1 already Unsubscribed.\r\n");
      }
      
      if (uart1FcmHandle != -1)
      {
         returnValue = adl_fcmUnsubscribe(uart2FcmHandle);
         if (returnValue < 0)
         {
            wm_sprintf(string, "(AtUart2LoopbackCmdHandler) adl_fcmUnsubscribe(uart2FcmHandle) failed. returnValue=%d\r\n", returnValue);
            SEND_TRACE(string);      
         }
         else
         {
            uart2FcmHandle = -1;
         }
      }
      else
      {
         SEND_TRACE("UART2 already Unsubscribed.\r\n");
      }
   }
   else
   {
      adl_atSendResponse ( ADL_AT_RSP, "\r\nERROR\r\n" );
      return;
   }

   adl_atSendResponse ( ADL_AT_RSP, "\r\nOK\r\n" );   
}

void adl_main ( adl_InitType_e  InitType )
{
   SEND_TRACE("Embedded : Appli Init\r\n");

   adl_atCmdSubscribe("AT+UART2", AtUart2LoopbackCmdHandler, ADL_CMD_TYPE_PARA | 0x11);
}

[/code]


#4

Thanks to your program, i found my error ! When i was using adl_fcmSubscribe function on UART, i was switching immediately after in DATA mode with adl_fcmSwitch24State function.

Now, i have integrated the adl_fcmSwitchV24State function in UART Control Handler as you do in your program above and it works fine.

Thank you for your help !

Best regards.