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; } }
What is "it"? ie, What does "nothing"?
It is highly unlikely that the MCU is doing nothing.
Almost certainly, it is doing something: so your job is to find out what it is doing - and work out why that isn't giving the results you expect.
That, essentially, is what debugging is all about.
www.8052.com/.../120313
www.ganssle.com/.../developingagoodbedsidemanner.htm
For a start, have you monitored what the MCU is actually sending, and what is coming back from the modem?
//Command "AT+CMGF=1" receives OK
I can't see where you check that it is actually, "OK" ?
Also, are you sure you have all the CR & LF correct ?
I have tried debugging the program for over 2 weeks now. I also wait on the response from the modem. Kindly inform me of any bug u noticed in the code. please.
the mcu isnt seeing +PBREADY from the modem
So _how_ have you tried to debug?
You say the program isn't seeing +PBREADY. So what _is_ it seeing?
Does your debugging include a produced list showing exactly what you have sent and what you have received? Or is that not part of your debugging?
So tell us exactly what you have done?
What have you found out?
What conclusions have you drawn from your observations?
It's your project; you have the hardware in front of you - we don't
unsigned char RXD_VAL; RXD_VAL = SBUF;
if(RI)
one more has copied this I doubt the above error has been made by that many persons
I wonder how those 'graduates' whose diploma should read 'copying' rather than 'engineering' will fare in the real world
I feel more and more confident that some of us will have good and well payed jobs until we die, when looking at the "new guys" that are about to enter our profession, I feel quite confident that I still will be beating on my keyboards for many more years to come :D
But it isn't too strange if people does not realize that SFR need not behave identical to normal memory cells and that just reading from a SFR may result in additional side effects.
The biggest problem when people copy code they have found on the net is that they don't show an interest in fully understanding how the code actually works. Small children asks "why" about everything around them, since it's a working way to collect information. After a while, they have collect enough information to be more selective when asking questions.
Beginning embedded developers needs to return to that child stage and ask "why" about everything, until they have collected enough experience to be able to properly detect the trickier aspects and understands when something is obvious and when it's required to check the chip datasheet, the programming language standard or the tool manuals.
The first time I moved a "working" program from a 16-bit PC to a Sun workstation and got a "bus error", I was quite confused. I thought I knew C, but had never been in a situation where aligned/unaligned memory accesses mattered.
The biggest problems isn't the skills level of people asking questions, but the inability to ask good questions or to look for answers themselves. And the schools seems to have totally failed to teach the need for finding multiple information sources for facts checking. Why grab the first source code lines found instead of shopping around for more alternatives? Everything on the net isn't good or truthful.
Its (partly) a result of the "instant satisfaction" of today. If something takes more than a google search for a finished solution, most/some just panics...
The biggest problem when people copy code they have found on the net is that they don't show an interest in fully understanding how the code actually works.
I think the real reason is that by copying as the above, you get too much. A sensible way to start would be to just send a character on the serial bus ans get that to work, then send s string, then receive a character, then receive a string, then AND ONLY THEN start processing data. With a big glob of 'unknown' code that does not work, where do you start?
Per, we have all been at "WHAT THE ..."
The biggest problems isn't the skills level of people asking questions, but the inability to ask good questions or to look for answers themselves.
unfortunately I thing it is not inability, but unwillingness
I actually thought this platform was to aid peeps who have certain ish... if you dont know somethings, i guess its beest to keep shut. I wrote codes by myself and all ya be saying codes u got from the net. Serzly, if you have nothing constructive to say or share , i suggest you stay off this thread. thanks!!!
We have asked you questions. You don't seem to be too interested to answer them.
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?
So you aren't answering our questions, and you aren't reading the answers?
unsigned char RXD_VAL; RXD_VAL = SBUF; if(RI)
Do you really think it's a good idea to check if there is a received character in the UART _after_ you have already read out any available character?
Order of instructions really do matter, just as when you build a house you can't start with the roof and sometimes at the end consider building the bottom floor or the foundation under the floating roof.