nbiot5 2.0.0.0
nbiot5.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 NBIOT5_H
29#define NBIOT5_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 NBIOT5_CMD_AT "AT"
74#define NBIOT5_CMD_CFUN "AT+CFUN"
75#define NBIOT5_CMD_CEREG "AT+CEREG"
76#define NBIOT5_CMD_CGDCONT "AT+CGDCONT"
77#define NBIOT5_CMD_CSQ "AT+CSQ"
78#define NBIOT5_CMD_COPS "AT+COPS"
79#define NBIOT5_CMD_CMGS "AT+CMGS"
80#define NBIOT5_CMD_CMGF "AT+CMGF"
81#define NBIOT5_CMD_ESOC "AT+ESOC"
82#define NBIOT5_CMD_ESOCON "AT+ESOCON"
83#define NBIOT5_CMD_ESOSEND "AT+ESOSEND"
84#define NBIOT5_CMD_ESOCL "AT+ESOCL"
85
90#define NBIOT5_RSP_OK "OK"
91#define NBIOT5_RSP_ERROR "ERROR"
92
98#define NBIOT5_RX_DRV_BUFFER_SIZE 256
99#define NBIOT5_TX_DRV_BUFFER_SIZE 256
100
101 // nbiot5_set
102
117#define NBIOT5_MAP_MIKROBUS( cfg, mikrobus ) \
118 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
119 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
120 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_AN ); \
121 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
122 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
123 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
124
125 // nbiot5_map
126 // nbiot5
127
132typedef struct
133{
134 // Output pins
135 digital_out_t rst;
136 digital_out_t cs;
137 digital_out_t wup;
138 digital_out_t en;
140 // Modules
141 uart_t uart;
143 // Buffers
144 uint8_t uart_rx_buffer[ NBIOT5_RX_DRV_BUFFER_SIZE ];
145 uint8_t uart_tx_buffer[ NBIOT5_TX_DRV_BUFFER_SIZE ];
147} nbiot5_t;
148
153typedef struct
154{
155 // Communication gpio pins
156 pin_name_t rx_pin;
157 pin_name_t tx_pin;
159 // Additional gpio pins
160 pin_name_t rst;
161 pin_name_t cs;
162 pin_name_t wup;
163 pin_name_t en;
165 // Static variable
166 uint32_t baud_rate;
168 uart_data_bits_t data_bit;
169 uart_parity_t parity_bit;
170 uart_stop_bits_t stop_bit;
173
187
204
218err_t nbiot5_init ( nbiot5_t *ctx, nbiot5_cfg_t *cfg );
219
232err_t nbiot5_generic_write ( nbiot5_t *ctx, uint8_t *data_in, uint16_t len );
233
246err_t nbiot5_generic_read ( nbiot5_t *ctx, uint8_t *data_out, uint16_t len );
247
257void nbiot5_set_rst_pin ( nbiot5_t *ctx, uint8_t state );
258
268void nbiot5_set_cs_pin ( nbiot5_t *ctx, uint8_t state );
269
279void nbiot5_set_wup_pin ( nbiot5_t *ctx, uint8_t state );
280
290void nbiot5_set_en_pin ( nbiot5_t *ctx, uint8_t state );
291
301void nbiot5_send_cmd ( nbiot5_t *ctx, uint8_t *cmd );
302
313void nbiot5_send_cmd_with_par ( nbiot5_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
314
324void nbiot5_send_cmd_check ( nbiot5_t *ctx, uint8_t *at_cmd_buf );
325
335void nbiot5_send_cmd_par_check ( nbiot5_t *ctx, uint8_t *at_cmd_buf );
336
346void nbiot5_set_sim_apn ( nbiot5_t *ctx, uint8_t *sim_apn );
347
358void nbiot5_send_sms_text ( nbiot5_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
359
373err_t nbiot5_send_sms_pdu ( nbiot5_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
374
375#ifdef __cplusplus
376}
377#endif
378#endif // NBIOT5_H
379
380 // nbiot5
381
382// ------------------------------------------------------------------------ END
#define NBIOT5_TX_DRV_BUFFER_SIZE
Definition nbiot5.h:99
#define NBIOT5_RX_DRV_BUFFER_SIZE
NB IoT 5 driver buffer size.
Definition nbiot5.h:98
err_t nbiot5_send_sms_pdu(nbiot5_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 5 send SMS in PDU mode.
void nbiot5_send_cmd_with_par(nbiot5_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
void nbiot5_set_en_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set en pin function.
void nbiot5_set_wup_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set wup pin function.
void nbiot5_set_rst_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set rst pin function.
void nbiot5_send_sms_text(nbiot5_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
NB IoT 5 send SMS in text mode.
void nbiot5_send_cmd(nbiot5_t *ctx, uint8_t *cmd)
Send command function.
err_t nbiot5_init(nbiot5_t *ctx, nbiot5_cfg_t *cfg)
NB IoT 5 initialization function.
void nbiot5_send_cmd_check(nbiot5_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
err_t nbiot5_generic_read(nbiot5_t *ctx, uint8_t *data_out, uint16_t len)
NB IoT 5 data reading function.
void nbiot5_cfg_setup(nbiot5_cfg_t *cfg)
NB IoT 5 configuration object setup function.
void nbiot5_set_sim_apn(nbiot5_t *ctx, uint8_t *sim_apn)
Set sim card APN.
void nbiot5_set_cs_pin(nbiot5_t *ctx, uint8_t state)
NB IoT 5 set cs pin function.
void nbiot5_send_cmd_par_check(nbiot5_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
err_t nbiot5_generic_write(nbiot5_t *ctx, uint8_t *data_in, uint16_t len)
NB IoT 5 data writing function.
nbiot5_return_value_t
NB IoT 5 Click return value data.
Definition nbiot5.h:179
@ NBIOT5_ERROR_UNKNOWN
Definition nbiot5.h:184
@ NBIOT5_ERROR
Definition nbiot5.h:181
@ NBIOT5_OK
Definition nbiot5.h:180
@ NBIOT5_ERROR_CMD
Definition nbiot5.h:183
@ NBIOT5_ERROR_TIMEOUT
Definition nbiot5.h:182
NB IoT 5 Click configuration object.
Definition nbiot5.h:154
uint32_t baud_rate
Definition nbiot5.h:166
pin_name_t wup
Definition nbiot5.h:162
bool uart_blocking
Definition nbiot5.h:167
uart_data_bits_t data_bit
Definition nbiot5.h:168
pin_name_t tx_pin
Definition nbiot5.h:157
pin_name_t rx_pin
Definition nbiot5.h:156
uart_stop_bits_t stop_bit
Definition nbiot5.h:170
pin_name_t en
Definition nbiot5.h:163
uart_parity_t parity_bit
Definition nbiot5.h:169
pin_name_t rst
Definition nbiot5.h:160
pin_name_t cs
Definition nbiot5.h:161
NB IoT 5 Click context object.
Definition nbiot5.h:133
digital_out_t cs
Definition nbiot5.h:136
uart_t uart
Definition nbiot5.h:141
digital_out_t wup
Definition nbiot5.h:137
digital_out_t en
Definition nbiot5.h:138
digital_out_t rst
Definition nbiot5.h:135