I am trying to communicate between AT89S52 microcontroller and NEOWAY M590E gsm module.I use HTerm to in communicating with the MCU it works perfectly. Whenever i connect the modem to the MCU it does nothing. For each command it sends , i allow it to turn on a the led of different ports. Unfortunately, none of the leds came on. I wonder why that is. KIndly help me out.
#include <reg51.h> void confirmPBready(void); void BYTEwrite( unsigned char VAL, unsigned char buffLEN, unsigned char *buffADDR); void sendAT(unsigned char *buf); bit COMP_buff2buff( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN); void delay(void); bit OKay( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN); void confirmOK(); unsigned char rcx[13]; unsigned char txtMOD[]="AT+CMGF=1\r"; unsigned char TE_com[]="AT+CSCS=\"GSM\"\r"; unsigned char MOBnum[]="AT+CMGS=\"+2349056777712\"\r"; bit RXDcmpt; //this flag is set if end of a string is detected. bit PBflag; //this flag is set when the MCU gets PB ready message. unsigned char i, rxd_cnt = 0; //counts as value are recieved in the serrial ISR. unsigned char SERIALcase ; //switch case in ISR. unsigned char *loc; void main() { //INITIALIZATION SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TR1 = 1; ES = 1; EA = 1; SERIALcase = 1; //set the default of the serial switch case in ISR. PBflag = rxd_cnt = RXDcmpt = 0; //set flag to default. while(!PBflag) { if(RXDcmpt) //Check if MCU recieved a value { confirmPBready(); //Check if its PBready. if(!PBflag) { rxd_cnt = 0; BYTEwrite(0x00,rxd_cnt,rcx); RXDcmpt = 0; } } } BYTEwrite(0x0,rxd_cnt,rcx); //clear buffer rxd_cnt= PBflag = RXDcmpt = 0; //PBready recievd. Proceed with confirguration. sendAT(txtMOD); while(!PBflag) { if(RXDcmpt && !PBflag) //Check if MCU recieved a value confirmOK(); //Check if its OK. } rxd_cnt = PBflag = RXDcmpt = 0; BYTEwrite(0,sizeof(rcx),rcx); //Command "AT+CMGF=1" receives OK sendAT(TE_com); while(!PBflag) { if(RXDcmpt && !PBflag) //Check if MCU recieved a value confirmOK(); //Check if its OK. } rxd_cnt = PBflag = RXDcmpt = 0; BYTEwrite(0,sizeof(rcx),rcx); //Command AT+CSCS=\"GSM\" receives OK sendAT(MOBnum); for(i = 1; i<30; i++) delay(); sendAT("GSM MODULE TEXT VIA CODING"); for(i = 1; i < 30 ; i++) delay(); sendAT("0x1A"); for(i = 1; i<60; i++) delay(); } void delay(void) { unsigned int i; for(i=0;i<25000;i++); } void BYTEwrite( unsigned char VAL, unsigned char buffLEN, unsigned char *buffADDR) { while(buffLEN) { *buffADDR++ = VAL; //write the value into address. buffLEN--; //decrement the lenght } return; } bit COMP_buff2buff( unsigned char *BUFF1, unsigned char *BUFF2, unsigned char LEN) { while(LEN) { if(*BUFF1++ != *BUFF2++) //Check if both value in address are same. { RXDcmpt = 0; return 0; //One value is different. } LEN--; //Decrement. } //AT Last, all values are the same in both buffers. return 1; } void confirmPBready() { if(COMP_buff2buff(rcx,"+PBREADY", rxd_cnt)) //Check if the value recieved is PBready {PBflag = 1; //YES. So set flag. } return; } void confirmOK() { if( COMP_buff2buff(rcx ,"OK", rxd_cnt))//Check if the value recieved is PBready PBflag = 1; //YES. So set flag. return; } void serial(void) interrupt 4 { unsigned char RXD_VAL; RXD_VAL = SBUF; if(RI) { switch(SERIALcase) { case 1: if(RXD_VAL == 0x0D) {//clear the buffer if the value is 0x0D SERIALcase=2; } break; case 2: if(RXD_VAL == 0x0A) {//clear the buffer if the value is 0x0A SERIALcase = 3; // buffer must receive OD n OA first } break; case 3: if(RXD_VAL == 0x0D) {//the next character should be 0x0A. SERIALcase = 4; //check for 0x0A. } else { rcx[rxd_cnt++] = RXD_VAL; //save the value recieved in rcx buffer } break; case 4: if(RXD_VAL == 0x0A) {//If 0x0A is recieved after 0x0D, then this is the end of recieve frame. RXDcmpt = 1; //set recieve complete flag. } else { rcx[rxd_cnt++] = RXD_VAL; //save the value recieved in rcx buffer } SERIALcase = 1; //its not 0x0A, so go back to keep recieveing till you detect another 0x0D. break; } } RI = 0; } void sendAT(unsigned char *buf) { while(*buf) { SBUF = *buf++; while(!TI); TI=0; } }
I only have access to the internet when am at work. When am home the internet isn't really good. Which is why i was unable to reply, sorry about that. Please if you see any bug in the program kindly let me know. I use a vero board where i connect the modem , mcu and my pc(HTerm) inorder to debug. I notice the received character in the SBUF isnt copying into the RXD_VAL variable. felt probably its from me debugging it. after i ran the program simulating my pc as the modem, using usb to serial cable it worked perfectly, but whenever i connect the modem to the MCU it just doesn't receive anything from the modem. What do you think i can do?