文档首页 > > SDK参考> SDK开发指南> LiteOS端云互通组件实战演练> (参考)端云互通组件无线接入实例> 移植GSM模块-SIM900A

移植GSM模块-SIM900A

分享
更新时间: 2019/01/02 GMT+08:00

与ESP8266非常类似,只不过具体AT命令有稍微差异。

  1. STM32F429开发板上连接SIM900A串口GSM模块,如下图所示

  2. 在设备文件sim900a.c定义API结构体。

    at_adaptor_api at_interface = {  
        .init = sim900a_ini,  
        /*TCP or UDP connect*/  
        .connect = sim900a_connect,  
        /*send data, if no response, retrun error*/  
        .send = sim900a_send,  
        .recv_timeout = sim900a_recv_timeout,  
        .recv = sim900a_recv,  
        .close = sim900a_close,/*close connect*/  
        .recv_cb = sim900a_recv_cb,/*receive event handle, no available by now */  
    .deinit = sim900a_deinit,  
    };

    sim900a.c位于 LiteOS/components/net/at_device/gprs_sim900a。

  3. 在main.c文件中,代码如下:

    #elif defined(WITH_AT_FRAMEWORK) && (defined(USE_ESP8266) || defined(USE_SIM900A))  
         extern at_adaptor_api at_interface;  
         at_api_register(&at_interface);  
         agent_tiny_entry();  
    #endif

  4. 确保打开了编译宏

    图1 全局宏包含WITH_AT_FRAMEWORK和USE_SIM900A

  5. 在sim900a.c实现具体设备API接口。

    例如demo例程发送和接收函数如下:

    int32_t  sim900a_recv_timeout(int32_t id, int8_t * buf, uint32_t len, int32_t timeout)  
    {  
        uint32_t qlen = sizeof(QUEUE_BUFF);  
        QUEUE_BUFF  qbuf = {0, NULL};  
        printf("****at.linkid[id].qid=%d***\n",at.linkid[id].qid);  
        int ret = LOS_QueueReadCopy(at.linkid[id].qid, &qbuf, &qlen, timeout);  
        AT_LOG("ret = %x, len = %d, id = %d", ret, qbuf.len, id);  
        if (qbuf.len){  
            memcpy(buf, qbuf.addr, qbuf.len);  
            atiny_free(qbuf.addr);  
        }  
        return qbuf.len;  
    }  
    int32_t sim900a_send(int32_t id , const uint8_t  *buf, uint32_t len)  
    {  
        int32_t ret = -1;  
        char cmd[64] = {0};  
        if (AT_MUXMODE_SINGLE == at.mux_mode)  
        {  
            snprintf(cmd, 64, "%s=%d", AT_CMD_SEND, len);  
        }  
        else  
        {  
            snprintf(cmd, 64, "%s=%d,%d", AT_CMD_SEND, id, len);  
        }  
        ret = at.write((int8_t *)cmd, "SEND OK", (int8_t*)buf, len);  
        return ret;  
    }

    而SIM900A模块AT命令定义的宏在sim900a.h定义如下,具体含义可以查看SIM900A官方手册。

    #define AT_CMD_AT           "AT" 
     #define AT_CMD_CPIN         "AT+CPIN?"//check sim card 
     #define AT_CMD_COPS         "AT+COPS?"//check register network 
     #define AT_CMD_CLOSE        "AT+CIPCLOSE" 
     #define AT_CMD_SHUT         "AT+CIPSHUT" 
     #define AT_CMD_ECHO_OFF     "ATE0" 
     #define AT_CMD_ECHO_ON      "ATE1" 
     #define AT_CMD_MUX          "AT+CIPMUX" 
     #define AT_CMD_CLASS        "AT+CGCLASS"//set MS type 
     #define AT_CMD_PDP_CONT     "AT+CGDCONT"//configure pdp context
     
    #define  AT_CMD_PDP_ATT        "AT+CGATT"//pdp attach network
     #define AT_CMD_PDP_ACT      "AT+CGACT"//active pdp context 
     #define AT_CMD_CSTT         "AT+CSTT"//start task 
     #define AT_CMD_CIICR        "AT+CIICR"//start gprs connect 
     #define AT_CMD_CIFSR        "AT+CIFSR"//get local ip 
     #define AT_CMD_CIPHEAD      "AT+CIPHEAD" 
     #define AT_CMD_CONN         "AT+CIPSTART" 
     #define AT_CMD_SEND         "AT+CIPSEND" 
     #define AT_CMD_CLOSE        "AT+CIPCLOSE"

    sim900a.h位于 LiteOS/components/net/at_device/gprs_sim900a。

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问