# I cant watch +CREG: 1

**URL:** <https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682>\
**Category:** Legacy AirPrime modules\
**Created:** [September 29, 2009, 8:54pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682 "2009-09-29T20:54:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicool67](https://avatars.discourse-cdn.com/v4/letter/n/b3f665/32.png) [@nicool67](https://forum.sierrawireless.com/u/nicool67)\
**Post date:** [September 29, 2009, 8:54pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/1 "2009-09-29T20:54:31Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![nicool67](https://avatars.discourse-cdn.com/v4/letter/n/b3f665/32.png) [@nicool67](https://forum.sierrawireless.com/u/nicool67)\
**Post date:** [September 29, 2009, 8:57pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/2 "2009-09-29T20:57:46Z")

</div>

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!.

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 29, 2009, 9:21pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/3 "2009-09-29T21:21:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nicool67](https://avatars.discourse-cdn.com/v4/letter/n/b3f665/32.png) [@nicool67](https://forum.sierrawireless.com/u/nicool67)\
**Post date:** [September 30, 2009, 12:22pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/4 "2009-09-30T12:22:38Z")

</div>

Thanks!!, ill reply with this feature.

```auto
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;
}
```

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 30, 2009, 1:14pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/5 "2009-09-30T13:14:00Z")

</div>

Do you really write your code like that - with no indentation at all ❓😮

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

---

<div class="post-metadata">

**Author:** ![nicool67](https://avatars.discourse-cdn.com/v4/letter/n/b3f665/32.png) [@nicool67](https://forum.sierrawireless.com/u/nicool67)\
**Post date:** [September 30, 2009, 1:38pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/6 "2009-09-30T13:38:18Z")

</div>

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

The important code in the hole aplicattion is this:

```auto
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.

---

<div class="post-metadata">

**Author:** ![nicool67](https://avatars.discourse-cdn.com/v4/letter/n/b3f665/32.png) [@nicool67](https://forum.sierrawireless.com/u/nicool67)\
**Post date:** [September 30, 2009, 2:16pm UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/7 "2009-09-30T14:16:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JasonDiplomat](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@JasonDiplomat](https://forum.sierrawireless.com/u/JasonDiplomat)\
**Post date:** [October 23, 2009, 9:00am UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/8 "2009-10-23T09:00:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [October 23, 2009, 9:09am UTC](https://forum.sierrawireless.com/t/i-cant-watch-creg-1/3682/9 "2009-10-23T09:09:11Z")

</div>

> [@nicool67](#):
>
> I realized that the unsolicited response +CREG: 1 comes faster than the event ADL\_SIM\_STATE\_FULL\_INIT.

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…
