nbiot4 2.0.0.0
nbiot4.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 NBIOT4_H
29#define NBIOT4_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 NBIOT4_CMD_AT "AT"
74#define NBIOT4_CMD_ATE1 "ATE1"
75#define NBIOT4_CMD_CFUN "AT+CFUN"
76#define NBIOT4_CMD_CREG "AT+CREG"
77#define NBIOT4_CMD_CEREG "AT+CEREG"
78#define NBIOT4_CMD_CGDCONT "AT+CGDCONT"
79#define NBIOT4_CMD_CSQ "AT+CSQ"
80#define NBIOT4_CMD_COPS "AT+COPS"
81#define NBIOT4_CMD_CMGS "AT+CMGS"
82#define NBIOT4_CMD_CMGF "AT+CMGF"
83#define NBIOT4_CMD_SIMSWAP "AT^SIMSWAP"
84#define NBIOT4_CMD_TRB "AT+TRB"
85#define NBIOT4_CMD_CIPMUX "AT+CIPMUX"
86#define NBIOT4_CMD_CIPSTART "AT+CIPSTART"
87#define NBIOT4_CMD_CIPCLOSE "AT+CIPCLOSE"
88#define NBIOT4_CMD_CIPSEND "AT+CIPSEND"
89#define NBIOT4_CMD_CIPHEAD "AT+CIPHEAD"
90
95#define NBIOT4_RSP_OK "OK"
96#define NBIOT4_RSP_ERROR "ERROR"
97#define NBIOT4_RSP_REBOOTING "REBOOTING"
98
104#define NBIOT4_RX_DRV_BUFFER_SIZE 256
105#define NBIOT4_TX_DRV_BUFFER_SIZE 256
106
107 // nbiot4_set
108
123#define NBIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
124 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
125 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
126 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
127 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
128 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_INT )
129
130 // nbiot4_map
131 // nbiot4
132
137typedef struct
138{
139 // Output pins
140 digital_out_t rst;
141 digital_out_t cs;
143 // Input pins
144 digital_in_t ring;
146 // Modules
147 uart_t uart;
149 // Buffers
150 uint8_t uart_rx_buffer[ NBIOT4_RX_DRV_BUFFER_SIZE ];
151 uint8_t uart_tx_buffer[ NBIOT4_TX_DRV_BUFFER_SIZE ];
153} nbiot4_t;
154
159typedef struct
160{
161 // Communication gpio pins
162 pin_name_t rx_pin;
163 pin_name_t tx_pin;
165 // Additional gpio pins
166 pin_name_t rst;
167 pin_name_t cs;
168 pin_name_t ring;
170 // Static variable
171 uint32_t baud_rate;
173 uart_data_bits_t data_bit;
174 uart_parity_t parity_bit;
175 uart_stop_bits_t stop_bit;
178
192
209
223err_t nbiot4_init ( nbiot4_t *ctx, nbiot4_cfg_t *cfg );
224
237err_t nbiot4_generic_write ( nbiot4_t *ctx, uint8_t *data_in, uint16_t len );
238
251err_t nbiot4_generic_read ( nbiot4_t *ctx, uint8_t *data_out, uint16_t len );
252
262void nbiot4_set_rst_pin ( nbiot4_t *ctx, uint8_t state );
263
273void nbiot4_set_cs_pin ( nbiot4_t *ctx, uint8_t state );
274
284
294void nbiot4_send_cmd ( nbiot4_t *ctx, uint8_t *cmd );
295
306void nbiot4_send_cmd_with_par ( nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
307
317void nbiot4_send_cmd_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
318
328void nbiot4_send_cmd_par_check ( nbiot4_t *ctx, uint8_t *at_cmd_buf );
329
339void nbiot4_set_sim_apn ( nbiot4_t *ctx, uint8_t *sim_apn );
340
351void nbiot4_send_sms_text ( nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
352
366err_t nbiot4_send_sms_pdu ( nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
367
368#ifdef __cplusplus
369}
370#endif
371#endif // NBIOT4_H
372
373 // nbiot4
374
375// ------------------------------------------------------------------------ END
#define NBIOT4_TX_DRV_BUFFER_SIZE
Definition nbiot4.h:105
#define NBIOT4_RX_DRV_BUFFER_SIZE
NB IoT 4 driver buffer size.
Definition nbiot4.h:104
err_t nbiot4_send_sms_pdu(nbiot4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 4 send SMS in PDU mode.
void nbiot4_set_sim_apn(nbiot4_t *ctx, uint8_t *sim_apn)
Set sim card APN.
err_t nbiot4_generic_read(nbiot4_t *ctx, uint8_t *data_out, uint16_t len)
NB IoT 4 data reading function.
void nbiot4_set_cs_pin(nbiot4_t *ctx, uint8_t state)
NB IoT 4 set cs pin function.
void nbiot4_send_sms_text(nbiot4_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 4 send SMS in text mode.
uint8_t nbiot4_get_ring_pin(nbiot4_t *ctx)
NB IoT 4 get ring pin function.
void nbiot4_send_cmd_check(nbiot4_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
void nbiot4_send_cmd_par_check(nbiot4_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
void nbiot4_cfg_setup(nbiot4_cfg_t *cfg)
NB IoT 4 configuration object setup function.
err_t nbiot4_generic_write(nbiot4_t *ctx, uint8_t *data_in, uint16_t len)
NB IoT 4 data writing function.
void nbiot4_send_cmd_with_par(nbiot4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
err_t nbiot4_init(nbiot4_t *ctx, nbiot4_cfg_t *cfg)
NB IoT 4 initialization function.
void nbiot4_send_cmd(nbiot4_t *ctx, uint8_t *cmd)
Send command function.
void nbiot4_set_rst_pin(nbiot4_t *ctx, uint8_t state)
NB IoT 4 set rst pin function.
nbiot4_return_value_t
NB IoT 4 Click return value data.
Definition nbiot4.h:184
@ NBIOT4_ERROR_UNKNOWN
Definition nbiot4.h:189
@ NBIOT4_ERROR_CMD
Definition nbiot4.h:188
@ NBIOT4_OK
Definition nbiot4.h:185
@ NBIOT4_ERROR_TIMEOUT
Definition nbiot4.h:187
@ NBIOT4_ERROR
Definition nbiot4.h:186
NB IoT 4 Click configuration object.
Definition nbiot4.h:160
uint32_t baud_rate
Definition nbiot4.h:171
pin_name_t ring
Definition nbiot4.h:168
bool uart_blocking
Definition nbiot4.h:172
uart_data_bits_t data_bit
Definition nbiot4.h:173
pin_name_t tx_pin
Definition nbiot4.h:163
pin_name_t rx_pin
Definition nbiot4.h:162
uart_stop_bits_t stop_bit
Definition nbiot4.h:175
uart_parity_t parity_bit
Definition nbiot4.h:174
pin_name_t rst
Definition nbiot4.h:166
pin_name_t cs
Definition nbiot4.h:167
NB IoT 4 Click context object.
Definition nbiot4.h:138
digital_out_t cs
Definition nbiot4.h:141
uart_t uart
Definition nbiot4.h:147
digital_out_t rst
Definition nbiot4.h:140
digital_in_t ring
Definition nbiot4.h:144