@@ -111,31 +111,36 @@ nsapi_error_t QUECTEL_BG96::hard_power_on()
111
111
112
112
nsapi_error_t QUECTEL_BG96::soft_power_on ()
113
113
{
114
- if (_rst.is_connected ()) {
115
- tr_info (" Reset modem" );
116
- _rst = !_active_high;
117
- ThisThread::sleep_for (100 );
118
- _rst = _active_high;
119
- ThisThread::sleep_for (150 + 460 ); // RESET_N timeout from BG96_Hardware_Design_V1.1
120
- _rst = !_active_high;
121
- ThisThread::sleep_for (500 );
114
+ if (!_rst.is_connected ()) {
115
+ return NSAPI_ERROR_OK;
116
+ }
122
117
123
- // wait for RDY
124
- _at->lock ();
125
- _at->set_at_timeout (10 * 1000 );
126
- _at->resp_start ();
127
- _at->set_stop_tag (" RDY" );
128
- bool rdy = _at->consume_to_stop_tag ();
129
- _at->set_stop_tag (OK);
130
- _at->restore_at_timeout ();
131
- _at->unlock ();
118
+ tr_info (" Reset modem" );
119
+ _rst = !_active_high;
120
+ ThisThread::sleep_for (100 );
121
+ _rst = _active_high;
122
+ ThisThread::sleep_for (150 + 460 ); // RESET_N timeout from BG96_Hardware_Design_V1.1
123
+ _rst = !_active_high;
124
+ ThisThread::sleep_for (500 );
132
125
133
- if (!rdy) {
134
- return NSAPI_ERROR_DEVICE_ERROR;
135
- }
126
+ // wait for RDY
127
+ _at->lock ();
128
+ _at->set_at_timeout (10 * 1000 );
129
+ _at->resp_start ();
130
+ _at->set_stop_tag (" RDY" );
131
+ bool rdy = _at->consume_to_stop_tag ();
132
+ _at->set_stop_tag (OK);
133
+ _at->restore_at_timeout ();
134
+
135
+ if (!rdy) {
136
+ // check if modem was silently powered on
137
+ _at->clear_error ();
138
+ _at->set_at_timeout (100 );
139
+ _at->cmd_start (" AT" );
140
+ _at->cmd_stop_read_resp ();
141
+ _at->restore_at_timeout ();
136
142
}
137
-
138
- return NSAPI_ERROR_OK;
143
+ return _at->unlock_return_error ();
139
144
}
140
145
141
146
nsapi_error_t QUECTEL_BG96::hard_power_off ()
@@ -162,26 +167,22 @@ nsapi_error_t QUECTEL_BG96::init()
162
167
_at->cmd_start (" AT+CMEE=1" ); // verbose responses
163
168
_at->cmd_stop_read_resp ();
164
169
165
- if (_at->get_last_error () == NSAPI_ERROR_OK) {
166
- do {
167
- _at->cmd_start (" AT+CFUN=1" ); // set full functionality
168
- _at->cmd_stop_read_resp ();
169
-
170
- // CFUN executed ok
171
- if (_at->get_last_error () != NSAPI_ERROR_OK) {
172
- // wait some time that modem gets ready for CFUN command, and try again
173
- retry++;
174
- _at->flush ();
175
- ThisThread::sleep_for (64 ); // experimental value
176
- } else {
177
- // yes continue
178
- break ;
179
- }
180
-
181
- /* code */
182
- } while ((retry < 3 ));
170
+ if (_at->get_last_error () != NSAPI_ERROR_OK) {
171
+ return _at->unlock_return_error ();
183
172
}
184
173
174
+ do {
175
+ _at->clear_error ();
176
+ _at->cmd_start (" AT+CFUN=1" ); // set full functionality
177
+ _at->cmd_stop_read_resp ();
178
+ if (_at->get_last_error () == NSAPI_ERROR_OK) {
179
+ break ;
180
+ }
181
+ // wait some time that modem gets ready for CFUN command, and try again
182
+ retry++;
183
+ ThisThread::sleep_for (64 ); // experimental value
184
+ } while (retry < 3 );
185
+
185
186
return _at->unlock_return_error ();
186
187
}
187
188
0 commit comments