【问题标题】:Can't write to GSM module through Serial connection from ARM board无法通过 ARM 板的串行连接写入 GSM 模块
【发布时间】:2012-06-12 17:06:33
【问题描述】:

在我们的 Graduation 项目中,我们应该将 GSM 模块 (ADH8066) 连接到运行嵌入式 Linux (Qtopia) 的 ARM 板 (OK-6410) 并与之通信。

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

当我们尝试从 ARM 板与其通信时,就会出现问题。

我们设法收到“就绪”消息,但没有任何响应。

这是我们目前开发的代码:

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;
}

我们得到的回应是:

Hello GSM

Ready Found!
Written

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

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

谢谢。

【问题讨论】:

  • tcflush 至少可以说是具有破坏性的。我很难理解您为什么要丢弃来自 GSM 模块的数据。假设这会奏效有点大胆。
  • 我以前没有使用过 AT 调制解调器,但我只是快速浏览了该标准 - 对我来说,您似乎不会在仅发送时收到任何响应“AT” - 这在超级终端中有效吗?你试过其他命令吗?

标签: linux arm gsm termios


【解决方案1】:

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

【讨论】:

  • 那是错误的。 Linux 会为你缓冲这个。运行两个应用程序是个坏主意。
  • 同意克里斯托夫。我已经编写了很多串行协议应用程序,并且在单个线程中完成所有事情从来没有遇到任何问题(或者,无论如何,答案中提出的问题都可以解决)。
  • 不建议在同一台 PC 或板上运行两个应用程序。事实上,它只是检查响应是否正确 rcvd。所以用户需要从另一个应用程序发出 cmds 并从另一个应用程序接收响应,以便可以清楚地区分问题所在。
猜你喜欢
  • 2018-08-11
  • 1970-01-01
  • 1970-01-01
  • 2021-10-23
  • 2019-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多