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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
65 #define NBIOT5_CMD_ATI "ATI"
66 #define NBIOT5_CMD_CIMI "AT+CIMI"
67 #define NBIOT5_CMD_CSQ "AT+CSQ"
68 
69 #define NBIOT5_SET_CFUN "AT+CFUN=1"
70 #define NBIOT5_SET_CREG "AT+CREG=2"
71 #define NBIOT5_SET_COPS "AT+COPS=0"
72 #define NBIOT5_SET_CMGF "AT+CMGF=1"
73 
74 #define NBIOT5_CHECK_CGATT "AT+CGATT?"
75 #define NBIOT5_CHECK_CREG "AT+CREG?"
76 
82 #define DRV_BUFFER_SIZE 200
83  // nbiot5_set
85 
100 #define NBIOT5_MAP_MIKROBUS( cfg, mikrobus ) \
101  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
102  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
103  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
104  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
105  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
106  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
107 
108  // nbiot5_map // nbiot5
110 
115 typedef struct
116 {
117  // Output pins
118  digital_out_t wkp;
119  digital_out_t rst;
120  digital_out_t cs;
121  digital_out_t en;
123  // Modules
124  uart_t uart;
126  // Buffers
127  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
128  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
130 } nbiot5_t;
131 
136 typedef struct
137 {
138  // Communication gpio pins
139  pin_name_t rx_pin;
140  pin_name_t tx_pin;
142  // Additional gpio pins
143 
144  pin_name_t wkp;
145  pin_name_t rst;
146  pin_name_t cs;
147  pin_name_t en;
149  // Static variable
150  uint32_t baud_rate;
151  bool uart_blocking;
152  uart_data_bits_t data_bit;
153  uart_parity_t parity_bit;
154  uart_stop_bits_t stop_bit;
156 } nbiot5_cfg_t;
157 
173 void nbiot5_cfg_setup ( nbiot5_cfg_t *cfg );
174 
188 err_t nbiot5_init ( nbiot5_t *ctx, nbiot5_cfg_t *cfg );
189 
203 err_t nbiot5_default_cfg ( nbiot5_t *ctx );
204 
217 err_t nbiot5_generic_write ( nbiot5_t *ctx, char *data_buf, uint16_t len );
218 
231 err_t nbiot5_generic_read ( nbiot5_t *ctx, char *data_buf, uint16_t max_len );
232 
233 
244 void nbiot5_set_wkp ( nbiot5_t *ctx, uint8_t state );
245 
256 void nbiot5_set_en ( nbiot5_t *ctx, uint8_t state );
257 
268 void nbiot5_set_rst ( nbiot5_t *ctx, uint8_t state );
269 
280 void nbiot5_set_cs ( nbiot5_t *ctx, uint8_t state );
281 
293 void nbiot5_send_cmd ( nbiot5_t *ctx, char *cmd );
294 
306 void nbiot5_set_sim_apn ( nbiot5_t *ctx, char *sim_apn );
307 
318 void nbiot5_send_text_message ( nbiot5_t *ctx, char *phone_number, char *message_context );
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 #endif // NBIOT5_H
324  // nbiot5
326 
327 // ------------------------------------------------------------------------ END
nbiot5_generic_write
err_t nbiot5_generic_write(nbiot5_t *ctx, char *data_buf, uint16_t len)
NB IoT 5 data writing function.
nbiot5_generic_read
err_t nbiot5_generic_read(nbiot5_t *ctx, char *data_buf, uint16_t max_len)
NB IoT 5 data reading function.
nbiot5_set_en
void nbiot5_set_en(nbiot5_t *ctx, uint8_t state)
Sets state of the en pin setting.
nbiot5_init
err_t nbiot5_init(nbiot5_t *ctx, nbiot5_cfg_t *cfg)
NB IoT 5 initialization function.
nbiot5_set_wkp
void nbiot5_set_wkp(nbiot5_t *ctx, uint8_t state)
Sets state of the wkp pin setting.
nbiot5_set_sim_apn
void nbiot5_set_sim_apn(nbiot5_t *ctx, char *sim_apn)
Set sim card APN.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
NB IoT 5 driver buffer size.
Definition: nbiot5.h:81
nbiot5_default_cfg
err_t nbiot5_default_cfg(nbiot5_t *ctx)
NB IoT 5 default configuration function.
nbiot5_cfg_t
NB IoT 5 Click configuration object.
Definition: nbiot5.h:135
nbiot5_t
NB IoT 5 Click context object.
Definition: nbiot5.h:114
nbiot5_cfg_setup
void nbiot5_cfg_setup(nbiot5_cfg_t *cfg)
NB IoT 5 configuration object setup function.
nbiot5_send_cmd
void nbiot5_send_cmd(nbiot5_t *ctx, char *cmd)
Send command function.
nbiot5_set_rst
void nbiot5_set_rst(nbiot5_t *ctx, uint8_t state)
Sets state of the rst pin setting.
nbiot5_set_cs
void nbiot5_set_cs(nbiot5_t *ctx, uint8_t state)
Sets state of the cs pin setting.
nbiot5_send_text_message
void nbiot5_send_text_message(nbiot5_t *ctx, char *phone_number, char *message_context)
NB IoT 5 send text message.