mbusrf3 2.1.0.0
mbusrf3.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 MBUSRF3_H
29#define MBUSRF3_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "mikrosdk_version.h"
36
37#ifdef __GNUC__
38#if mikroSDK_GET_VERSION < 20800ul
39#include "rcu_delays.h"
40#else
41#include "delays.h"
42#endif
43#endif
44
45#include "drv_digital_out.h"
46#include "drv_digital_in.h"
47#include "drv_uart.h"
48
69#define MBUSRF3_CMD_SFD 0xFF
70#define MBUSRF3_CMD_DATA_REQ 0x00
71#define MBUSRF3_CMD_DATA_IND 0x03
72#define MBUSRF3_CMD_SET_MODE_REQ 0x04
73#define MBUSRF3_CMD_RESET_REQ 0x05
74#define MBUSRF3_CMD_SET_REQ 0x09
75#define MBUSRF3_CMD_SETUARTSPEED_REQ 0x10
76#define MBUSRF3_CMD_FACTORYRESET_REQ 0x11
77#define MBUSRF3_CMD_GET_REQ 0x0A
78#define MBUSRF3_CMD_SERIALNO_REQ 0x0B
79#define MBUSRF3_CMD_FWV_REQ 0x0C
80#define MBUSRF3_CMD_RSSI_REQ 0x0D
81#define MBUSRF3_CMD_SET_AES_KEY_REQ 0x50
82#define MBUSRF3_CMD_CLR_AES_KEY_REQ 0x51
83#define MBUSRF3_CMD_GET_AES_KEY_REQ 0x52
84#define MBUSRF3_CMD_RESPONSE 0x80
85
91#define MBUSRF3_TX_DRV_BUFFER_SIZE 100
92#define MBUSRF3_RX_DRV_BUFFER_SIZE 300
93 // mbusrf3_cmd
95
110#define MBUSRF3_MAP_MIKROBUS( cfg, mikrobus ) \
111 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
112 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
113 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
114 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
115 // mbusrf3_map // mbusrf3
118
123typedef struct
124{
125 // Output pins
126 digital_out_t rst;
128 // Input pins
129 digital_in_t rts;
131 // Modules
132 uart_t uart;
134 // Buffers
135 uint8_t uart_rx_buffer[ MBUSRF3_RX_DRV_BUFFER_SIZE ];
136 uint8_t uart_tx_buffer[ MBUSRF3_TX_DRV_BUFFER_SIZE ];
138} mbusrf3_t;
139
144typedef struct
145{
146 // Communication gpio pins
147 pin_name_t rx_pin;
148 pin_name_t tx_pin;
150 // Additional gpio pins
151 pin_name_t rst;
152 pin_name_t rts;
154 // Static variable
155 uint32_t baud_rate;
157 uart_data_bits_t data_bit;
158 uart_parity_t parity_bit;
159 uart_stop_bits_t stop_bit;
162
167typedef enum
168{
172
174
191
206
219err_t mbusrf3_generic_write ( mbusrf3_t *ctx, uint8_t *data_in, uint16_t len );
220
233err_t mbusrf3_generic_read ( mbusrf3_t *ctx, uint8_t *data_out, uint16_t len );
234
244void mbusrf3_set_rst_pin ( mbusrf3_t *ctx, uint8_t pin_state );
245
259err_t mbusrf3_send_command ( mbusrf3_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
260
273err_t mbusrf3_send_data ( mbusrf3_t *ctx, uint8_t *data_in, uint8_t len );
274
275#ifdef __cplusplus
276}
277#endif
278#endif // MBUSRF3_H
279 // mbusrf3
281
282// ------------------------------------------------------------------------ END
#define MBUSRF3_TX_DRV_BUFFER_SIZE
M-BUS RF 3 driver buffer size.
Definition: mbusrf3.h:91
#define MBUSRF3_RX_DRV_BUFFER_SIZE
Definition: mbusrf3.h:92
err_t mbusrf3_init(mbusrf3_t *ctx, mbusrf3_cfg_t *cfg)
M-BUS RF 3 initialization function.
void mbusrf3_set_rst_pin(mbusrf3_t *ctx, uint8_t pin_state)
M-BUS RF 3 set reset pin function.
err_t mbusrf3_send_command(mbusrf3_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
M-BUS RF 3 send command function.
err_t mbusrf3_generic_read(mbusrf3_t *ctx, uint8_t *data_out, uint16_t len)
M-BUS RF 3 data reading function.
err_t mbusrf3_generic_write(mbusrf3_t *ctx, uint8_t *data_in, uint16_t len)
M-BUS RF 3 data writing function.
void mbusrf3_cfg_setup(mbusrf3_cfg_t *cfg)
M-BUS RF 3 configuration object setup function.
err_t mbusrf3_send_data(mbusrf3_t *ctx, uint8_t *data_in, uint8_t len)
M-BUS RF 3 send data function.
mbusrf3_return_value_t
M-BUS RF 3 Click return value data.
Definition: mbusrf3.h:168
@ MBUSRF3_ERROR
Definition: mbusrf3.h:170
@ MBUSRF3_OK
Definition: mbusrf3.h:169
@ MBUSRF3_ERROR_TIMEOUT
Definition: mbusrf3.h:171
M-BUS RF 3 Click configuration object.
Definition: mbusrf3.h:145
pin_name_t rts
Definition: mbusrf3.h:152
uint32_t baud_rate
Definition: mbusrf3.h:155
bool uart_blocking
Definition: mbusrf3.h:156
uart_data_bits_t data_bit
Definition: mbusrf3.h:157
pin_name_t tx_pin
Definition: mbusrf3.h:148
pin_name_t rx_pin
Definition: mbusrf3.h:147
uart_stop_bits_t stop_bit
Definition: mbusrf3.h:159
uart_parity_t parity_bit
Definition: mbusrf3.h:158
pin_name_t rst
Definition: mbusrf3.h:151
M-BUS RF 3 Click context object.
Definition: mbusrf3.h:124
uart_t uart
Definition: mbusrf3.h:132
digital_in_t rts
Definition: mbusrf3.h:129
digital_out_t rst
Definition: mbusrf3.h:126