nbiot2 2.1.0.0
nbiot2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef NBIOT2_H
29#define NBIOT2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define NBIOT2_CMD_AT "AT"
74#define NBIOT2_CMD_ATI "ATI"
75#define NBIOT2_CMD_CGMR "AT+CGMR"
76#define NBIOT2_CMD_CFUN "AT+CFUN"
77#define NBIOT2_CMD_CREG "AT+CREG"
78#define NBIOT2_CMD_CEREG "AT+CEREG"
79#define NBIOT2_CMD_CGDCONT "AT+CGDCONT"
80#define NBIOT2_CMD_CIMI "AT+CIMI"
81#define NBIOT2_CMD_CGATT "AT+CGATT"
82#define NBIOT2_CMD_CSQ "AT+CSQ"
83#define NBIOT2_CMD_CESQ "AT+CESQ"
84#define NBIOT2_CMD_COPS "AT+COPS"
85#define NBIOT2_CMD_CSCON "AT+CSCON"
86#define NBIOT2_CMD_CMEE "AT+CMEE"
87#define NBIOT2_CMD_CMGS "AT+CMGS"
88#define NBIOT2_CMD_CGACT "AT+CGACT"
89#define NBIOT2_CMD_URAT "AT+URAT"
90#define NBIOT2_CMD_UBANDMASK "AT+UBANDMASK"
91#define NBIOT2_CMD_URATCONF "AT+URATCONF"
92#define NBIOT2_CMD_UAUTHREQ "AT+UAUTHREQ"
93#define NBIOT2_CMD_UUICC "AT+UUICC"
94#define NBIOT2_CMD_UCGED "AT+UCGED"
95#define NBIOT2_CMD_UCELLINFO "AT+UCELLINFO"
96#define NBIOT2_CMD_UANTR "AT+UANTR"
97#define NBIOT2_CMD_CMGF "AT+CMGF"
98#define NBIOT2_CMD_QSPCHSC "AT+QSPCHSC"
99#define NBIOT2_CMD_CPSMS "AT+CPSMS"
100#define NBIOT2_CMD_QRST "AT+QRST"
101#define NBIOT2_CMD_QBAND "AT+QBAND"
102#define NBIOT2_CMD_QNBIOTEVENT "AT+QNBIOTEVENT"
103#define NBIOT2_CMD_SM "AT+SM"
104#define NBIOT2_CMD_QSCLK "AT+QSCLK"
105#define NBIOT2_CMD_QIOPEN "AT+QIOPEN"
106#define NBIOT2_CMD_QISEND "AT+QISEND"
107#define NBIOT2_CMD_QIRD "AT+QIRD"
108#define NBIOT2_CMD_QICLOSE "AT+QICLOSE"
109
114#define NBIOT2_PIN_STATE_HIGH 0x01
115#define NBIOT2_PIN_STATE_LOW 0x00
116
121#define NBIOT2_RSP_OK "OK"
122#define NBIOT2_RSP_ERROR "ERROR"
123
129#define NBIOT2_TX_DRV_BUFFER_SIZE 100
130#define NBIOT2_RX_DRV_BUFFER_SIZE 300
131
132 // nbiot2_cmd
133
148#define NBIOT2_MAP_MIKROBUS( cfg, mikrobus ) \
149 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
150 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
151 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
152 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_INT );
153
154 // nbiot2_map
155 // nbiot2
156
161typedef struct
162{
163 // Output pins
164 digital_out_t rst;
165 digital_out_t wup;
167 // Modules
168 uart_t uart;
170 // Buffers
171 char uart_rx_buffer[ NBIOT2_RX_DRV_BUFFER_SIZE ];
172 char uart_tx_buffer[ NBIOT2_TX_DRV_BUFFER_SIZE ];
174} nbiot2_t;
175
180typedef struct
181{
182 // Communication gpio pins
183 pin_name_t rx_pin;
184 pin_name_t tx_pin;
186 // Additional gpio pins
187 pin_name_t rst;
188 pin_name_t wup;
190 // Static variable
191 uint32_t baud_rate;
193 uart_data_bits_t data_bit;
194 uart_parity_t parity_bit;
195 uart_stop_bits_t stop_bit;
198
211
228
242err_t nbiot2_init ( nbiot2_t *ctx, nbiot2_cfg_t *cfg );
243
256err_t nbiot2_generic_write ( nbiot2_t *ctx, char *data_in, uint16_t len );
257
270err_t nbiot2_generic_read ( nbiot2_t *ctx, char *data_out, uint16_t len );
271
281void nbiot2_set_rst_pin_state ( nbiot2_t *ctx, uint8_t state );
282
292void nbiot2_set_wup_pin_state ( nbiot2_t *ctx, uint8_t state );
293
303
313void nbiot2_send_cmd ( nbiot2_t *ctx, char *cmd );
314
325void nbiot2_send_cmd_with_parameter ( nbiot2_t *ctx, char *at_cmd_buf, char *param_buf );
326
336void nbiot2_send_cmd_check ( nbiot2_t *ctx, char *at_cmd_buf );
337
347void nbiot2_send_cmd_parameter_check ( nbiot2_t *ctx, char *at_cmd_buf );
348
358void nbiot2_set_apn( nbiot2_t *ctx, char *apn );
359
370void nbiot2_send_sms_text_mode ( nbiot2_t *ctx, char *phone_number, char *message_context );
371
385err_t nbiot2_send_sms_pdu ( nbiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text );
386
387#ifdef __cplusplus
388}
389#endif
390#endif // NBIOT2_H
391
392 // nbiot2
393
394// ------------------------------------------------------------------------ END
#define NBIOT2_RX_DRV_BUFFER_SIZE
Definition nbiot2.h:130
#define NBIOT2_TX_DRV_BUFFER_SIZE
NB IoT 2 driver buffer size.
Definition nbiot2.h:129
void nbiot2_send_cmd_check(nbiot2_t *ctx, char *at_cmd_buf)
NB IoT 2 check the sent command.
err_t nbiot2_send_sms_pdu(nbiot2_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
NB IoT 2 send SMS in PDU mode.
void nbiot2_set_rst_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the RST pin.
void nbiot2_send_cmd(nbiot2_t *ctx, char *cmd)
NB IoT 2 send command function.
void nbiot2_hw_reset(nbiot2_t *ctx)
NB IoT 2 hardware reset function.
void nbiot2_send_cmd_with_parameter(nbiot2_t *ctx, char *at_cmd_buf, char *param_buf)
NB IoT 2 send command function with parameter.
void nbiot2_send_sms_text_mode(nbiot2_t *ctx, char *phone_number, char *message_context)
NB IoT 2 send SMS in text mode.
void nbiot2_cfg_setup(nbiot2_cfg_t *cfg)
NB IoT 2 configuration object setup function.
void nbiot2_set_wup_pin_state(nbiot2_t *ctx, uint8_t state)
NB IoT 2 sets state of the WUP pin.
void nbiot2_send_cmd_parameter_check(nbiot2_t *ctx, char *at_cmd_buf)
NB IoT 2 check the command parameters.
void nbiot2_set_apn(nbiot2_t *ctx, char *apn)
NB IoT 2 set sim card APN.
err_t nbiot2_generic_write(nbiot2_t *ctx, char *data_in, uint16_t len)
NB IoT 2 data writing function.
err_t nbiot2_generic_read(nbiot2_t *ctx, char *data_out, uint16_t len)
NB IoT 2 data reading function.
err_t nbiot2_init(nbiot2_t *ctx, nbiot2_cfg_t *cfg)
NB IoT 2 initialization function.
nbiot2_return_value_t
NB IoT 2 Click return value data.
Definition nbiot2.h:204
@ NBIOT2_ERROR_OVERFLOW
Definition nbiot2.h:207
@ NBIOT2_OK
Definition nbiot2.h:205
@ NBIOT2_ERROR_TIMEOUT
Definition nbiot2.h:208
@ NBIOT2_ERROR
Definition nbiot2.h:206
NB IoT 2 Click configuration object.
Definition nbiot2.h:181
uint32_t baud_rate
Definition nbiot2.h:191
pin_name_t wup
Definition nbiot2.h:188
bool uart_blocking
Definition nbiot2.h:192
uart_data_bits_t data_bit
Definition nbiot2.h:193
pin_name_t tx_pin
Definition nbiot2.h:184
pin_name_t rx_pin
Definition nbiot2.h:183
uart_stop_bits_t stop_bit
Definition nbiot2.h:195
uart_parity_t parity_bit
Definition nbiot2.h:194
pin_name_t rst
Definition nbiot2.h:187
NB IoT 2 Click context object.
Definition nbiot2.h:162
uart_t uart
Definition nbiot2.h:168
digital_out_t wup
Definition nbiot2.h:165
digital_out_t rst
Definition nbiot2.h:164