mbusrf2 2.1.0.0
mbusrf2.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 MBUSRF2_H
29#define MBUSRF2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38
59#define MBUSRF2_CMD_SFD 0xFF
60#define MBUSRF2_CMD_DATA_REQ 0x00
61#define MBUSRF2_CMD_DATA_IND 0x03
62#define MBUSRF2_CMD_SET_MODE_REQ 0x04
63#define MBUSRF2_CMD_RESET_REQ 0x05
64#define MBUSRF2_CMD_SET_REQ 0x09
65#define MBUSRF2_CMD_SETUARTSPEED_REQ 0x10
66#define MBUSRF2_CMD_FACTORYRESET_REQ 0x11
67#define MBUSRF2_CMD_GET_REQ 0x0A
68#define MBUSRF2_CMD_SERIALNO_REQ 0x0B
69#define MBUSRF2_CMD_FWV_REQ 0x0C
70#define MBUSRF2_CMD_RSSI_REQ 0x0D
71#define MBUSRF2_CMD_SET_AES_KEY_REQ 0x50
72#define MBUSRF2_CMD_CLR_AES_KEY_REQ 0x51
73#define MBUSRF2_CMD_GET_AES_KEY_REQ 0x52
74#define MBUSRF2_CMD_RESPONSE 0x80
75
81#define MBUSRF2_TX_DRV_BUFFER_SIZE 100
82#define MBUSRF2_RX_DRV_BUFFER_SIZE 300
83 // mbusrf2_cmd
85
100#define MBUSRF2_MAP_MIKROBUS( cfg, mikrobus ) \
101 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
102 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
103 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
104 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
105 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
106 // mbusrf2_map // mbusrf2
109
114typedef struct
115{
116 // Output pins
117 digital_out_t rst;
118 digital_out_t cts;
120 // Input pins
121 digital_in_t rts;
123 // Modules
124 uart_t uart;
126 // Buffers
127 uint8_t uart_rx_buffer[ MBUSRF2_RX_DRV_BUFFER_SIZE ];
128 uint8_t uart_tx_buffer[ MBUSRF2_TX_DRV_BUFFER_SIZE ];
130} mbusrf2_t;
131
136typedef struct
137{
138 // Communication gpio pins
139 pin_name_t rx_pin;
140 pin_name_t tx_pin;
142 // Additional gpio pins
143 pin_name_t rst;
144 pin_name_t cts;
145 pin_name_t rts;
147 // Static variable
148 uint32_t baud_rate;
150 uart_data_bits_t data_bit;
151 uart_parity_t parity_bit;
152 uart_stop_bits_t stop_bit;
155
160typedef enum
161{
165
167
184
199
212err_t mbusrf2_generic_write ( mbusrf2_t *ctx, uint8_t *data_in, uint16_t len );
213
226err_t mbusrf2_generic_read ( mbusrf2_t *ctx, uint8_t *data_out, uint16_t len );
227
237void mbusrf2_set_rst_pin ( mbusrf2_t *ctx, uint8_t pin_state );
238
252err_t mbusrf2_send_command ( mbusrf2_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
253
266err_t mbusrf2_send_data ( mbusrf2_t *ctx, uint8_t *data_in, uint8_t len );
267
268#ifdef __cplusplus
269}
270#endif
271#endif // MBUSRF2_H
272 // mbusrf2
274
275// ------------------------------------------------------------------------ END
#define MBUSRF2_RX_DRV_BUFFER_SIZE
Definition: mbusrf2.h:82
#define MBUSRF2_TX_DRV_BUFFER_SIZE
M-BUS RF 2 driver buffer size.
Definition: mbusrf2.h:81
err_t mbusrf2_send_command(mbusrf2_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
M-BUS RF 2 send command function.
err_t mbusrf2_send_data(mbusrf2_t *ctx, uint8_t *data_in, uint8_t len)
M-BUS RF 2 send data function.
err_t mbusrf2_generic_read(mbusrf2_t *ctx, uint8_t *data_out, uint16_t len)
M-BUS RF 2 data reading function.
err_t mbusrf2_generic_write(mbusrf2_t *ctx, uint8_t *data_in, uint16_t len)
M-BUS RF 2 data writing function.
void mbusrf2_cfg_setup(mbusrf2_cfg_t *cfg)
M-BUS RF 2 configuration object setup function.
void mbusrf2_set_rst_pin(mbusrf2_t *ctx, uint8_t pin_state)
M-BUS RF 2 set reset pin function.
err_t mbusrf2_init(mbusrf2_t *ctx, mbusrf2_cfg_t *cfg)
M-BUS RF 2 initialization function.
mbusrf2_return_value_t
M-BUS RF 2 Click return value data.
Definition: mbusrf2.h:161
@ MBUSRF2_ERROR
Definition: mbusrf2.h:163
@ MBUSRF2_ERROR_TIMEOUT
Definition: mbusrf2.h:164
@ MBUSRF2_OK
Definition: mbusrf2.h:162
M-BUS RF 2 Click configuration object.
Definition: mbusrf2.h:137
pin_name_t rts
Definition: mbusrf2.h:145
uint32_t baud_rate
Definition: mbusrf2.h:148
pin_name_t cts
Definition: mbusrf2.h:144
bool uart_blocking
Definition: mbusrf2.h:149
uart_data_bits_t data_bit
Definition: mbusrf2.h:150
pin_name_t tx_pin
Definition: mbusrf2.h:140
pin_name_t rx_pin
Definition: mbusrf2.h:139
uart_stop_bits_t stop_bit
Definition: mbusrf2.h:152
uart_parity_t parity_bit
Definition: mbusrf2.h:151
pin_name_t rst
Definition: mbusrf2.h:143
M-BUS RF 2 Click context object.
Definition: mbusrf2.h:115
uart_t uart
Definition: mbusrf2.h:124
digital_in_t rts
Definition: mbusrf2.h:121
digital_out_t rst
Definition: mbusrf2.h:117
digital_out_t cts
Definition: mbusrf2.h:118