HOWTO: Different setup for UART 1 & 2

Hi,

Actually, it is quite easy to setup different parameters on UART1 and UART2 from the embedded application, if you know how…

From AT Commands Interface Guide in the V24-V25 commands section:

This sentence completely misled me and another person I was reading this with. How do you select a UART? I knew how to activate with AT+WMFM, so I thought that should be it. I tried to deactivate UART1 then activated UART2 and assumed the AT+IPR, etc. commands would now be used to setup the UART2 parameters. Wrong!

Actually, how to accomplish this setup is described in the Open AT ADL User Guide - in adl_atCmdCreate section. A place I didn’t expect it…

It works like this:

adl_atCmdCreate( "AT+IPR=38400", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), Res_IPR_Handler, "*", NULL );

So there is no need to disable UART1… nice!

One more thing: I think you also need to use the ADL_AT_PORT_TYPE macro, if you would like to save the setting with AT&W.

Best Regards,
Jan

I have to disable UART1 with AT command (AT+WMFM=0,0,0). How can activeted it?
Thanks

Did I understand this right, that you have deactivated it and now would like to activate again?

If you have activated UART2 in AT-mode, you could just enter the activate command there.

If you deactivated by the internal application, you might be able to re-activate only from the internal application, but you can’t connect to load a modified application because the port is deactived, right?

I don’t know if you may be able to use the Target Monitor Tool to connect anyway. If that fails and you can’t run the application in Debug mode you might need to flash the wavecom core software by using the bootpin…

After flashing the defaults will be restored and UART1 is activated.

Best Regards,
Jan

Hi Jan,

I had disabled the UART1 port by using AT+WMFM=0,0,0 command.

How can I enable the port by using the BOOT switch?
Can you please describe me the procedure in detail?

Thanks,
Vali.

Hi Vali,

this procedure is quite involved, if you haven’t done that yet you probably should speak to tech support of your distributor.

Do you have a Starter-Kit? That would simplify the procedure, because there is a switch to enable boot mode…

In any case you would need the program DWLWin and core firmware files that can be used with DWLWin. (I think those are not included in the OpenAT distribution CD’s)

Best Regards,
Jan

Hi Jan

Thanks for response

Hi Jan, I´m here once again now in this topic…

As you told:

adl_atCmdCreate( "AT+IPR=38400", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), Res_IPR_Handler, "*", NULL );

Can activate the UART2 use, correct?

  1. How can I identify if the data I´m receiving is from UART1 or UART2?

  2. For the UART2 use, do I need the full modem control of the serial or the RX and TX are enough? I mean… if I´m receiving for example a Text String.

Best Regards,

Henrique

Hi Henrique,

This code actually only configures the port speed… To activate a port you need to use the AT+WMFM command first…

When you subscribe for the flow, e.g.

Handle = adl_fcmSubscribe( ADL_FCM_FLOW_V24_UART2, fcmCtrlH, fcmDataH );

you have passed a handler for the data, here it is fcmDataH. When this function is called you know it came from UART2. Your subscription for UART1 could have a different data handler so when the handler for UART1 is called you know that the data came from UART1.

As far as I know, UART2 doesn’t have much more than RX / TX… So, you should be OK just using these!

Best Regards,
Jan

To send AT+WMFM command through Code… I have to use a adl_atCmdCreate(“AT+WMFM”… right?

Thanks,
Henrique

That’s right! On OpenAT 3.02 you could do it with for example:

adl_atCmdCreate( "AT+WMFM=0,1,2", FALSE, Res_WMFM1_Handler, "*", NULL );

Best Regards,
Jan

The Res_IPR_Handler is the Handle responsible for the speed response right?

Do I really need to have one? Even if I don´t want to treat eventually errors or anything else?

Best Regards,

Henrique

Is this code possible?

void UART2_Enable ( void )
{

	adl_atCmdCreate( "AT+WMFM=0,1,2", FALSE, Res_WMFM1_Handler, "*", NULL );

	adl_atCmdCreate( "AT+IPR=19200", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), Res_IPR_Handler, "*", NULL );

	adl_fcmSubscribe( ADL_FCM_FLOW_V24_UART2, fcmCtrlH, fcmDataH );

}

void fcmCtrlH ( u8 event )
{
    switch ( Event )
    {
        case ADL_FCM_RET_ERROR_GSM_GPRS_ALREADY_OPENNED :
            TRACE (( 1, "Flow GSM already Opened"));
        break;
	}
}

void fcmDataH ( u16 DataLen, u8 * Data )
{
    u8 result;

    adl_atSendResponse(ADL_AT_UNS, "\r\n<- Receive FCM Data Blocks \r\n");
    DUMP ( 1, Data, DataLen );

}

bool Res_WMFM1_Handler ( void )
{
	return TRUE;
}

bool Res_IPR_Handler ( void )
{
	return TRUE;
}

The last two Handlers don´t matter for me yet…

Att,

Henrique

for type correctness, the handler should be defined as functions with one parameter, like bool Res_WMFM1_Handler( adl_atResponse_t *paras );

If you consider to move to data mode on the flow later, you probably should subscribe to the flow in the last handler of setting up the port parameters, e.g.

bool Res_IPR_Handler( adl_atResponse_t *paras )
{ 
   adl_fcmSubscribe( ADL_FCM_FLOW_V24_UART2, fcmCtrlH, fcmDataH );
   return TRUE; 
}

and remove the adl_fcmSubscribe in UART2_Enable… (this way you can avoid a problem you might have when sending a command with the ADL_AT_PORT_TYPE macro, see also http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=133)

Best Regards,
Jan

Jan, it seems like it worked! At least I got no kind of error… I´ll try with the external driver this time and I´ll let you know!

Best Regards,

Henrique

Hi Jan!

Just 2 Little questions:

If I want to send data to the UART2, all I need to do is call the adl_fcmDataSend or adl_fcmDataSendExt and as a parameter use the handler I subscribed to UART2, right?

What´s is the difference between the adl_fcmDataSend and adl_fcmDataSendExt functions? The Wavecom documentation says it is the processing on the data block. But it wasn´t so clear to me… do you have any clear words to translate for us!?

Thanks a lot!

Henrique

Here´s what I did:

/* Prototype - UART2 */

void UART2_Enable ( void );
void fcmCtrlH ( u8 event );
void fcmDataH ( u16 DataLen, u8 * Data );
bool Res_WMFM1_Handler ( adl_atResponse_t *paras );
bool Res_IPR_Handler( adl_atResponse_t *paras ); 
s8 UART2_Handle;

void UART2_Enable ( void )
{

	adl_atCmdCreate( "AT+WMFM=0,1,2", FALSE, Res_WMFM1_Handler, "*", NULL );

	adl_atCmdCreate( "AT+IPR=19200", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), Res_IPR_Handler, "*", NULL );

	UART2_Handle = adl_fcmSubscribe( ADL_FCM_FLOW_V24_UART2, fcmCtrlH, fcmDataH );

}

void fcmCtrlH ( u8 Event )
{

adl_atSendResponse(ADL_AT_UNS, "\r\n<- FCM CRTL \r\n");

}

void fcmDataH ( u16 DataLen, u8 * Data )
{
    u8 result;

    adl_atSendResponse(ADL_AT_UNS, "\r\n<- Receive FCM Data Blocks \r\n");
    DUMP ( 1, Data, DataLen );

}

bool Res_WMFM1_Handler ( adl_atResponse_t *paras )
{
	return TRUE;
}

bool Res_IPR_Handler( adl_atResponse_t *paras ) 
{ 
   //adl_fcmSubscribe( ADL_FCM_FLOW_V24_UART2, fcmCtrlH, fcmDataH ); // Para mudar o FLOW para Dados
   return TRUE; 
}

The “UART_ENABLE” is called from the adl_main function.

Then inside a Timer I try to put the following data through adl_fcmSendData:

ascii teste [20];
	u8 teste_len;
	wm_sprintf ( teste, "Testando!");
	teste_len = wm_strlen(teste);

    adl_fcmSendData(UART2_Handle, teste, teste_len);

Then I started the program on the module (the UART1 was connected to the Computer´s serial and the Hyper Terminal was renning).

Everything seemed fine.

Then I shut off Hyper Terminal listening function.
Switched the serial cable from UART1 to UART2… set up another connection on the Hyper Terminal (this time with 19200bps speed).

But nothing came on screen…

Any ideas!?

Best Regards,

Henrique

UART2 is the problem…

Is there any way to use UART2 and GSM at the same time?

Thanks,

Henrique