xbee3 2.1.0.0
xbee3.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 XBEE3_H
29#define XBEE3_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 XBEE3_ENTER_CMD_MODE "+++"
74#define XBEE3_EXIT_CMD_MODE "CN"
75#define XBEE3_FACTORY_RESET "RE"
76#define XBEE3_SET_NODE_IDENTIFIER "NI"
77#define XBEE3_GET_SERIAL_NUMBER "SH,SL"
78#define XBEE3_SET_DEST_ADDR_HIGH "DH"
79#define XBEE3_SET_DEST_ADDR_LOW "DL"
80#define XBEE3_APPLY_CHANGES "AC"
81#define XBEE3_API_MODE "AP"
82#define XBEE3_SAVE_CHANGES "WR"
83#define XBEE3_CMD_AT "AT"
84#define XBEE3_DELIMITER ","
85#define XBEE3_CARRIAGE_RETURN "\r"
86
91#define XBEE3_MODE_TRANSPARENT 0
92#define XBEE3_MODE_API_WITHOUT_ESC 1
93#define XBEE3_MODE_API_WITH_ESC 2
94
99#define XBEE3_BROADCAST_DEST_ADDRESS_HIGH "00000000"
100#define XBEE3_BROADCAST_DEST_ADDRESS_LOW "0000FFFF"
101
106#define XBEE3_RSP_OK "OK"
107#define XBEE3_RSP_ERROR "ERROR"
108
114#define DRV_BUFFER_SIZE 200
115
116 // xbee3_cmd
117
132#define XBEE3_MAP_MIKROBUS( cfg, mikrobus ) \
133 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
134 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
135 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_AN ); \
136 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
137 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
138 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
139 cfg.att_dtr = MIKROBUS( mikrobus, MIKROBUS_INT );
140
141 // xbee3_map
142 // xbee3
143
148typedef struct
149{
150 // Output pins
151 digital_out_t rts;
152 digital_out_t rst;
153 digital_out_t cs;
155 // Input pins
156 digital_in_t cts;
157 digital_in_t att_dtr;
159 // Modules
160 uart_t uart;
162 // Buffers
163 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
164 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
166} xbee3_t;
167
172typedef struct
173{
174 // Communication gpio pins
175 pin_name_t rx_pin;
176 pin_name_t tx_pin;
178 // Additional gpio pins
179 pin_name_t rts;
180 pin_name_t rst;
181 pin_name_t cs;
182 pin_name_t cts;
183 pin_name_t att_dtr;
185 // Static variable
186 uint32_t baud_rate;
188 uart_data_bits_t data_bit;
189 uart_parity_t parity_bit;
190 uart_stop_bits_t stop_bit;
193
198typedef enum
199{
201 XBEE3_ERROR = -1
202
204
221
235err_t xbee3_init ( xbee3_t *ctx, xbee3_cfg_t *cfg );
236
249err_t xbee3_generic_write ( xbee3_t *ctx, char *data_in, uint16_t len );
250
263err_t xbee3_generic_read ( xbee3_t *ctx, char *data_out, uint16_t len );
264
274void xbee3_set_rts_pin ( xbee3_t *ctx, uint8_t state );
275
285void xbee3_set_rst_pin ( xbee3_t *ctx, uint8_t state );
286
296void xbee3_set_cs_pin ( xbee3_t *ctx, uint8_t state );
297
306uint8_t xbee3_get_cts_pin ( xbee3_t *ctx );
307
318
330err_t xbee3_write_command ( xbee3_t *ctx, char *data_buf );
331
341
353
365
377
389
401err_t xbee3_set_device_name ( xbee3_t *ctx, char *dev_name );
402
415err_t xbee3_set_destination_address ( xbee3_t *ctx, char *dest_addr_high, char *dest_addr_low );
416
430err_t xbee3_set_api_mode ( xbee3_t *ctx, uint8_t api_mode );
431
443
455
456#ifdef __cplusplus
457}
458#endif
459#endif // XBEE3_H
460
461 // xbee3
462
463// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
XBEE 3 driver buffer size.
Definition xbee3.h:114
err_t xbee3_init(xbee3_t *ctx, xbee3_cfg_t *cfg)
XBEE 3 initialization function.
err_t xbee3_generic_read(xbee3_t *ctx, char *data_out, uint16_t len)
XBEE 3 data reading function.
void xbee3_hw_reset(xbee3_t *ctx)
XBEE 3 hw reset function.
void xbee3_set_cs_pin(xbee3_t *ctx, uint8_t state)
XBEE 3 set cs pin function.
void xbee3_set_rts_pin(xbee3_t *ctx, uint8_t state)
XBEE 3 set rts pin function.
err_t xbee3_set_api_mode(xbee3_t *ctx, uint8_t api_mode)
XBEE 3 set api mode function.
err_t xbee3_generic_write(xbee3_t *ctx, char *data_in, uint16_t len)
XBEE 3 data writing function.
uint8_t xbee3_get_att_dtr_pin(xbee3_t *ctx)
XBEE 3 get att_dtr pin function.
err_t xbee3_write_command(xbee3_t *ctx, char *data_buf)
XBEE 3 write command function.
err_t xbee3_exit_command_mode(xbee3_t *ctx)
XBEE 3 exit command mode function.
err_t xbee3_set_device_name(xbee3_t *ctx, char *dev_name)
XBEE 3 set device name function.
err_t xbee3_save_changes(xbee3_t *ctx)
XBEE 3 save changes function.
void xbee3_cfg_setup(xbee3_cfg_t *cfg)
XBEE 3 configuration object setup function.
void xbee3_set_rst_pin(xbee3_t *ctx, uint8_t state)
XBEE 3 set rst pin function.
uint8_t xbee3_get_cts_pin(xbee3_t *ctx)
XBEE 3 get cts pin function.
err_t xbee3_get_serial_number(xbee3_t *ctx)
XBEE 3 get serial number function.
err_t xbee3_set_destination_address(xbee3_t *ctx, char *dest_addr_high, char *dest_addr_low)
XBEE 3 set destination address function.
err_t xbee3_enter_command_mode(xbee3_t *ctx)
XBEE 3 enter command mode function.
err_t xbee3_apply_changes(xbee3_t *ctx)
XBEE 3 apply changes function.
err_t xbee3_factory_reset(xbee3_t *ctx)
XBEE 3 factory reset function.
XBEE 3 Click configuration object.
Definition xbee3.h:173
pin_name_t rts
Definition xbee3.h:179
uint32_t baud_rate
Definition xbee3.h:186
pin_name_t att_dtr
Definition xbee3.h:183
pin_name_t cts
Definition xbee3.h:182
bool uart_blocking
Definition xbee3.h:187
uart_data_bits_t data_bit
Definition xbee3.h:188
pin_name_t tx_pin
Definition xbee3.h:176
pin_name_t rx_pin
Definition xbee3.h:175
uart_stop_bits_t stop_bit
Definition xbee3.h:190
uart_parity_t parity_bit
Definition xbee3.h:189
pin_name_t rst
Definition xbee3.h:180
pin_name_t cs
Definition xbee3.h:181
XBEE 3 Click context object.
Definition xbee3.h:149
digital_out_t cs
Definition xbee3.h:153
digital_in_t att_dtr
Definition xbee3.h:157
digital_out_t rts
Definition xbee3.h:151
uart_t uart
Definition xbee3.h:160
digital_in_t cts
Definition xbee3.h:156
digital_out_t rst
Definition xbee3.h:152
xbee3_return_value_t
XBEE 3 Click return value data.
Definition xbee3.h:199
@ XBEE3_ERROR
Definition xbee3.h:201
@ XBEE3_OK
Definition xbee3.h:200