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; } }
whatever is sent out of the modem is seen in the HTerm
To be clear, what you need to do is to monitor both the Tx and the Rx line simultaneously - something like this:
+----------+ | | | PC | | | +---+---+--+ | | ^ ^ | | | | | | +---------+ | | +---------+ | | | | | | | Tx+->-----------+--------+ | | AT89S52 | | | M590E | | Rx+-<-------+------------+ | | | | | +---------+ +---------+
Then you can be sure that you're seeing everything that's happening between the modem & the MCU.
That design have been a standard tool for embedded developers for a good many years.
There are also nice programs that can record from multiple serial ports while storing exact time stamps just to make it easy to match and combine the send and receive data.
Just one note here is to make sure all parts of the circuit communicates using the same levels. So if 8051 and modem uses TTL levels, then the circuit needs to be wired with two 5V-to-USB serial adapters or use two 5V-to-RS232 converters. Or possibly adapters with 3V3 logic if the modem and processor is running on 3V3.
The modem's voltage levels are compatible with the MCU - aren't they ... ?
And you do have Tx & Rx the correct way around - don't you ?
Note that a modem is a DCE so, strictly, "Tx" should be an input - it is the data to be transmitted over the comms link. But some modem manufacturers try to be "helpful" (sic) and make "Tx" an output...
The skimpy stuff n the net does not tell, is the modem RS232 or TTL?
I notice that the NEOWAY M590E documentation claims it uses a 2.85V IO power system. docs.mirifica.eu/.../Neoway M590 Hardware Design Manual V1.1.pdf
Input voltages should be below 0.57V or above 2.0V (but max 3.3V)
Output voltages will be below 0.2V or above 2.5V (but max 2.85V)
Is that really compatible with your AT89S52? Isn't that a 5V device with 4.0 to 5.5V allowed supply voltage? Which would indicate it would give out a too high voltage on the TX pin.
www.atmel.com/.../doc1919.pdf The data sheet seems to indicate that outputs can reach 0.9*VCC which would be 4.5V if VCC is 5V. And the chip wants at least 0.7*VCC as high input or 3.5V which is way more than the modem can give.
Datasheets doesn't hurt to read. They can even be very, very useful to read. That might also be the reason why companies spends so much time creating them.
Thanks alot.... would do that right now!
"I do, but they are working on a large project at the moment...."
You do what?
Who are "they"?
What does the above have to do with this thread?
Note that even if this forum pretends to support tree-based threads, it really doesn't. It's not possible to see which previous message you responded to.
Another thing - haven't you already grasped that much issues comes from you supplying too little information? So it would be logical to not write short answers that assumes that we happens to be thinking about exactly the same thing you were thinking on when you wrote the text just to have a chance to guess what you intended to mean!