digipot12 2.1.0.0
digipot12.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 DIGIPOT12_H
29#define DIGIPOT12_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_i2c_master.h"
52
73#define DIGIPOT12_CTRL_BIT_NOP 0x00
74#define DIGIPOT12_CTRL_BIT_WRITE_RDAC 0x10
75#define DIGIPOT12_CTRL_BIT_WRITE_SHIFT_REG 0x20
76#define DIGIPOT12_CTRL_BIT_READ 0x30
77#define DIGIPOT12_CTRL_BIT_LIN_RDAC 0x40
78#define DIGIPOT12_CTRL_BIT_6_DB_RDAC 0x50
79#define DIGIPOT12_CTRL_BIT_COPY_LRDAC 0x60
80#define DIGIPOT12_CTRL_BIT_COPY_RDAC_EEPROM 0x70
81#define DIGIPOT12_CTRL_BIT_WRITE_EEPROM 0x80
82#define DIGIPOT12_CTRL_BIT_SCALE 0x90
83#define DIGIPOT12_CTRL_BIT_SW_RST 0xB0
84#define DIGIPOT12_CTRL_BIT_SW_SHDN 0xC0
85#define DIGIPOT12_CTRL_BIT_REG_CTRL 0xD0
86#define DIGIPOT12_CTRL_BIT_MASK 0xF0
87
88 // digipot12_ctrl
89
99#define DIGIPOT12_ADDR_BIT_RDAC1 0x00
100#define DIGIPOT12_ADDR_BIT_RDAC2 0x01
101#define DIGIPOT12_ADDR_BIT_ALL_CHANNELS 0x08
102
103 // digipot12_addr
104
114#define DIGIPOT12_WIPER_SEL_1 0x00
115#define DIGIPOT12_WIPER_SEL_2 0x01
116#define DIGIPOT12_WIPER_SEL_BOTH 0x08
117
118 // digipot12_wiper_sel
119
129#define DIGIPOT12_ADDR_BIT_READ_INPUT_REG 0x00
130#define DIGIPOT12_ADDR_BIT_READ_EEPROM 0x01
131#define DIGIPOT12_ADDR_BIT_READ_CTRL_REG 0x02
132#define DIGIPOT12_ADDR_BIT_READ_RDAC 0x03
133#define DIGIPOT12_ADDR_BIT_RDAC_DECR 0x00
134#define DIGIPOT12_ADDR_BIT_RDAC_INCR 0x01
135#define DIGIPOT12_ADDR_BIT_COPY_TO_RDAC 0x00
136#define DIGIPOT12_ADDR_BIT_COPY_TO_EEPROM 0x01
137#define DIGIPOT12_ADDR_BIT_SCALE_MODE_NORMAL 0x80
138#define DIGIPOT12_ADDR_BIT_SCALE_MODE_SHDN 0x81
139#define DIGIPOT12_ADDR_BIT_SCALE_EXIT 0x00
140#define DIGIPOT12_ADDR_BIT_SCALE_ENTER 0x01
141#define DIGIPOT12_ADDR_BIT_SW_SHDN_MODE_NORMAL 0x00
142#define DIGIPOT12_ADDR_BIT_SW_SHDN_MODE_SHDN 0x01
143
144
145 // digipot12_mask
146
161#define DIGIPOT12_CTRL_REG_WIPER_POS_FROZEN 0x00
162#define DIGIPOT12_CTRL_REG_UPDATE_WIPER_POS 0x01
163#define DIGIPOT12_CTRL_REG_EEPROM_PROGRAM_DISABLE 0x00
164#define DIGIPOT12_CTRL_REG_EEPROM_PROGRAM_ENABLE 0x02
165#define DIGIPOT12_CTRL_REG_MODE_POTENTIOMETER 0x00
166#define DIGIPOT12_CTRL_REG_MODE_LINEAR_GAIN 0x04
167#define DIGIPOT12_CTRL_REG_MODE_BURST_DISABLE 0x00
168#define DIGIPOT12_CTRL_REG_MODE_BURST_ENABLE 0x08
169
174#define DIGIPOT12_WIPER_POS_MAX 255
175#define DIGIPOT12_WIPER_POS_MIN 0
176#define DIGIPOT12_WIPER_POS_MIDDLE 127
177#define DIGIPOT12_RES_10_KOHM 10
178#define DIGIPOT12_RES_0_KOHM 0
179
185#define DIGIPOT12_DEVICE_ADDRESS_0 0x2F
186#define DIGIPOT12_DEVICE_ADDRESS_1 0x2C
187#define DIGIPOT12_DEVICE_ADDRESS_2 0x23
188#define DIGIPOT12_DEVICE_ADDRESS_3 0x20
189
190 // digipot12_set
191
206#define DIGIPOT12_MAP_MIKROBUS( cfg, mikrobus ) \
207 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
208 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
209 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
210
211 // digipot12_map
212 // digipot12
213
218typedef struct
219{
220 // Output pins
221 digital_out_t rst;
223 // Modules
224 i2c_master_t i2c;
226 // I2C slave address
230
235typedef struct
236{
237 pin_name_t scl;
238 pin_name_t sda;
240 pin_name_t rst;
242 uint32_t i2c_speed;
243 uint8_t i2c_address;
246
257
274
289
303
317
331
346err_t digipot12_write_data ( digipot12_t *ctx, uint8_t ctrl, uint8_t addr, uint8_t data_in );
347
362err_t digipot12_read_data ( digipot12_t *ctx, uint8_t addr, uint8_t mask, uint8_t *data_out );
363
378err_t digipot12_write_rdac ( digipot12_t *ctx, uint8_t addr, uint8_t data_in );
379
394err_t digipot12_read_rdac ( digipot12_t *ctx, uint8_t addr, uint8_t *data_out );
395
409err_t digipot12_set_wiper_1 ( digipot12_t *ctx, uint8_t wiper_pos );
410
424err_t digipot12_set_wiper_2 ( digipot12_t *ctx, uint8_t wiper_pos );
425
440err_t digipot12_set_resistance ( digipot12_t *ctx, uint8_t wiper_sel, float res_kohm );
441
456err_t digipot12_get_resistance ( digipot12_t *ctx, uint8_t wiper_sel, float *res_kohm );
457
458#ifdef __cplusplus
459}
460#endif
461#endif // DIGIPOT12_H
462
463 // digipot12
464
465// ------------------------------------------------------------------------ END
digipot12_return_value_t
DIGI POT 12 Click return value data.
Definition digipot12.h:252
@ DIGIPOT12_OK
Definition digipot12.h:253
@ DIGIPOT12_ERROR
Definition digipot12.h:254
err_t digipot12_write_rdac(digipot12_t *ctx, uint8_t addr, uint8_t data_in)
DIGI POT 12 write the RDAC function.
err_t digipot12_set_wiper_2(digipot12_t *ctx, uint8_t wiper_pos)
DIGI POT 12 set wiper 2 function.
err_t digipot12_read_rdac(digipot12_t *ctx, uint8_t addr, uint8_t *data_out)
DIGI POT 12 read the RDAC function.
err_t digipot12_set_wiper_1(digipot12_t *ctx, uint8_t wiper_pos)
DIGI POT 12 set wiper 1 function.
err_t digipot12_write_data(digipot12_t *ctx, uint8_t ctrl, uint8_t addr, uint8_t data_in)
DIGI POT 12 I2C writing function.
err_t digipot12_default_cfg(digipot12_t *ctx)
DIGI POT 12 default configuration function.
void digipot12_cfg_setup(digipot12_cfg_t *cfg)
DIGI POT 12 configuration object setup function.
err_t digipot12_read_data(digipot12_t *ctx, uint8_t addr, uint8_t mask, uint8_t *data_out)
DIGI POT 12 I2C reading function.
void digipot12_hw_reset(digipot12_t *ctx)
DIGI POT 12 hardware reset function.
err_t digipot12_get_resistance(digipot12_t *ctx, uint8_t wiper_sel, float *res_kohm)
DIGI POT 12 get the resistance function.
void digipot12_device_enable(digipot12_t *ctx)
DIGI POT 12 enable the device function.
err_t digipot12_set_resistance(digipot12_t *ctx, uint8_t wiper_sel, float res_kohm)
DIGI POT 12 set the resistance function.
err_t digipot12_init(digipot12_t *ctx, digipot12_cfg_t *cfg)
DIGI POT 12 initialization function.
DIGI POT 12 Click configuration object.
Definition digipot12.h:236
uint32_t i2c_speed
Definition digipot12.h:242
pin_name_t scl
Definition digipot12.h:237
pin_name_t sda
Definition digipot12.h:238
pin_name_t rst
Definition digipot12.h:240
uint8_t i2c_address
Definition digipot12.h:243
DIGI POT 12 Click context object.
Definition digipot12.h:219
i2c_master_t i2c
Definition digipot12.h:224
digital_out_t rst
Definition digipot12.h:221
uint8_t slave_address
Definition digipot12.h:227