Go to the documentation of this file.
35 #include "mikrosdk_version.h"
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
69 #define PAC1954_REG_REFRESH 0x00
70 #define PAC1954_REG_CTRL 0x01
71 #define PAC1954_REG_ACC_COUNT 0x02
72 #define PAC1954_REG_VACC_CH1 0x03
73 #define PAC1954_REG_VACC_CH2 0x04
74 #define PAC1954_REG_VACC_CH3 0x05
75 #define PAC1954_REG_VACC_CH4 0x06
76 #define PAC1954_REG_VBUS_CH1 0x07
77 #define PAC1954_REG_VBUS_CH2 0x08
78 #define PAC1954_REG_VBUS_CH3 0x09
79 #define PAC1954_REG_VBUS_CH4 0x0A
80 #define PAC1954_REG_VSENSE_CH1 0x0B
81 #define PAC1954_REG_VSENSE_CH2 0x0C
82 #define PAC1954_REG_VSENSE_CH3 0x0D
83 #define PAC1954_REG_VSENSE_CH4 0x0E
84 #define PAC1954_REG_VBUS_CH1_AVG 0x0F
85 #define PAC1954_REG_VBUS_CH2_AVG 0x10
86 #define PAC1954_REG_VBUS_CH3_AVG 0x11
87 #define PAC1954_REG_VBUS_CH4_AVG 0x12
88 #define PAC1954_REG_VSENSE_CH1_AVG 0x13
89 #define PAC1954_REG_VSENSE_CH2_AVG 0x14
90 #define PAC1954_REG_VSENSE_CH3_AVG 0x15
91 #define PAC1954_REG_VSENSE_CH4_AVG 0x16
92 #define PAC1954_REG_VPOWER_CH1 0x17
93 #define PAC1954_REG_VPOWER_CH2 0x18
94 #define PAC1954_REG_VPOWER_CH3 0x19
95 #define PAC1954_REG_VPOWER_CH4 0x1A
96 #define PAC1954_REG_SMBUS_CFG 0x1C
97 #define PAC1954_REG_NEG_PWR_FSR 0x1D
98 #define PAC1954_REG_REFRESH_G 0x1E
99 #define PAC1954_REG_REFRESH_V 0x1F
100 #define PAC1954_REG_SLOW 0x20
101 #define PAC1954_REG_CTRL_ACT 0x21
102 #define PAC1954_REG_NEG_PWR_FSR_ACT 0x22
103 #define PAC1954_REG_CTRL_LAT 0x23
104 #define PAC1954_REG_NEG_PWR_FSR_LAT 0x24
105 #define PAC1954_REG_ACC_CFG 0x25
106 #define PAC1954_REG_ALERT_STATUS 0x26
107 #define PAC1954_REG_SLOW_ALERT1 0x27
108 #define PAC1954_REG_GPIO_ALERT2 0x28
109 #define PAC1954_REG_ACC_FULLNESS_LIM 0x29
110 #define PAC1954_REG_OC_LIM_CH1 0x30
111 #define PAC1954_REG_OC_LIM_CH2 0x31
112 #define PAC1954_REG_OC_LIM_CH3 0x32
113 #define PAC1954_REG_OC_LIM_CH4 0x33
114 #define PAC1954_REG_UC_LIM_CH1 0x34
115 #define PAC1954_REG_UC_LIM_CH2 0x35
116 #define PAC1954_REG_UC_LIM_CH3 0x36
117 #define PAC1954_REG_UC_LIM_CH4 0x37
118 #define PAC1954_REG_OP_LIM_CH1 0x38
119 #define PAC1954_REG_OP_LIM_CH2 0x39
120 #define PAC1954_REG_OP_LIM_CH3 0x3A
121 #define PAC1954_REG_OP_LIM_CH4 0x3B
122 #define PAC1954_REG_OV_LIM_CH1 0x3C
123 #define PAC1954_REG_OV_LIM_CH2 0x3D
124 #define PAC1954_REG_OV_LIM_CH3 0x3E
125 #define PAC1954_REG_OV_LIM_CH4 0x3F
126 #define PAC1954_REG_UV_LIM_CH1 0x40
127 #define PAC1954_REG_UV_LIM_CH2 0x41
128 #define PAC1954_REG_UV_LIM_CH3 0x42
129 #define PAC1954_REG_UV_LIM_CH4 0x43
130 #define PAC1954_REG_OC_LIM_NSAMPLES 0x44
131 #define PAC1954_REG_UC_LIM_NSAMPLES 0x45
132 #define PAC1954_REG_OP_LIM_NSAMPLES 0x46
133 #define PAC1954_REG_OV_LIM_NSAMPLES 0x47
134 #define PAC1954_REG_UV_LIM_NSAMPLES 0x48
135 #define PAC1954_REG_ALERT_ENABLE 0x49
136 #define PAC1954_REG_ACC_CFG_ACT 0x4A
137 #define PAC1954_REG_ACC_CFG_LAT 0x4B
138 #define PAC1954_REG_ID_PRODUCT 0xFD
139 #define PAC1954_REG_ID_MANUFACTURER 0xFE
140 #define PAC1954_REG_ID_REVISION 0xFF
158 #define PAC1954_CTRLH_SPS_1024_ADAPT_ACC 0x00
159 #define PAC1954_CTRLH_SPS_256_ADAPT_ACC 0x10
160 #define PAC1954_CTRLH_SPS_64_ADAPT_ACC 0x20
161 #define PAC1954_CTRLH_SPS_8_ADAPT_ACC 0x30
162 #define PAC1954_CTRLH_SPS_1024 0x40
163 #define PAC1954_CTRLH_SPS_256 0x50
164 #define PAC1954_CTRLH_SPS_64 0x60
165 #define PAC1954_CTRLH_SPS_8 0x70
166 #define PAC1954_CTRLH_SINGLE_SHOT_MODE 0x80
167 #define PAC1954_CTRLH_SINGLE_SHOT_8X 0x90
168 #define PAC1954_CTRLH_FAST_MODE 0xA0
169 #define PAC1954_CTRLH_BURST_MODE 0xB0
170 #define PAC1954_CTRLH_SLEEP 0xF0
171 #define PAC1954_CTRLH_INT_PIN_ALERT 0x00
172 #define PAC1954_CTRLH_INT_PIN_DIG_IN 0x04
173 #define PAC1954_CTRLH_INT_PIN_DIG_OUT 0x08
174 #define PAC1954_CTRLH_INT_PIN_SLOW 0x0C
175 #define PAC1954_CTRLH_SLW_PIN_ALERT 0x00
176 #define PAC1954_CTRLH_SLW_PIN_DIG_IN 0x01
177 #define PAC1954_CTRLH_SLW_PIN_DIG_OUT 0x02
178 #define PAC1954_CTRLH_SLW_PIN_SLOW 0x03
179 #define PAC1954_CTRLL_CH1_OFF 0x80
180 #define PAC1954_CTRLL_CH2_OFF 0x40
181 #define PAC1954_CTRLL_CH3_OFF 0x20
182 #define PAC1954_CTRLL_CH4_OFF 0x10
183 #define PAC1954_CTRLL_ALL_CH_OFF 0xF0
184 #define PAC1954_CTRLL_ALL_CH_ON 0x00
190 #define PAC1954_NEG_PWR_FSR_CH1_OFFSET 6
191 #define PAC1954_NEG_PWR_FSR_CH2_OFFSET 4
192 #define PAC1954_NEG_PWR_FSR_CH3_OFFSET 2
193 #define PAC1954_NEG_PWR_FSR_CH4_OFFSET 0
199 #define PAC1954_SMBUS_INT_PIN_MASK 0x80
200 #define PAC1954_SMBUS_SLW_PIN_MASK 0x40
201 #define PAC1954_SMBUS_ALERT_MASK 0x20
202 #define PAC1954_SMBUS_POR_MASK 0x10
203 #define PAC1954_SMBUS_TIMEOUT_OFF 0x00
204 #define PAC1954_SMBUS_TIMEOUT_ON 0x08
205 #define PAC1954_SMBUS_BYTE_COUNT_OFF 0x00
206 #define PAC1954_SMBUS_BYTE_COUNT_ON 0x04
207 #define PAC1954_SMBUS_AUTO_INC_SKIP_ON 0x00
208 #define PAC1954_SMBUS_AUTO_INC_SKIP_OFF 0x02
209 #define PAC1954_SMBUS_I2C_HIGH_SPEED 0x01
215 #define PAC1954_MEAS_SEL_V_SOURCE 0
216 #define PAC1954_MEAS_SEL_I_SENSE 1
217 #define PAC1954_MEAS_SEL_P_SENSE 2
223 #define PAC1954_CH_SEL_CH_1 1
224 #define PAC1954_CH_SEL_CH_2 2
225 #define PAC1954_CH_SEL_CH_3 3
226 #define PAC1954_CH_SEL_CH_4 4
232 #define PAC1954_AVG_SEL_DISABLE 0
233 #define PAC1954_AVG_SEL_ENABLE 1
239 #define PAC1954_MEAS_MODE_UNIPOLAR_FSR 0
240 #define PAC1954_MEAS_MODE_BIPOLAR_FSR 1
241 #define PAC1954_MEAS_MODE_BIPOLAR_HALF_FSR 2
247 #define PAC1954_ALL_CH_SAMPLE_8SPS_ON 1
248 #define PAC1954_ALL_CH_SAMPLE_8SPS_OFF 0
254 #define PAC1954_DEV_ENABLE 1
255 #define PAC1954_DEV_PWR_DWN 0
261 #define PAC1954_ALERT_ACTIVE 0
262 #define PAC1954_ALERT_INACTIVE 1
269 #define PAC1954_DEV_ADDR_0 0x10
270 #define PAC1954_DEV_ADDR_1 0x1F
288 #define PAC1954_MAP_MIKROBUS( cfg, mikrobus ) \
289 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
290 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
291 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
292 cfg.slw = MIKROBUS( mikrobus, MIKROBUS_RST ); \
293 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
541 uint8_t avg_sel, uint32_t *data_out );
593 uint8_t avg_sel, uint8_t meas_mode,
float *data_out );
err_t pac1954_set_address_pointer(pac1954_t *ctx, uint8_t reg)
PAC1954 Set Address Pointer Function.
void pac1954_cfg_setup(pac1954_cfg_t *cfg)
PAC1954 configuration object setup function.
err_t pac1954_get_measurement(pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint32_t *data_out)
PAC1954 Get Measurement Function.
uint32_t i2c_speed
Definition: pac1954.h:332
digital_out_t slw
Definition: pac1954.h:306
void pac1954_set_ch_8_sps(pac1954_t *ctx, uint8_t state)
PAC1954 Slow Down Sampling Freq Of All Channels Function.
digital_in_t int_pin
Definition: pac1954.h:309
PAC1954 Click context object.
Definition: pac1954.h:303
err_t pac1954_single_read(pac1954_t *ctx, uint8_t reg, uint8_t *data_out)
PAC1954 Single Byte Read Function.
err_t pac1954_generic_write(pac1954_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
PAC1954 I2C writing function.
err_t pac1954_default_cfg(pac1954_t *ctx)
PAC1954 default configuration function.
i2c_master_t i2c
Definition: pac1954.h:312
void pac1954_enable(pac1954_t *ctx, uint8_t state)
PAC1954 Power Control Function.
PAC1954 Click configuration object.
Definition: pac1954.h:324
pin_name_t sda
Definition: pac1954.h:326
pin_name_t scl
Definition: pac1954.h:325
err_t pac1954_get_calc_measurement(pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode, float *data_out)
PAC1954 Get Calculated Measurement Function.
err_t pac1954_get_acc_output(pac1954_t *ctx, uint8_t ch_sel, uint8_t *data_out)
PAC1954 Get Accumulator Output Function.
pin_name_t slw
Definition: pac1954.h:329
err_t pac1954_get_acc_count(pac1954_t *ctx, uint32_t *data_out)
PAC1954 Get Accumulator Count Function.
err_t pac1954_init(pac1954_t *ctx, pac1954_cfg_t *cfg)
PAC1954 initialization function.
digital_out_t en
Definition: pac1954.h:305
uint8_t pac1954_get_alert2_status(pac1954_t *ctx)
PAC1954 Get INT Pin State Function.
@ PAC1954_OK
Definition: pac1954.h:343
@ PAC1954_ERROR
Definition: pac1954.h:344
err_t pac1954_single_write(pac1954_t *ctx, uint8_t reg, uint8_t data_in)
PAC1954 Single Byte Write Function.
err_t pac1954_generic_read(pac1954_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
PAC1954 I2C reading function.
err_t pac1954_refresh_cmd(pac1954_t *ctx)
PAC1954 Refresh Command.
pac1954_return_value_t
PAC1954 Click return value data.
Definition: pac1954.h:342
pin_name_t en
Definition: pac1954.h:328
pin_name_t int_pin
Definition: pac1954.h:330
err_t pac1954_read_last_access_reg(pac1954_t *ctx, uint8_t *data_out)
PAC1954 Last Accessed Register Read Function.
err_t pac1954_vol_refresh_cmd(pac1954_t *ctx)
PAC1954 Volatile Refresh Command.
uint8_t i2c_address
Definition: pac1954.h:333
uint8_t slave_address
Definition: pac1954.h:315