Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem in AT+CPBR Command with PIC18F452

Status
Not open for further replies.

softlab

New Member
Dear all,

I can able to send and receive all AT Commands except (AT+CPBR and AT+CMGR Commands). I want to store all the phone book entries (already stored in SIM) into array. So, When I start the GSM Modem/Module, I issue AT+CPBR=1,250 command and read the Phone Book (SIM) and Store the Phone numbers into the array. If I issue AT+CPBR command, it executes well and return the phone book records and hangs. I don't know why. All other commands work fine. Any help? I give you my code here. Pl go thro' that and pl let me know if you found any errors. The code could be little large. Inconvenience regretted.


Code:
/* MAKE RECEIVE AS HIGH INTERRUPT PRIORITY */
#pragma code rx_interrupt = 0x8 //high interrupt vector
void rx_int (void)
{
    if (PIR1bits.RCIF){
        PIR1bits.RCIF = 0; // clear interrupt flag
        rx_handler();
    }
    return;
}
#pragma code

#pragma interrupt rx_handler // changed the interrupt to interruptlow
void rx_handler (void)
{
  unsigned char input;
  
  input = ReadUSART();
    
	switch(input){
            
	case '\x0A': // if line feed detected in the GSM output i.e. '\n'
                        break;
            case '\x0D': // if carriage return detected i.e. '\r'
                        gsmOutput_c[i] = '\x00';
           		lenOfGSMOutput = strlen((char*)gsmOutput_c);
                        if (lenOfGSMOutput > 0){
	                     i = 0;
	   	            lenOfGSMOutput = 0;
                            showGSM_DATA(gsmOutput_c);
                            *gsmOutput_c = 0;
                            
                            PIE1bits.RCIE = 1; // enable receive interrupts
                            
                        }
                        break;
                        			
        default: // if characters received
		if(i < 80){
		           gsmOutput_c[i] = input;
			i++;
		}
		else{
			i = 0;
		}
                break;
        }//end for switch
}

//Processing and Validating GSM_MODEM_OR_MODULE OUTPUT

void showGSM_DATA(char gsmOutput_s[]){
    
    if (strcmppgm2ram(gsmOutput_s, (const far rom char*)"OK") == 0){
       OK = TRUE;
    }
    if (strcmppgm2ram(gsmOutput_s, (const far rom char*)"ERROR") == 0){
       OK = FALSE;
     return;
    }
        	
	if (strcmp(gsmOutput_s, NO_CARRIER) == 0){
		WriteCmdXLCD(CLR_LCD); 
		while(BusyXLCD()); 
		WriteCmdXLCD(HOME_LCD); 
		while(BusyXLCD()); 
		putrsXLCD("NO CARRIER");
     return;
	}
	
	if (strcmp(gsmOutput_s, Error) == 0) {
		WriteCmdXLCD(CLR_LCD); 
		while(BusyXLCD()); 
		WriteCmdXLCD(HOME_LCD); 
		while(BusyXLCD()); 
		putrsXLCD("Error");
     return;
	}
    
    if (strcmppgm2ram(NextGSMCmd, (const far rom char*) "PhBk_Stored") == 0){
        
        *NextGSMCmd = 0;
        *gsmOutput_s = 0;
        
        WriteCmdXLCD(CLR_LCD); 
		while(BusyXLCD()); 
		WriteCmdXLCD(HOME_LCD); 
		while(BusyXLCD());
        
        if (OK == TRUE){
            OK = FALSE;
    		putrsXLCD("PH BK READ - OK");
        }
        else{
            putrsXLCD("PH BOOK ERROR");
        }
     return; 
    }
    
    if (strlen(gsmOutput_s) > 5){
        
	strBuff = 0;
	i = 0;
       
	while(i < 5){
		strBuff[i] = gsmOutput_s[i];
		i++;
	}
	strBuff[i] = '\x00';
	i = 0;
		
	if (strcmppgm2ram(strBuff, (const far rom char*)"+CPBR") == 0){
            
            *strBuff = 0;
            if (strcmppgm2ram(NextGSMCmd, (const far rom char*) "store_PhBk_Into_Array") == 0){
                strcpypgm2ram(NextGSMCmd, (const far rom char*) "PhBk_Stored");

Here the problem araises. If I comment the LCD Commands as follows, it works fine. But If I uncomment, The text "gsmOutput_s" displayed and hangs.

Code:
                /*
                *gsmOutput_s = 0;
                WriteCmdXLCD(CLR_LCD); 
            while(BusyXLCD()); 
            WriteCmdXLCD(HOME_LCD); 
            while(BusyXLCD()); 
            putrsXLCD("gsmOutput_s");
               */
            }
          return;
        }
    } 
}

Code:
void main (void)
{

    TRISA = 0; // RS, R/W, E pins of LCD
    /* Configure all PORTB pins for output except RB0*/
    TRISB = 0; // RB0 as Input for Interrupt
    TRISD = 0; // set PORTD as Output for LCD (D4 to D7) 
    PORTB = 0; // Initialize portB
    PORTD = 0; // Initialize PORTD
    
    /* Make receive interrupt high priority */
    IPR1bits.RCIP = 1;
    
    /* Enable interrupt priority */
    RCONbits.IPEN = 1;
    /* Enable all high & low priority interrupts */
    INTCONbits.GIEH = 1;  // interrupt on RB0
    
    OpenXLCD(FOUR_BIT & LINE_5X7); // Open and Initialize LCD
	
    /*
    * Open the USART configured as
    * 8N1, 9600 baud, in polled mode
    */
    OpenUSART (USART_TX_INT_OFF &    //Set and Open Serial Port
               USART_RX_INT_ON &
               USART_ASYNCH_MODE &
               USART_EIGHT_BIT &
               USART_CONT_RX &
               USART_BRGH_HIGH, 25);
    
    i = 0;
    
    OK = FALSE;
    strcpypgm2ram(NextGSMCmd, (const far rom char*) "store_PhBk_Into_Array");
    
    while (BusyUSART());
    putrsUSART((const far rom char *)"AT+CPBR=1");
    while (BusyUSART());
    putcUSART(0x0A);
    putcUSART(0x0D);
    
    /* Loop forever */
    while (1);
    // maintain the power-down mode until interrupt occurred 
    // and return to sleep once if the interrupt has been serviced***
    
}
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top