rs485isolator3 2.1.0.0
rs485isolator3.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 RS485ISOLATOR3_H
29#define RS485ISOLATOR3_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
74#define RS485ISOLATOR3_TX_DRV_BUFFER_SIZE 100
75#define RS485ISOLATOR3_RX_DRV_BUFFER_SIZE 300
76
77 // rs485isolator3_cmd
78
93#define RS485ISOLATOR3_MAP_MIKROBUS( cfg, mikrobus ) \
94 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
95 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
96 cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
97 cfg.de = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
98 cfg.inv = MIKROBUS( mikrobus, MIKROBUS_INT );
99
100 // rs485isolator3_map
101 // rs485isolator3
102
107typedef struct
108{
109 // Output pins
110 digital_out_t re;
111 digital_out_t de;
112 digital_out_t inv;
114 // Modules
115 uart_t uart;
117 // Buffers
118 char uart_rx_buffer[ RS485ISOLATOR3_RX_DRV_BUFFER_SIZE ];
119 char uart_tx_buffer[ RS485ISOLATOR3_TX_DRV_BUFFER_SIZE ];
122
127typedef struct
128{
129 // Communication gpio pins
130 pin_name_t rx_pin;
131 pin_name_t tx_pin;
133 // Additional gpio pins
134 pin_name_t re;
135 pin_name_t de;
136 pin_name_t inv;
138 // Static variable
139 uint32_t baud_rate;
141 uart_data_bits_t data_bit;
142 uart_parity_t parity_bit;
143 uart_stop_bits_t stop_bit;
146
157
174
189
201
214err_t rs485isolator3_generic_write ( rs485isolator3_t *ctx, char *data_in, uint16_t len );
215
228err_t rs485isolator3_generic_read ( rs485isolator3_t *ctx, char *data_out, uint16_t len );
229
239
249
259
269
280
290
303
304#ifdef __cplusplus
305}
306#endif
307#endif // RS485ISOLATOR3_H
308
309 // rs485isolator3
310
311// ------------------------------------------------------------------------ END
#define RS485ISOLATOR3_TX_DRV_BUFFER_SIZE
RS485 Isolator 3 driver buffer size.
Definition rs485isolator3.h:74
#define RS485ISOLATOR3_RX_DRV_BUFFER_SIZE
Definition rs485isolator3.h:75
err_t rs485isolator3_generic_read(rs485isolator3_t *ctx, char *data_out, uint16_t len)
RS485 Isolator 3 data reading function.
void rs485isolator3_enable_receiver_input(rs485isolator3_t *ctx)
RS485 Isolator 3 enable receiver input function.
void rs485isolator3_default_cfg(rs485isolator3_t *ctx)
RS485 Isolator 3 default configuration function.
err_t rs485isolator3_send_bit_by_bit(rs485isolator3_t *ctx, char *command)
RS485 Isolator 3 send data function.
void rs485isolator3_cfg_setup(rs485isolator3_cfg_t *cfg)
RS485 Isolator 3 configuration object setup function.
void rs485isolator3_disable_output(rs485isolator3_t *ctx)
RS485 Isolator 3 disable output function.
void rs485isolator3_inverted_inputs(rs485isolator3_t *ctx)
RS485 Isolator 3 invert output function.
void rs485isolator3_disable_receiver_input(rs485isolator3_t *ctx)
RS485 Isolator 3 disable receiver input function.
err_t rs485isolator3_init(rs485isolator3_t *ctx, rs485isolator3_cfg_t *cfg)
RS485 Isolator 3 initialization function.
void rs485isolator3_enable_output(rs485isolator3_t *ctx)
RS485 Isolator 3 enable output function.
err_t rs485isolator3_generic_write(rs485isolator3_t *ctx, char *data_in, uint16_t len)
RS485 Isolator 3 data writing function.
void rs485isolator3_not_inverted_inputs(rs485isolator3_t *ctx)
RS485 Isolator 3 not invert output function.
rs485isolator3_return_value_t
RS485 Isolator 3 Click return value data.
Definition rs485isolator3.h:152
@ RS485ISOLATOR3_OK
Definition rs485isolator3.h:153
@ RS485ISOLATOR3_ERROR
Definition rs485isolator3.h:154
RS485 Isolator 3 Click configuration object.
Definition rs485isolator3.h:128
uint32_t baud_rate
Definition rs485isolator3.h:139
pin_name_t re
Definition rs485isolator3.h:134
bool uart_blocking
Definition rs485isolator3.h:140
uart_data_bits_t data_bit
Definition rs485isolator3.h:141
pin_name_t inv
Definition rs485isolator3.h:136
pin_name_t tx_pin
Definition rs485isolator3.h:131
pin_name_t de
Definition rs485isolator3.h:135
pin_name_t rx_pin
Definition rs485isolator3.h:130
uart_stop_bits_t stop_bit
Definition rs485isolator3.h:143
uart_parity_t parity_bit
Definition rs485isolator3.h:142
RS485 Isolator 3 Click context object.
Definition rs485isolator3.h:108
digital_out_t re
Definition rs485isolator3.h:110
digital_out_t inv
Definition rs485isolator3.h:112
uart_t uart
Definition rs485isolator3.h:115
digital_out_t de
Definition rs485isolator3.h:111