In our Graduation project, we're supposed to connect a GSM module (ADH8066) to our ARM board (OK-6410) which is running Embedded Linux (Qtopia) and communicate with it.
When we first operate on the module, it sends a "Ready" message, then we can communicate with it through AT commands. We've communicated with it successfully using Hyper-Terminal and managed to send a simple SMS.
The problem happens when we try to communicate with it from the ARM board.
We manage to receive the "Ready" message, but then we don't have any response.
Here is the code we've developed till now:
int main(void){
int fd;
char *dev ="/dev/ttySAC3";
struct termios options;
char buffer[20];
char buffer2[20];
char *bufptr;
char *bufptr2;
bufptr = buffer;
bufptr2 = buffer2;
int nbytes,nbytes2=0;
fd = open (dev, O_RDWR | O_NOCTTY);
tcflush(fd, TCIOFLUSH);
tcgetattr(fd, &options);
cfsetispeed(&options, B115200); //Set Baud-rate to 115200
cfsetospeed(&options, B115200);
options.c_cflag |= CLOCAL | CREAD; //Enable the receiver and set local mode
options.c_cflag &= ~PARENB; //No parity (8N1)
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS; //Disable hardware flow control
options.c_lflag |= (ICANON | ECHO | ECHOE); //enable input-canonical mode
options.c_iflag = IGNPAR; //Ignore parity errors
options.c_iflag &= ~(IXON | IXOFF | IXANY); //Disable software flow control
options.c_oflag &= ~OPOST; //disable output-processing mode
tcsetattr(fd, TCSANOW, &options);
printf("Hello GSM\n");
tcflush(fd, TCIOFLUSH);
//capture the "Ready" message
while(1){
nbytes = read(fd, bufptr, 1);
if (0!=strstr(buffer,"Ready")){
printf("\nReady Found!\n");
break;
}
bufptr += nbytes;
}
tcflush(fd, TCIOFLUSH);
// send simple "AT" AT command
int y = write(fd,"AT\r\n",4);
if (y==4)
printf("Written\n");
//trying to capture the "OK" response for the above AT command
while(1){
nbytes2 = read(fd, bufptr2, 1);
printf("%c\n",*bufptr2);
}
return 1;
}
we got this response:
Hello GSM
--- Ready Found! ---
Written: 3
and then it blocks and stays idle.
If we manage to capture the "Ready" message, doesn't that mean that "read" is working fine? and If "written" is printed above, doesn't that mean that "write" is working fine?
So, why can't we communicate with the module?
Thanks.