diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 3ad93a3d09..d9e2de23dd 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -78,27 +78,30 @@ void QUECTEL_BG96::set_ready_cb(Callback callback) nsapi_error_t QUECTEL_BG96::hard_power_on() { - DigitalOut ModemResetIn (MBED_CONF_QUECTEL_BG96_POWER); -printf("QUECTEL_BG96::hard_power_on\n"); + DigitalOut ModemResetIn (MBED_CONF_QUECTEL_BG96_PWR); + wait_ms(250); ModemResetIn = 0; wait_ms(250); ModemResetIn = 1; wait_ms(500); - wait_ms(250); + return NSAPI_ERROR_OK; } + nsapi_error_t QUECTEL_BG96::soft_power_on() { - DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_RESET); -printf("QUECTEL_BG96::soft_power_on\n"); + // turn moden on + DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_RST); + ModemPwrkey = 0; wait_ms(100); ModemPwrkey = 1; wait_ms(500); ModemPwrkey = 0; wait_ms(500); -printf("wait for RDY\n"); + + // wait for RDY _at->lock(); _at->set_at_timeout(60000); _at->resp_start(); @@ -106,21 +109,66 @@ printf("wait for RDY\n"); bool rdy = _at->consume_to_stop_tag(); _at->set_stop_tag(OK); _at->unlock(); + if (!rdy) { return NSAPI_ERROR_DEVICE_ERROR; } + return NSAPI_ERROR_OK; } + nsapi_error_t QUECTEL_BG96::hard_power_off() { - DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_POWER); -printf("QUECTEL_BG96::hard_power_off\n"); + // turn moden off + DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_PWR); + ModemPwrkey = 1; wait_ms(250); ModemPwrkey = 0; + return NSAPI_ERROR_OK; } + +nsapi_error_t QUECTEL_BG96::init() +{ + int retry = 0; + + _at->lock(); + _at->flush(); + _at->cmd_start("ATE0"); // echo off + _at->cmd_stop_read_resp(); + + _at->cmd_start("AT+CMEE=1"); // verbose responses + _at->cmd_stop_read_resp(); + + if (_at->get_last_error() != NSAPI_ERROR_OK) + { + do + { + _at->cmd_start("AT+CFUN=1"); // set full functionality + _at->cmd_stop_read_resp(); + + // CFUN executed ok + if (_at->get_last_error() != NSAPI_ERROR_OK) + { + // wait some time that modem gets ready for CFUN command, and try again + retry++; + _at->flush(); + wait_ms(64); + } + else + { + // yes continue + break; + } + + /* code */ + } while ( (retry < 3) ); + } + return _at->unlock_return_error(); +} + #if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 2eaf197c49..3744308f19 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -43,6 +43,7 @@ protected: // AT_CellularDevice virtual nsapi_error_t hard_power_on(); virtual nsapi_error_t hard_power_off(); virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t init(); public: void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json index 01c7555612..d72b2fba46 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json +++ b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json @@ -17,6 +17,18 @@ "help": "CTS pin for serial connection", "value": null }, + "pwr": { + "help": "Power control pin", + "value": null + }, + "rst": { + "help": "Reset control pin", + "value": null + }, + "polarity": { + "help": "Pin polarity, 1 = Active high, 0 = Active low", + "value": null + }, "baudrate" : { "help": "Serial connection baud rate", "value": 115200 @@ -24,14 +36,6 @@ "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false - }, - "power": { - "help": "Modem's power key.", - "value": null - }, - "reset": { - "help": "Modem's reset key.", - "value": null } } }