i2c1wire2  2.1.0.0
i2c1wire2.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 I2C1WIRE2_H
29 #define I2C1WIRE2_H
30 
31 #ifdef __cplusplus
32 extern "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 
50 #include "drv_digital_out.h"
51 #include "drv_digital_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define I2C1WIRE2_REG_MASTER_CFG 0x00
75 #define I2C1WIRE2_REG_STD_SPEED_TRSTL 0x01
76 #define I2C1WIRE2_REG_STD_SPEED_TMSI 0x02
77 #define I2C1WIRE2_REG_STD_SPEED_TMSP 0x03
78 #define I2C1WIRE2_REG_STD_SPEED_TRTH 0x04
79 #define I2C1WIRE2_REG_STD_SPEED_TW0L 0x05
80 #define I2C1WIRE2_REG_STD_SPEED_TW1L 0x06
81 #define I2C1WIRE2_REG_STD_SPEED_TMSR 0x07
82 #define I2C1WIRE2_REG_STD_SPEED_TREC 0x08
83 #define I2C1WIRE2_REG_OVER_SPEED_TRSTL 0x09
84 #define I2C1WIRE2_REG_OVER_SPEED_TMSI 0x0A
85 #define I2C1WIRE2_REG_OVER_SPEED_TMSP 0x0B
86 #define I2C1WIRE2_REG_OVER_SPEED_TRTH 0x0C
87 #define I2C1WIRE2_REG_OVER_SPEED_TW0L 0x0D
88 #define I2C1WIRE2_REG_OVER_SPEED_TW1L 0x0E
89 #define I2C1WIRE2_REG_OVER_SPEED_TMSR 0x0F
90 #define I2C1WIRE2_REG_OVER_SPEED_TREC 0x10
91 #define I2C1WIRE2_REG_PRUP_BUFF 0x11
92 #define I2C1WIRE2_REG_PDSLEW 0x12
93 
98 #define I2C1WIRE2_CMD_WRITE_MEMORY 0x96
99 #define I2C1WIRE2_CMD_READ_MEMORY 0x44
100 #define I2C1WIRE2_CMD_SET_PAGE_PROTECTION 0xC3
101 #define I2C1WIRE2_CMD_READ_STATUS 0xAA
102 #define I2C1WIRE2_CMD_READ_1WIRE_PORT_CFG 0x52
103 #define I2C1WIRE2_CMD_WRITE_1WIRE_PORT_CFG 0x99
104 #define I2C1WIRE2_CMD_MASTER_RESET 0x62
105 #define I2C1WIRE2_CMD_1WIRE_SCRIPT 0x88
106 #define I2C1WIRE2_CMD_1WIRE_BLOCK 0xAB
107 #define I2C1WIRE2_CMD_1WIRE_READ_BLOCK 0x50
108 #define I2C1WIRE2_CMD_1WIRE_WRITE_BLOCK 0x68
109 #define I2C1WIRE2_CMD_1WIRE_SEARCH 0x11
110 #define I2C1WIRE2_CMD_FULL_COMMAND_SEQUENCE 0x57
111 #define I2C1WIRE2_CMD_COMPUTE_CRC16 0xCC
112 
113 
114 
115  // i2c1wire2_reg
117 
132 #define I2C1WIRE2_CUSTOM_VAL 0x80
133 #define I2C1WIRE2_RWPU_EXT 0x00
134 #define I2C1WIRE2_RWPU_500 0x01
135 #define I2C1WIRE2_RWPU_1000 0x02
136 #define I2C1WIRE2_RWPU_333 0x03
137 #define I2C1WIRE2_VIAPO_LOW 0x00
138 #define I2C1WIRE2_VIAPO_MEDIUM 0x04
139 #define I2C1WIRE2_VIAPO_HIGH 0x08
140 #define I2C1WIRE2_VIAPO_OFF 0x0C
141 #define I2C1WIRE2_VTH_LOW 0x00
142 #define I2C1WIRE2_VTH_MEDIUM 0x01
143 #define I2C1WIRE2_VTH_HIGH 0x02
144 #define I2C1WIRE2_VTH_OFF 0x03
145 
150 #define I2C1WIRE2_SEARCH_1WIRE_RESET 0x01
151 #define I2C1WIRE2_SEARCH_IGNORE_PULSE 0x02
152 #define I2C1WIRE2_SEARCH_RESET 0x04
153 
158 #define I2C1WIRE2_RESULT_BYTE_OK 0xAA
159 #define I2C1WIRE2_RESULT_BYTE_ERROR 0x55
160 #define I2C1WIRE2_NO_PRESENCE_PULS 0x33
161 #define I2C1WIRE2_NO_DEVICE_DETECTED 0x00
162 #define I2C1WIRE2_RESULT_BYTE_ERROR_INVALID_PARAMS 0x77
163 #define I2C1WIRE2_RESULT_BYTE_ERROR_RESET_FAIL 0x22
164 
170 #define I2C1WIRE2_DEVICE_ADDRESS 0x40
171  // i2c1wire2_set
173 
188 #define I2C1WIRE2_MAP_MIKROBUS( cfg, mikrobus ) \
189  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
190  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
191  // i2c1wire2_map // i2c1wire2
194 
199 typedef struct
200 {
201  // Modules
202  i2c_master_t i2c;
204  // I2C slave address
205  uint8_t slave_address;
207 } i2c1wire2_t;
208 
213 typedef struct
214 {
215  pin_name_t scl;
216  pin_name_t sda;
218  uint32_t i2c_speed;
219  uint8_t i2c_address;
222 
227 typedef enum
228 {
230  I2C1WIRE2_ERROR = -1
231 
233 
250 
265 
279 
294 err_t i2c1wire2_generic_write ( i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
295 
310 err_t i2c1wire2_generic_read ( i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
311 
323 
336 err_t i2c1wire2_read_port_cfg ( i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_out );
337 
350 err_t i2c1wire2_write_port_cfg ( i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_in );
351 
367 err_t i2c1wire2_search ( i2c1wire2_t *ctx, uint8_t *flag, uint8_t *rom_id, uint8_t *last_flag, uint8_t param_data, uint8_t command_code );
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 #endif // I2C1WIRE2_H
373  // i2c1wire2
375 
376 // ------------------------------------------------------------------------ END
i2c1wire2_read_port_cfg
err_t i2c1wire2_read_port_cfg(i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_out)
I2C 1-Wire 2 read port configuration function.
i2c1wire2_search
err_t i2c1wire2_search(i2c1wire2_t *ctx, uint8_t *flag, uint8_t *rom_id, uint8_t *last_flag, uint8_t param_data, uint8_t command_code)
I2C 1-Wire 2 search function.
i2c1wire2_default_cfg
err_t i2c1wire2_default_cfg(i2c1wire2_t *ctx)
I2C 1-Wire 2 default configuration function.
i2c1wire2_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2c1wire2.h:219
i2c1wire2_master_reset
err_t i2c1wire2_master_reset(i2c1wire2_t *ctx)
I2C 1-Wire 2 master reset function.
i2c1wire2_write_port_cfg
err_t i2c1wire2_write_port_cfg(i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_in)
I2C 1-Wire 2 write port configuration function.
i2c1wire2_cfg_t::sda
pin_name_t sda
Definition: i2c1wire2.h:216
i2c1wire2_t
I2C 1-Wire 2 Click context object.
Definition: i2c1wire2.h:200
i2c1wire2_return_value_t
i2c1wire2_return_value_t
I2C 1-Wire 2 Click return value data.
Definition: i2c1wire2.h:228
I2C1WIRE2_OK
@ I2C1WIRE2_OK
Definition: i2c1wire2.h:229
i2c1wire2_init
err_t i2c1wire2_init(i2c1wire2_t *ctx, i2c1wire2_cfg_t *cfg)
I2C 1-Wire 2 initialization function.
i2c1wire2_cfg_t
I2C 1-Wire 2 Click configuration object.
Definition: i2c1wire2.h:214
I2C1WIRE2_ERROR
@ I2C1WIRE2_ERROR
Definition: i2c1wire2.h:230
i2c1wire2_t::i2c
i2c_master_t i2c
Definition: i2c1wire2.h:202
i2c1wire2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2c1wire2.h:218
i2c1wire2_t::slave_address
uint8_t slave_address
Definition: i2c1wire2.h:205
i2c1wire2_cfg_t::scl
pin_name_t scl
Definition: i2c1wire2.h:215
i2c1wire2_generic_read
err_t i2c1wire2_generic_read(i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
I2C 1-Wire 2 I2C reading function.
i2c1wire2_generic_write
err_t i2c1wire2_generic_write(i2c1wire2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
I2C 1-Wire 2 I2C writing function.
i2c1wire2_cfg_setup
void i2c1wire2_cfg_setup(i2c1wire2_cfg_t *cfg)
I2C 1-Wire 2 configuration object setup function.