Changing baud rate of UART 2

I am using the following code to open UART2 and configure 9600 baud rate.

I always get: Res_WMFM1_Handler +CME ERROR: 3 (operation not allowed).

Although the UART2 is opened (and switched to data mode - code not included), the baud rate is 115200 (default rate) even when I explictly set to 9600.

How do I modify the baud rate of UART2?

bool Res_IPR_Handler ( void )
return FALSE;

bool Res_WMFM1_Handler ( adl_atResponse_t *paras )
char strOut[255];
ascii *rsp;

rsp = (ascii *)adl_memGet(paras->StrLength);
wm_strRemoveCRLF(rsp, paras->StrData, paras->StrLength);

sprintf(strOut, "Res_WMFM1_Handler %s", rsp);
adl_atSendResponse ( ADL_AT_UNS, strOut);

adl_atCmdCreate( "AT+IPR=9600", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t)Res_IPR_Handler, "*", NULL );
adl_atCmdCreate( "AT+IFC=0,0", ADL_AT_PORT_TYPE( ADL_AT_UART2, FALSE ), (adl_atRspHandler_t)Res_IPR_Handler, "*", NULL );

UART2_Handle = adl_fcmSubscribe( ADL_FCM_FLOW_V24_UART2, (adl_fcmCtrlHdlr_f)hnd_fcmCtrl_U1, (adl_fcmDataHdlr_f)hnd_fcmData_U1 ); 
if(wm_strncmp(rsp, "OK", 2) == 0)
else if(!wm_strncmp(rsp, "+CME: Error", strlen("+CME: Error")))
    adl_atSendResponse ( ADL_AT_UNS, rsp);
return FALSE;


void UART2_Enable ( void )
adl_atCmdCreate( “AT+WMFM=0,1,2”, FALSE, (adl_atRspHandler_t)Res_WMFM1_Handler, “*”, NULL );

Don’t setup the parameters during data mode, only in AT mode.

I change the UART1 to data mode after I request the baud rate change with IPR command.

AT+IFC=0,0 or AT+IFC=2,2 is changing the UART1’s Flow Control settings.

However AT+IPR=9600 does NOT change the baud rate.

Do you wait for the module initialization?

Please format your code properly, because it is hard to read this way.

Don’t you want to change the UART2 settings?

Wheres is the code of the “hnd_fcmCtrl_U1” handler? Why U1 when you change the Uart2? Note that the IPR and IFC command have the same handler called “Res_IPR_Handler”, IFC command and IPR handler? :slight_smile: It is safer to do one thing at a time, anyway.

  1. Setup the parameters of the UART, wait for the command response handlers OK answers, after that the UART is in the expected config.
  2. Then you can do whatever you want.

can only be done if the port isn’t open yet.

If the port is already open, it will give an error.

Check first if the port is open or not and only run the above if you need to.