I cant watch +CREG: 1

Hello everyone!!, im working on a GSM/GPRS project and i would like to read the unsolicited response ’ +CREG: 1’ and ‘+CGREG: 1’.

This is my code:

//attachment handler//
u8 initreg_SIM (void)
{
if (adl_atUnSoSubscribe("+CREG:",gms_register_handler)==OK)
{
TRACE (( 1, “[init_SIM]:+CREG: 1 subscribe OK” ));
if(adl_atUnSoSubscribe("+CREG: 0",gms_unregister_handler)==OK)
{
TRACE (( 1, “[init_SIM]:+CREG: 0 subscribe OK” ));
if(adl_atUnSoSubscribe("+CREG: 2",gms_unregister_handler)==OK)
{
TRACE (( 1, “[init_SIM]:+CREG: 2 subscribe OK” ));
return 1; //Primer paso de la inicializacion hecha.
}
else
TRACE (( 1, “[init_SIM]:+CREG: 2 subscribe ERROR” ));
}
else
TRACE (( 1, “[init_SIM]:+CREG: 0 subscribe ERROR” ));
}
else
TRACE (( 1, “[init_SIM]:+CREG: 1 subscribe ERROR” ));
return 0;
}

Later on, in the handlers…

bool gms_register_handler (adl_atUnsolicited_t *param)
{
if (GSM_ini==1 && GSM_reg==0) //Se debe registrar una sola vez.
{
GSM_reg=1;
TRACE (( 1, “[gms_register_handler]:SIM_REGISTRADO” ));
}
return TRUE;
}

bool gms_unregister_handler (adl_atUnsolicited_t *param)
{
if (GSM_ini==1 && GSM_reg==1)
{
TRACE (( 1, “[gms_unregister_handler]:SIM NO REGISTRADO.REINTENTADO…” ));
GSM_reg=0;
}
else
{
TRACE (( 1, “[gms_unregister_handler]:SIM NO REGISTRADO” ));
}
TRACE (( 1, “[gms_unregister_handler]:SIM NO REGISTRADO” ));
return TRUE;
}

When i run the apllication, it never go inside those handlers. But if y enter “AT+CREG?” the answer is “+CREG: 0,1” so i assume its registered!.
Can anyone help me?. Thanks!.

You need to post your code using the ‘Code’ tags to make it legible - see the ‘Code’ button to apply the ‘Code’ formatting…

Thanks!!, ill reply with this feature.

u8 initreg_SIM (void)
{
if (adl_atUnSoSubscribe("+CREG:",gms_register_handler)==OK)
{
TRACE (( 1, "[init_SIM]:+CREG: 1 subscribe OK" ));
if(adl_atUnSoSubscribe("+CREG: 0",gms_unregister_handler)==OK)
{
TRACE (( 1, "[init_SIM]:+CREG: 0 subscribe OK" ));
if(adl_atUnSoSubscribe("+CREG: 2",gms_unregister_handler)==OK)
{
TRACE (( 1, "[init_SIM]:+CREG: 2 subscribe OK" ));
return 1; //Primer paso de la inicializacion hecha.
}
else
TRACE (( 1, "[init_SIM]:+CREG: 2 subscribe ERROR" ));
}
else
TRACE (( 1, "[init_SIM]:+CREG: 0 subscribe ERROR" ));
}
else
TRACE (( 1, "[init_SIM]:+CREG: 1 subscribe ERROR" ));
return 0;
}

Later on, in the handlers....nicool67 
 


bool gms_register_handler (adl_atUnsolicited_t *param)
{
if (GSM_ini==1 && GSM_reg==0) //Se debe registrar una sola vez.
{
GSM_reg=1;
TRACE (( 1, "[gms_register_handler]:SIM_REGISTRADO" ));
}
return TRUE;
}



bool gms_unregister_handler (adl_atUnsolicited_t *param)
{
if (GSM_ini==1 && GSM_reg==1)
{
TRACE (( 1, "[gms_unregister_handler]:SIM NO REGISTRADO.REINTENTADO...." ));
GSM_reg=0;
}
else
{
TRACE (( 1, "[gms_unregister_handler]:SIM NO REGISTRADO" ));
}
TRACE (( 1, "[gms_unregister_handler]:SIM NO REGISTRADO" ));
return TRUE;
}

Do you really write your code like that - with no indentation at all :question: :open_mouth:

Note: don’t use TABs for indentation (their interpretation cannot be relied upon - especially on web forums) - use only spaces.

Well, actually i didint, but when i posted for some reason it appeared like that.

The important code in the hole aplicattion is this:

adl_simSubscribe(SimHandler,NULL); //First of all, i suscribed here
....
....
....
//in  SimHandler
case ADL_SIM_STATE_FULL_INIT: //I reached here without problems
...
...
...
//in an other part of the code
adl_atUnSoSubscribe("+CREG: 1",gms_register_handler)  // I need the +CREG: 1 response.
...
...
...
//in the handler
bool gms_register_handler (adl_atUnsolicited_t *param) //It never reaches here. 
{
if (GSM_ini==1 && GSM_reg==0) //Se debe registrar una sola vez.
    {
     GSM_reg=1;
     TRACE (( 1, "[gms_register_handler]:SIM_REGISTRADO" ));
    }
return TRUE;
}

So, i`ve said i cant manage to get inside “gms_register_manager”. I need the +CREG: 1 response to know the SIM registration. Thanks for advance

Best Regards.

I think i solve it!, i change the orden of the code. I realized that the unsolicited response +CREG: 1 comes faster than the event ADL_SIM_STATE_FULL_INIT. So, now i check when both of conditions are true to know if im really registered.

Thank u so much.

Don’t forget that CREG status of “5” is also registered…

As I understand it, the ADL_SIM_STATE_FULL_INIT indicates that everything including phonebook initialisations is complete;
Phonebook initialisations can take quite a long time, and are not required for GSM registration - hence registration may occur before ADL_SIM_STATE_FULL_INIT.

In practice, you just have to assume that the events could occur in either order.

Also note what JasonDiplomat said about +CREG: 5