UART2 communication in DATA MODE


#1

Hi all,
I am new in the wonderfull embedded module developement of SiWi.
Well, I am presently using a Q26 wireless module which is integrated in a design. I want to display some informations gathered from the UART2, and display it on UART1, here is my code, I found it in this forum and please have a look on it :

/*
    | DESCRIPTION:
    |   UART2 Data reading
    |
    |
    |   Refer to: AT_Command_Interface_Guide.pdf
    |   Refer to: ADL_User_Guide_v6_31.pdf
    |
    |   Program state diagram:
    |   ----------------------
    |   (Config uart)-->(set data mode)-->(echo uart1 char) --ESC recived-->(switch to AT MODE)
    |
    */


    /*----------------------------- includes ---------------------------------*/
    #include "adl_global.h" /* Application development layer */
	#include "generated.h"

    /*-------------------------------- defines -------------------------------*/
    #define UART_1 ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_RSP) /* refer to ADL User Guide pag 67, rspflag */
	#define UART_2 ADL_AT_PORT_TYPE(ADL_PORT_UART2,ADL_AT_RSP) /* refer to ADL User Guide pag 67, rspflag */
	/* --- UART Config enums --- */
    /* Data format */
    enum UART_FORMAT{

       NO_USE,
       DATA8_STOP2,
       DATA8_STOP1_PARITY1,
       DATA8_STOP1,
       DATA7_STOP2,
       DATA7_STOP1_PARITY1,
       DATA7_STOP1

    };

    /* parity bit config */
    enum UART_PARITY{

       ODD,
       EVEN,
       MARK,
       SPACE,
       NONE_PARITY

    };

    /* flow control */
    enum UART_FLOW_CONTROL{

       CTS_RTS,
       NO_CTS_RTS

    };

    /* UART mode type */
    enum UART_TYPE{

       DATAMODE,
       ATMODE

    };
    /*----------------------------- data types ---------------------------*/


        /*------------------------------ variables ---------------------------*/

        /*  can anybody help me with stack size???? */
        const u16 wm_apmCustomStackSize = 1024*3;    /* application stack size (trial&error to determine size)*/

        s8 handle_uart1, handle_uart2;                     /* UART1 handler */
        u8 mode_uart1, mode_uart2;                        /* UART1 mode type */


        /*---------------------------- Function prototypes --------------------------*/
        /*---------------------------------------------------------------------------
        | Portability: WMP 100/150
        |----------------------------------------------------------------------------
        | Routine description:
        |  * Configures UART1 as specified by parameters
        |    If all ok returns 0 else -1
        |---------------------------------------------------------------------------
        | Parameters description:
        |   u8 mode: AT COMMANDS or DATA mode
        |   int speed: port baud rate
        |   u8 format: data format
        |   u8 parity: parity bit
        |   u8 flow_control: flow control
        |   *see defines
        /---------------------------------------------------------------------------*/
        int initUART2(u8 mode, int speed, u8 format, u8 parity, u8 flow_control);

        /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Handler of control events in UART, sets UART mode
            |    If all ok returns TRUE else FALSE
            |---------------------------------------------------------------------------
            | Parameters description:
            |   adl_fcmEvent_e evnt: FCM event that raised handler.
            /---------------------------------------------------------------------------*/
            static bool EvhCrtlUart1(adl_fcmEvent_e evnt);
            static bool EvhCrtlUart2(adl_fcmEvent_e evnt);

            /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Handler when data recived, echo data until ESC recived, then switch to ATMODE
            |---------------------------------------------------------------------------
            | Parameters description:
            |   u16 datalength: number of bytes recived
            |   u8 *data: pointer to data recived
            /---------------------------------------------------------------------------*/
            static bool EvhDataUart1(u16 datalength, u8 *data);
            static bool EvhDataUart2(u16 datalength, u8 *data);


            /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Handler of port configuration using AT, al responses are ignored
            |---------------------------------------------------------------------------
            | Parameters description:
            |   adl_atResponse_t *Rsp: response from AT command
            /---------------------------------------------------------------------------*/
            static void EvhConfUartx(adl_atResponse_t *Rsp);
            /*-------------------------------- Functions --------------------------------*/

               int initUART2(u8 mode, int speed, u8 format, u8 parity, u8 flow_control){

                  char comand[15];
                  /* Check if port available*/
                  if(adl_fcmIsAvailable(ADL_FCM_FLOW_V24_UART2))
                  {
                     /* Save UART operation mode: DATA o AT*/
                     mode_uart2=mode;

                     /* subscribe to FCM uart service */
                     handle_uart2=adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART2, EvhCrtlUart2,EvhDataUart2);

                     /* config parity with AT Command*/
                     wm_sprintf(comand,"AT+ICF=%d,%d", format, parity);
                     adl_atCmdCreate(comand, UART_2,EvhConfUartx,NULL);

                     /* speed  with AT Command*/
                     wm_sprintf(comand,"AT+IPR=%d", speed);
                     adl_atCmdCreate(comand, UART_2,EvhConfUartx,NULL);

                     /* flow control  with AT Command*/
                     switch(flow_control){
                     /* hardware flow control */
                     case CTS_RTS:
                        adl_atCmdCreate("AT+IFC=2,2",UART_2,EvhConfUartx,NULL);
                        break;
                        /* no hardware flow control */
                     case NO_CTS_RTS:
                        adl_atCmdCreate("AT+IFC=0,0",UART_2,EvhConfUartx,NULL);
                        break;
                     }
                     /* save configuration */
                     adl_atCmdCreate("AT&W", UART_2, (adl_atRspHandler_t)EvhConfUartx,NULL);
                     return 0;
                  }
                  else {
                	  adl_atSendResponse(ADL_AT_RSP, "\r\nUART2 not available");
                  }
                  return -1;

               }/*initUART2*/


               static bool EvhCrtlUart1(adl_fcmEvent_e evnt){
                     switch (evnt)
                      {
                      /* when com is open, operation mode is defined */
                      case ADL_FCM_EVENT_FLOW_OPENNED:
                         /*  DATA MODE */
                         if(mode_uart1 == DATAMODE){
                            adl_atSendResponse(ADL_AT_RSP, "\r\nUART1: Data Mode");
                            adl_fcmSwitchV24State(handle_uart1,ADL_FCM_V24_STATE_DATA);
                         }
                         /* AT MODE */
                         else if(mode_uart1 == ATMODE){
                            adl_atSendResponse(ADL_AT_RSP, "\r\nUART1: AT Mode");
                            adl_fcmSwitchV24State(handle_uart1,ADL_FCM_V24_STATE_AT);
                         }
                         break;

                      case ADL_FCM_EVENT_V24_DATA_MODE:
                         /* DATA MODE OK */
                         break;

                      case ADL_FCM_EVENT_V24_AT_MODE:
                         /* AT MODE OK */
                         break;

                      case ADL_FCM_EVENT_RESUME:
                         break;

                      case ADL_FCM_EVENT_MEM_RELEASE:
                         break;

                      default:
                         return FALSE;
                         break;
                      }
                      return TRUE;
                  }/*EvhCrtlUart1*/

               static bool EvhCrtlUart2(adl_fcmEvent_e evnt){
                      switch (evnt)
                       {
                       /* when com is open, operation mode is defined */
                       case ADL_FCM_EVENT_FLOW_OPENNED:
                          /*  DATA MODE */
                          if(mode_uart2 == DATAMODE){
                             adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: Data Mode");
                             adl_fcmSwitchV24State(handle_uart2,ADL_FCM_V24_STATE_DATA);
                          }
                          /* AT MODE */
                          else if(mode_uart2 == ATMODE){
                             adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: AT Mode");
                             adl_fcmSwitchV24State(handle_uart2,ADL_FCM_V24_STATE_AT);
                          }
                          break;

                       case ADL_FCM_EVENT_V24_DATA_MODE:
                          /* DATA MODE OK */
                          break;

                       case ADL_FCM_EVENT_V24_AT_MODE:
                          /* AT MODE OK */
                          break;

                       case ADL_FCM_EVENT_RESUME:
                          break;

                       case ADL_FCM_EVENT_MEM_RELEASE:
                          break;

                       default:
                          return FALSE;
                          break;
                       }
                       return TRUE;
                   }/*EvhCrtlUart2*/
               static bool EvhDataUart2(u16 datalength, u8 *data){

                      /* when data recived echo it */
                      s8 error;

                      /* check for ESC to switch to AT MODE */
                      if(data[0] == 27)
                      {
                         adl_fcmSwitchV24State(handle_uart2,ADL_FCM_V24_STATE_AT);
                         adl_atSendResponse(ADL_AT_RSP,"DATA RECEIVED");
                      }
                      else
                      {
                         error = adl_fcmSendData(handle_uart2,data,datalength);
                         adl_atSendResponse(ADL_AT_RSP,"UNKNOWN ERROR");
                         switch(error){
                         case ADL_RET_ERR_PARAM:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: parameter incorrect value");
                            break;
                         case ADL_RET_ERR_UNKNOWN_HDL:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: unknown handle");
                            break;
                         case ADL_RET_ERR_BAD_STATE:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: not ready to send data");
                            break;
                         case ADL_FCM_RET_ERR_WAIT_RESUME:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: flow has no more credit");
                            break;
                         case ADL_RET_ERR_SERVICE_LOCKED:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: from a low level");
                            break;
                         }
                      }
                      return TRUE;

                   }/*EvhDataUart2*/
               static void EvhConfUartx(adl_atResponse_t *Rsp){

                   }/*EvhConfUartx*/




void main_task ( void )
{
	initUART2(DATAMODE, 57600 , DATA8_STOP1 , NONE_PARITY , NO_CTS_RTS);

}

Actually, the App shows me permanently :

UART2: Data Mode
+WIND: 1

+CREG: 2

+WIND: 7

+CREG: 1,"0007","1ECA"

+WIND: 4

+WIND: 3

+CREG: 0

+CGREG: 0

Again and again
I will apreciate your help!


#2

In other words, you application is crashing;
Then the unit restarts;
Then the application crashes;
etc.


#3

Thank you awneil,
I have changed a little bit the code so that the reding operation happens just after the part of the code executed well before. I mean it were executed until DATA MODE entering so I did this:

/*
    | DESCRIPTION:
    |   UART2 Data reading
    |
    |
    |   Refer to: AT_Command_Interface_Guide.pdf
    |   Refer to: ADL_User_Guide_v6_31.pdf
    |
    |   Program state diagram:
    |   ----------------------
    |   (Config uart)-->(set data mode)-->(echo uart1 char) --ESC recived-->(switch to AT MODE)
    |
    */


    /*----------------------------- includes ---------------------------------*/
    #include "adl_global.h" /* Application development layer */
	#include "generated.h"

    /*-------------------------------- defines -------------------------------*/
    #define UART_1 ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_RSP) /* refer to ADL User Guide pag 67, rspflag */
	#define UART_2 ADL_AT_PORT_TYPE(ADL_PORT_UART2,ADL_AT_RSP) /* refer to ADL User Guide pag 67, rspflag */
	/* --- UART Config enums --- */
    /* Data format */
    enum UART_FORMAT{

       NO_USE,
       DATA8_STOP2,
       DATA8_STOP1_PARITY1,
       DATA8_STOP1,
       DATA7_STOP2,
       DATA7_STOP1_PARITY1,
       DATA7_STOP1

    };

    /* parity bit config */
    enum UART_PARITY{

       ODD,
       EVEN,
       MARK,
       SPACE,
       NONE_PARITY

    };

    /* flow control */
    enum UART_FLOW_CONTROL{

       CTS_RTS,
       NO_CTS_RTS

    };

    /* UART mode type */
    enum UART_TYPE{

       DATAMODE,
       ATMODE

    };
    /*----------------------------- data types ---------------------------*/


        /*------------------------------ variables ---------------------------*/

        /*  can anybody help me with stack size???? */
        const u16 wm_apmCustomStackSize = 1024*3;    /* application stack size (trial&error to determine size)*/

        s8 handle_uart1, handle_uart2;                     /* UART1 handler */
        u8 mode_uart1, mode_uart2;                        /* UART1 mode type */
        ascii result;

        /*---------------------------- Function prototypes --------------------------*/
        /*---------------------------------------------------------------------------
        | Portability: WMP 100/150
        |----------------------------------------------------------------------------
        | Routine description:
        |  * Configures UART1 as specified by parameters
        |    If all ok returns 0 else -1
        |---------------------------------------------------------------------------
        | Parameters description:
        |   u8 mode: AT COMMANDS or DATA mode
        |   int speed: port baud rate
        |   u8 format: data format
        |   u8 parity: parity bit
        |   u8 flow_control: flow control
        |   *see defines
        /---------------------------------------------------------------------------*/
        int initUART2(u8 mode, int speed, u8 format, u8 parity, u8 flow_control);

        /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Handler of control events in UART, sets UART mode
            |    If all ok returns TRUE else FALSE
            |---------------------------------------------------------------------------
            | Parameters description:
            |   adl_fcmEvent_e evnt: FCM event that raised handler.
            /---------------------------------------------------------------------------*/
            static bool EvhCrtlUart1(adl_fcmEvent_e evnt);
            static bool EvhCrtlUart2(adl_fcmEvent_e evnt);

            /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Handler when data recived, echo data until ESC recived, then switch to ATMODE
            |---------------------------------------------------------------------------
            | Parameters description:
            |   u16 datalength: number of bytes recived
            |   u8 *data: pointer to data recived
            /---------------------------------------------------------------------------*/
            static bool EvhDataUart1(u16 datalength, u8 *data);
            static bool EvhDataUart2(u16 datalength, u8 *data);


            /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Handler of port configuration using AT, al responses are ignored
            |---------------------------------------------------------------------------
            | Parameters description:
            |   adl_atResponse_t *Rsp: response from AT command
            /---------------------------------------------------------------------------*/
            static void EvhConfUartx(adl_atResponse_t *Rsp);
            /*-------------------------------- Functions --------------------------------*/

               int initUART2(u8 mode, int speed, u8 format, u8 parity, u8 flow_control){

                  char comand[15];
                  /* Check if port available*/
                  if(adl_fcmIsAvailable(ADL_FCM_FLOW_V24_UART2))
                  {
                     /* Save UART operation mode: DATA o AT*/
                     mode_uart2=mode;

                     /* subscribe to FCM uart service */
                     handle_uart2=adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART2, EvhCrtlUart2,EvhDataUart2);

                     /* config parity with AT Command*/
                     wm_sprintf(comand,"AT+ICF=%d,%d", format, parity);
                     adl_atCmdCreate(comand, UART_2,EvhConfUartx,NULL);

                     /* speed  with AT Command*/
                     wm_sprintf(comand,"AT+IPR=%d", speed);
                     adl_atCmdCreate(comand, UART_2,EvhConfUartx,NULL);

                     /* flow control  with AT Command*/
                     switch(flow_control){
                     /* hardware flow control */
                     case CTS_RTS:
                        adl_atCmdCreate("AT+IFC=2,2",UART_2,EvhConfUartx,NULL);
                        break;
                        /* no hardware flow control */
                     case NO_CTS_RTS:
                        adl_atCmdCreate("AT+IFC=0,0",UART_2,EvhConfUartx,NULL);
                        break;
                     }
                     /* save configuration */
                     adl_atCmdCreate("AT&W", UART_2, (adl_atRspHandler_t)EvhConfUartx,NULL);
                     return 0;
                  }
                  else {
                	  adl_atSendResponse(ADL_AT_RSP, "\r\nUART2 not available");
                  }
                  return -1;

               }/*initUART2*/


               static bool EvhCrtlUart1(adl_fcmEvent_e evnt){
                     switch (evnt)
                      {
                      /* when com is open, operation mode is defined */
                      case ADL_FCM_EVENT_FLOW_OPENNED:
                         /*  DATA MODE */
                         if(mode_uart1 == DATAMODE){
                            adl_atSendResponse(ADL_AT_RSP, "\r\nUART1: Data Mode");
                            adl_fcmSwitchV24State(handle_uart1,ADL_FCM_V24_STATE_DATA);
                         }
                         /* AT MODE */
                         else if(mode_uart1 == ATMODE){
                            adl_atSendResponse(ADL_AT_RSP, "\r\nUART1: AT Mode");
                            adl_fcmSwitchV24State(handle_uart1,ADL_FCM_V24_STATE_AT);
                         }
                         break;

                      case ADL_FCM_EVENT_V24_DATA_MODE:
                         /* DATA MODE OK */
                         break;

                      case ADL_FCM_EVENT_V24_AT_MODE:
                         /* AT MODE OK */
                         break;

                      case ADL_FCM_EVENT_RESUME:
                         break;

                      case ADL_FCM_EVENT_MEM_RELEASE:
                         break;

                      default:
                         return FALSE;
                         break;
                      }
                      return TRUE;
                  }/*EvhCrtlUart1*/

               static bool EvhCrtlUart2(adl_fcmEvent_e evnt){
                      switch (evnt)
                       {
                       /* when com is open, operation mode is defined */
                       case ADL_FCM_EVENT_FLOW_OPENNED:
                          /*  DATA MODE */
                          if(mode_uart2 == DATAMODE){
                             adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: Data Mode");
                             adl_fcmSwitchV24State(handle_uart2,ADL_FCM_V24_STATE_DATA);
                          }
                          /* AT MODE */
                          else if(mode_uart2 == ATMODE){
                             adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: AT Mode");
                             adl_fcmSwitchV24State(handle_uart2,ADL_FCM_V24_STATE_AT);
                          }
                          break;

                       case ADL_FCM_EVENT_V24_DATA_MODE:
                          /* DATA MODE OK */
                          break;

                       case ADL_FCM_EVENT_V24_AT_MODE:
                          /* AT MODE OK */
                          break;

                       case ADL_FCM_EVENT_RESUME:
                          break;

                       case ADL_FCM_EVENT_MEM_RELEASE:
                          break;

                       default:
                          return FALSE;
                          break;
                       }
                       return TRUE;
                   }/*EvhCrtlUart2*/
               static bool EvhDataUart2(u16 datalength, u8 *data){

                      /* when data received echo it */
                      s8 error;

                      /* check for ESC to switch to AT MODE */
                      if(data[0] == 27)
                      {
                         adl_fcmSwitchV24State(handle_uart2,ADL_FCM_V24_STATE_AT);
                         ascii NewText [ 20 ],txt[20];
                                   u16 i;
                                   result=*data;
                                    for ( i = 0 ; i < datalength ; i++ )
                                    {
                                        if ( data [ i ] == '~' )
                                        {
                                         adl_fcmUnsubscribe(handle_uart2);
                                        }
                                   else
                                      {
                                      txt[i]=data[i];
                                      wm_sprintf ( NewText, "%c", txt[i] );

                                      adl_atSendResponse(ADL_AT_RSP, NewText);//to send received data and display using uart1.
                                      //adl_fcmSendData ( FCM_Handler, NewText, datlength );
                                      }
                                   }

                      }
                      else
                      {
                         error = adl_fcmSendData(handle_uart2,data,datalength);
                         adl_atSendResponse(ADL_AT_RSP,"UNKNOWN ERROR");
                         switch(error){
                         case ADL_RET_ERR_PARAM:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: parameter incorrect value");
                            break;
                         case ADL_RET_ERR_UNKNOWN_HDL:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: unknown handle");
                            break;
                         case ADL_RET_ERR_BAD_STATE:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: not ready to send data");
                            break;
                         case ADL_FCM_RET_ERR_WAIT_RESUME:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: flow has no more credit");
                            break;
                         case ADL_RET_ERR_SERVICE_LOCKED:
                            adl_atSendResponse(ADL_AT_RSP,"FCM send data: from a low level");
                            break;
                         }
                      }
                      return TRUE;

                   }/*EvhDataUart2*/
               static void EvhConfUartx(adl_atResponse_t *Rsp){

                   }/*EvhConfUartx*/




void main_task ( void )
{
	initUART2(DATAMODE, 57600 , DATA8_STOP1 , NONE_PARITY , NO_CTS_RTS);

}

and this is the answer:

UART2: Data Mode
+WIND: 1

+CREG: 2

+WIND: 4

+WIND: 7

+CREG: 1,"0009","20AC"

+WIND: 3

+CREG: 0

+CGREG: 0

Could you PLEASE help me a little bit more or explain me what’s happening?

I’m becoming really mad


#4

Ok,
I have read docs and know more about my messages. But it’s explained that the WIND indicates states of GSM registration. I will say ther is something I dont understand. My logic is this to read on UART2 and display the result on UART1:

  1. subscribe to FCM uart service
  2. switch UARTS2 to datat mode.
    Once I dod it Data event handler function should handle events.
    But in my code, I am switching in DATA MODE, the ADL_FCM_EVENT_FLOW_OPENNED happens, then the ADL_FCM_EVENT_V24_DATA_MODE too, But it jumps directly at ADL_FCM_EVENT_MEM_RELEASE I thought that at this stage, my data handler should handle incoming data, then nothing happens! Is there something that mismatch? please help me. here is my final code:
/*
        | DESCRIPTION:
        |   UART2 Data reading
        |
        |
        |   Refer to: AT_Command_Interface_Guide.pdf
        |   Refer to: ADL_User_Guide_v6_31.pdf
        |
        |   Program state diagram:
        |   ----------------------
        |   (Config uart)-->(set data mode)-->(echo uart1 char) --ESC recived-->(switch to AT MODE)
        |
        */


        /*----------------------------- includes ---------------------------------*/
        #include "adl_global.h" /* Application development layer */
       #include "generated.h"

        /*-------------------------------- defines -------------------------------*/
        #define UART_1 ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_RSP) /* refer to ADL User Guide pag 67, rspflag */
		#define UART_2 ADL_AT_PORT_TYPE(ADL_PORT_UART2,ADL_AT_RSP) /* refer to ADL User Guide pag 67, rspflag */
       /* --- UART Config enums --- */
        /* Data format */
        enum UART_FORMAT{

           NO_USE,
           DATA8_STOP2,
           DATA8_STOP1_PARITY1,
           DATA8_STOP1,
           DATA7_STOP2,
           DATA7_STOP1_PARITY1,
           DATA7_STOP1

        };

        /* parity bit config */
        enum UART_PARITY{

           ODD,
           EVEN,
           MARK,
           SPACE,
           NONE_PARITY

        };

        /* flow control */
        enum UART_FLOW_CONTROL{

           CTS_RTS,
           NO_CTS_RTS

        };

        /* UART mode type */
        enum UART_TYPE{

           DATAMODE,
           ATMODE

        };
        /*----------------------------- data types ---------------------------*/


            /*------------------------------ variables ---------------------------*/

            /*  can anybody help me with stack size???? */
            const u16 wm_apmCustomStackSize = 1024*3;    /* application stack size (trial&error to determine size)*/

            s8 handle_uart2;                     /* UART1 handler */
            u8 mode_uart2;                        /* UART1 mode type */
            ascii result;


            /*---------------------------- Function prototypes --------------------------*/
            /*---------------------------------------------------------------------------
            | Portability: WMP 100/150
            |----------------------------------------------------------------------------
            | Routine description:
            |  * Configures UART1 as specified by parameters
            |    If all ok returns 0 else -1
            |---------------------------------------------------------------------------
            | Parameters description:
            |   u8 mode: AT COMMANDS or DATA mode
            |   int speed: port baud rate
            |   u8 format: data format
            |   u8 parity: parity bit
            |   u8 flow_control: flow control
            |   *see defines
            /---------------------------------------------------------------------------*/
            int initUART2(u8 mode, int speed, u8 format, u8 parity, u8 flow_control);

            /*---------------------------------------------------------------------------
                | Portability: WMP 100/150
                |----------------------------------------------------------------------------
                | Routine description:
                |  * Handler of control events in UART, sets UART mode
                |    If all ok returns TRUE else FALSE
                |---------------------------------------------------------------------------
                | Parameters description:
                |   adl_fcmEvent_e evnt: FCM event that raised handler.
                /---------------------------------------------------------------------------*/

                static bool EvhCrtlUart2(adl_fcmEvent_e evnt);

                /*---------------------------------------------------------------------------
                | Portability: WMP 100/150
                |----------------------------------------------------------------------------
                | Routine description:
                |  * Handler when data recived, echo data until ESC recived, then switch to ATMODE
                |---------------------------------------------------------------------------
                | Parameters description:
                |   u16 datalength: number of bytes recived
                |   u8 *data: pointer to data recived
                /---------------------------------------------------------------------------*/

                static bool EvhDataUart2(u16 datalength, u8 *data);


                /*---------------------------------------------------------------------------
                | Portability: WMP 100/150
                |----------------------------------------------------------------------------
                | Routine description:
                |  * Handler of port configuration using AT, al responses are ignored
                |---------------------------------------------------------------------------
                | Parameters description:
                |   adl_atResponse_t *Rsp: response from AT command
                /---------------------------------------------------------------------------*/
                static void EvhConfUartx(adl_atResponse_t *Rsp);
                /*-------------------------------- Functions --------------------------------*/

                   int initUART2(u8 mode, int speed, u8 format, u8 parity, u8 flow_control){

                      char comand[15];
                      /* Check if port available*/
                      if(adl_fcmIsAvailable(ADL_FCM_FLOW_V24_UART2))
                      {
                         /* Save UART operation mode: DATA o AT*/
                         mode_uart2 = mode;

                         /* config parity with AT Command*/
                         wm_sprintf(comand,"AT+ICF=%d,%d", format, parity);
                         adl_atCmdCreate(comand, UART_2,EvhConfUartx,NULL);

                         /* speed  with AT Command*/
                         wm_sprintf(comand,"AT+IPR=%d", speed);
                         adl_atCmdCreate(comand, UART_2,EvhConfUartx,NULL);

                         /* flow control  with AT Command*/
                         switch(flow_control){
                         /* hardware flow control */
                         case CTS_RTS:
                            adl_atCmdCreate("AT+IFC=2,2",UART_2,EvhConfUartx,NULL);
                            break;
                            /* no hardware flow control */
                         case NO_CTS_RTS:
                            adl_atCmdCreate("AT+IFC=0,0",UART_2,EvhConfUartx,NULL);
                            break;
                         }
                         /* save configuration */
                         adl_atCmdCreate("AT&W", UART_2, (adl_atRspHandler_t)EvhConfUartx,NULL);

                         /* subscribe to FCM uart service */
                          handle_uart2 = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART2, EvhCrtlUart2, EvhDataUart2);

                         return 0;
                      }
                      else {
                         adl_atSendResponse(ADL_AT_RSP, "\r\nUART2 not available");
                      }
                      return -1;

                   }/*initUART2*/



                   static bool EvhCrtlUart2(adl_fcmEvent_e evnt){
                          switch (evnt)
                           {
                           /* when com is open, operation mode is defined */
                           case ADL_FCM_EVENT_FLOW_OPENNED:
                              /*  DATA MODE */
                              if(mode_uart2 == DATAMODE){
                                 adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: Flow Opened in Data Mode");
                                 adl_fcmSwitchV24State(handle_uart2, ADL_FCM_V24_STATE_DATA);
                              }
                              /* AT MODE */
                              else if(mode_uart2 == ATMODE){
                                 adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: AT Mode");
                                 adl_fcmSwitchV24State(handle_uart2, ADL_FCM_V24_STATE_AT);
                              }
                              break;

                           case ADL_FCM_EVENT_V24_DATA_MODE:
                              /* DATA MODE OK */
                        	   adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: Data Mode Ready! ");
                        	  adl_fcmSendData(handle_uart2, "GPGLL", 11);


                              break;

                           case ADL_FCM_EVENT_V24_AT_MODE:
                              /* AT MODE OK */
                        	   adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: AT Mode Ready! ");

                              break;

                           case ADL_FCM_EVENT_RESUME:
                        	   adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: Event resume! ");
                              break;

                           case ADL_FCM_EVENT_MEM_RELEASE:
                        	   adl_atSendResponse(ADL_AT_RSP, "\r\nUART2: Mem release! ");
                              break;

                           default:
                              return FALSE;
                              break;
                           }
                           return TRUE;
                       }/*EvhCrtlUart2*/


                   static bool EvhDataUart2(u16 datalength, u8 *data){
                	   adl_atSendResponse(ADL_AT_RSP,"\r\nInto Data handler");
                	     ascii NewText [ 20 ], txt[20];
                	     u16 i;
                	     result = *data;

                	     for ( i = 0 ; i < datalength ; i++ ){
                	        if ( data [ i ] == '~' ){
                	           adl_fcmUnsubscribe(handle_uart2);
                	        } else {
                	           txt[i]=data[i];
                	           wm_sprintf ( NewText, "%c", txt[i] );

                	           //adl_atSendResponse(ADL_AT_RSP, NewText);//to send received data and display using uart1.

                	           adl_atSendResponse(ADL_AT_RSP, NewText);
                	           adl_atSendResponse(ADL_AT_RSP, data[i]);
                	        }
                	     }
                          return TRUE;

                       }/*EvhDataUart2*/
                   static void EvhConfUartx(adl_atResponse_t *Rsp){

                       }/*EvhConfUartx*/




    void main_task ( void )
    {
       initUART2(DATAMODE, 57600 , DATA8_STOP1 , NONE_PARITY , NO_CTS_RTS);

    }

You will really be lovely to help me!


#5

+WIND: gives General Indications - including, but not limited to, GSM Registration.

Note that an FCM subscription has two handlers:

  1. The Data handler;
  2. The Event handler.

I think you may be confusing the two…?


#6

Hi awneil!
Thanks a lot again for your help. But you said:

I don’t think i’m confusing the two handlers. The two handlers can not be invoked at the same time, right?
When in AT mode (or in interactive mode), it’s the event control handler which have hand, is it correct?
Then when switched to data mode data control handler is active, right?
in my case, I thought that when the ADL_FCM_EVENT_FLOW_OPENNED happens, then the ADL_FCM_EVENT_V24_DATA_MODEevents are ON, the data control handler should automatically take control of the port then manage my data as instructed in my

EvhDataUart2(u16 datalength, u8 *data)

function, as I have suscribed to the FCM with this:

handle_uart2=adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART2, EvhCrtlUart2,EvhDataUart2);

Or maybe I am completely out of the topic. Please awneil, tell me if there is another way to ACTIVATE or SWITCH hanlers functions.

Thanks