首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法通过ARM板的串行连接写入GSM模块

无法通过ARM板的串行连接写入GSM模块
EN

Stack Overflow用户
提问于 2012-06-13 01:06:33
回答 1查看 930关注 0票数 1

在我们的毕业设计中,我们应该将一个GSM模块(ADH8066)连接到运行嵌入式Linux (Qtopia)的ARM板(OK-6410)上,并与之通信。

当我们第一次操作模块时,它会发送一个“就绪”消息,然后我们可以通过AT命令与它通信。我们已经成功地使用超级终端与它通信,并设法发送了一条简单的SMS。

当我们试图从ARM主板与它通信时,问题就发生了。

我们设法接收到"Ready“消息,但随后没有任何响应。

以下是我们到目前为止开发的代码:

代码语言:javascript
复制
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; //enable 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);
    perror ("Read error: ");
    printf("%c\n",*bufptr2);
}

return 1;
}

我们得到的回应是:

代码语言:javascript
复制
Hello GSM

Ready Found!
Written

然后它就会阻塞并保持空闲。

如果我们设法捕捉到"Ready“消息,这是否意味着"read”可以正常工作?如果上面打印了"write“,这是否意味着”write“可以正常工作?那么,为什么我们不能与模块通信呢?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-06-29 20:36:16

您能够接收到"Ready“,因为调制解调器发送此消息时没有任何命令。但是当您开始发出ATM命令时,您需要立即接收响应,没有任何延迟,因为Modem会在您发出命令后立即恢复。在这里,您需要运行两个应用程序,一个是发出命令,另一个是接收响应。也可以使用定时器中断或读取串口响应。

票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11001405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档