xbee2 2.1.0.0
xbee2.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 XBEE2_H
29#define XBEE2_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 XBEE2_ENTER_CMD_MODE "+++"
74#define XBEE2_EXIT_CMD_MODE "CN"
75#define XBEE2_FACTORY_RESET "RE"
76#define XBEE2_SET_NODE_IDENTIFIER "NI"
77#define XBEE2_GET_SERIAL_NUMBER "SH,SL"
78#define XBEE2_SET_DEST_ADDR_HIGH "DH"
79#define XBEE2_SET_DEST_ADDR_LOW "DL"
80#define XBEE2_APPLY_CHANGES "AC"
81#define XBEE2_API_MODE "AP"
82#define XBEE2_DEV_ROLE "CE"
83#define XBEE2_SAVE_CHANGES "WR"
84#define XBEE2_CMD_AT "AT"
85#define XBEE2_DELIMITER ","
86#define XBEE2_CARRIAGE_RETURN "\r"
87
92#define XBEE2_MODE_TRANSPARENT 0
93#define XBEE2_MODE_API_WITHOUT_ESC 1
94#define XBEE2_MODE_API_WITH_ESC 2
95
100#define XBEE2_DEVICE_ROLE_JOIN_NETWORK 0
101#define XBEE2_DEVICE_ROLE_FORM_NETWORK 1
102
107#define XBEE2_BROADCAST_DEST_ADDRESS_HIGH "00000000"
108#define XBEE2_BROADCAST_DEST_ADDRESS_LOW "0000FFFF"
109
114#define XBEE2_RSP_OK "OK"
115#define XBEE2_RSP_ERROR "ERROR"
116
122#define DRV_BUFFER_SIZE 200
123
124 // xbee2_cmd
125
140#define XBEE2_MAP_MIKROBUS( cfg, mikrobus ) \
141 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
142 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
143 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_AN ); \
144 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
145 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
146 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
147 cfg.att_dtr = MIKROBUS( mikrobus, MIKROBUS_INT );
148
149 // xbee2_map
150 // xbee2
151
156typedef struct
157{
158 // Output pins
159 digital_out_t rts;
160 digital_out_t rst;
161 digital_out_t cs;
163 // Input pins
164 digital_in_t cts;
165 digital_in_t att_dtr;
167 // Modules
168 uart_t uart;
170 // Buffers
171 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
172 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
174} xbee2_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 rts;
188 pin_name_t rst;
189 pin_name_t cs;
190 pin_name_t cts;
191 pin_name_t att_dtr;
193 // Static variable
194 uint32_t baud_rate;
196 uart_data_bits_t data_bit;
197 uart_parity_t parity_bit;
198 uart_stop_bits_t stop_bit;
201
206typedef enum
207{
209 XBEE2_ERROR = -1
210
212
229
243err_t xbee2_init ( xbee2_t *ctx, xbee2_cfg_t *cfg );
244
257err_t xbee2_generic_write ( xbee2_t *ctx, char *data_in, uint16_t len );
258
271err_t xbee2_generic_read ( xbee2_t *ctx, char *data_out, uint16_t len );
272
282void xbee2_set_rts_pin ( xbee2_t *ctx, uint8_t state );
283
293void xbee2_set_rst_pin ( xbee2_t *ctx, uint8_t state );
294
304void xbee2_set_cs_pin ( xbee2_t *ctx, uint8_t state );
305
314uint8_t xbee2_get_cts_pin ( xbee2_t *ctx );
315
326
338err_t xbee2_write_command ( xbee2_t *ctx, char *data_buf );
339
349
361
373
385
397
409err_t xbee2_set_device_name ( xbee2_t *ctx, char *dev_name );
410
423err_t xbee2_set_destination_address ( xbee2_t *ctx, char *dest_addr_high, char *dest_addr_low );
424
438err_t xbee2_set_api_mode ( xbee2_t *ctx, uint8_t api_mode );
439
452err_t xbee2_set_device_role ( xbee2_t *ctx, uint8_t dev_role );
453
465
477
478#ifdef __cplusplus
479}
480#endif
481#endif // XBEE2_H
482
483 // xbee2
484
485// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
XBEE 2 driver buffer size.
Definition xbee2.h:122
void xbee2_set_rts_pin(xbee2_t *ctx, uint8_t state)
XBEE 2 set rts pin function.
err_t xbee2_generic_write(xbee2_t *ctx, char *data_in, uint16_t len)
XBEE 2 data writing function.
err_t xbee2_set_api_mode(xbee2_t *ctx, uint8_t api_mode)
XBEE 2 set api mode function.
err_t xbee2_set_device_role(xbee2_t *ctx, uint8_t dev_role)
XBEE 2 set device role function.
void xbee2_set_cs_pin(xbee2_t *ctx, uint8_t state)
XBEE 2 set cs pin function.
uint8_t xbee2_get_att_dtr_pin(xbee2_t *ctx)
XBEE 2 get att_dtr pin function.
void xbee2_hw_reset(xbee2_t *ctx)
XBEE 2 hw reset function.
err_t xbee2_exit_command_mode(xbee2_t *ctx)
XBEE 2 exit command mode function.
err_t xbee2_set_device_name(xbee2_t *ctx, char *dev_name)
XBEE 2 set device name function.
err_t xbee2_generic_read(xbee2_t *ctx, char *data_out, uint16_t len)
XBEE 2 data reading function.
void xbee2_cfg_setup(xbee2_cfg_t *cfg)
XBEE 2 configuration object setup function.
err_t xbee2_factory_reset(xbee2_t *ctx)
XBEE 2 factory reset function.
err_t xbee2_get_serial_number(xbee2_t *ctx)
XBEE 2 get serial number function.
void xbee2_set_rst_pin(xbee2_t *ctx, uint8_t state)
XBEE 2 set rst pin function.
err_t xbee2_enter_command_mode(xbee2_t *ctx)
XBEE 2 enter command mode function.
err_t xbee2_init(xbee2_t *ctx, xbee2_cfg_t *cfg)
XBEE 2 initialization function.
uint8_t xbee2_get_cts_pin(xbee2_t *ctx)
XBEE 2 get cts pin function.
err_t xbee2_write_command(xbee2_t *ctx, char *data_buf)
XBEE 2 write command function.
err_t xbee2_set_destination_address(xbee2_t *ctx, char *dest_addr_high, char *dest_addr_low)
XBEE 2 set destination address function.
err_t xbee2_apply_changes(xbee2_t *ctx)
XBEE 2 apply changes function.
err_t xbee2_save_changes(xbee2_t *ctx)
XBEE 2 save changes function.
XBEE 2 Click configuration object.
Definition xbee2.h:181
pin_name_t rts
Definition xbee2.h:187
uint32_t baud_rate
Definition xbee2.h:194
pin_name_t att_dtr
Definition xbee2.h:191
pin_name_t cts
Definition xbee2.h:190
bool uart_blocking
Definition xbee2.h:195
uart_data_bits_t data_bit
Definition xbee2.h:196
pin_name_t tx_pin
Definition xbee2.h:184
pin_name_t rx_pin
Definition xbee2.h:183
uart_stop_bits_t stop_bit
Definition xbee2.h:198
uart_parity_t parity_bit
Definition xbee2.h:197
pin_name_t rst
Definition xbee2.h:188
pin_name_t cs
Definition xbee2.h:189
XBEE 2 Click context object.
Definition xbee2.h:157
digital_out_t cs
Definition xbee2.h:161
digital_in_t att_dtr
Definition xbee2.h:165
digital_out_t rts
Definition xbee2.h:159
uart_t uart
Definition xbee2.h:168
digital_in_t cts
Definition xbee2.h:164
digital_out_t rst
Definition xbee2.h:160
xbee2_return_value_t
XBEE 2 Click return value data.
Definition xbee2.h:207
@ XBEE2_ERROR
Definition xbee2.h:209
@ XBEE2_OK
Definition xbee2.h:208