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_spi_master.h"
70 #define HBRIDGE9_OPCODE_WRITE 0x00
71 #define HBRIDGE9_OPCODE_READ 0x40
72 #define HBRIDGE9_OPCODE_READ_CLEAR 0x80
73 #define HBRIDGE9_OPCODE_READ_DEV_INFO 0xC0
74 #define HBRIDGE9_ADV_OPCODE_SET_DEFAULT 0xFF
75 #define HBRIDGE9_ADV_OPCODE_CLEAR_STATUS 0xBF
76 #define HBRIDGE9_OPCODE_BITS_MASK 0xC0
82 #define HBRIDGE9_REG_CR0 0x00
83 #define HBRIDGE9_REG_CR1 0x01
84 #define HBRIDGE9_REG_CR2 0x02
85 #define HBRIDGE9_REG_CR3 0x03
86 #define HBRIDGE9_REG_CR4 0x04
87 #define HBRIDGE9_REG_CR5 0x05
88 #define HBRIDGE9_REG_CR6 0x06
89 #define HBRIDGE9_REG_CR7 0x07
90 #define HBRIDGE9_REG_CR8 0x08
96 #define HBRIDGE9_REG_SR0 0x10
97 #define HBRIDGE9_REG_SR1 0x11
98 #define HBRIDGE9_REG_SR2 0x12
99 #define HBRIDGE9_REG_SR3 0x13
100 #define HBRIDGE9_REG_SR4 0x14
101 #define HBRIDGE9_REG_SR5 0x15
102 #define HBRIDGE9_REG_SR6 0x16
103 #define HBRIDGE9_REG_SR7 0x17
104 #define HBRIDGE9_REG_SR8 0x18
110 #define HBRIDGE9_REG_INFO_COMPANY_CODE 0x00
111 #define HBRIDGE9_REG_INFO_DEVICE_FAMILY 0x01
112 #define HBRIDGE9_REG_INFO_DEVICE_NO_1 0x02
113 #define HBRIDGE9_REG_INFO_DEVICE_NO_2 0x03
114 #define HBRIDGE9_REG_INFO_DEVICE_NO_3 0x04
115 #define HBRIDGE9_REG_INFO_DEVICE_NO_4 0x05
116 #define HBRIDGE9_REG_INFO_SILICON_VER 0x0A
117 #define HBRIDGE9_REG_INFO_SPI_MODE 0x10
118 #define HBRIDGE9_REG_INFO_SPI_CPHA_TEST 0x20
136 #define HBRIDGE9_SPI_CPHA_TEST 0x55
142 #define HBRIDGE9_ODD_PARITY 0x01
148 #define HBRIDGE9_CR0_PWM_FREQ_10p240 0x0000
149 #define HBRIDGE9_CR0_PWM_FREQ_12p288 0x2000
150 #define HBRIDGE9_CR0_PWM_FREQ_14p336 0x4000
151 #define HBRIDGE9_CR0_PWM_FREQ_16p384 0x6000
152 #define HBRIDGE9_CR0_PWM_FREQ_18p432 0x8000
153 #define HBRIDGE9_CR0_PWM_FREQ_20p480 0xA000
154 #define HBRIDGE9_CR0_PWM_FREQ_22p528 0xC000
155 #define HBRIDGE9_CR0_PWM_FREQ_24p576 0xE000
156 #define HBRIDGE9_CR0_PWM_FREQ_MASK 0xE000
157 #define HBRIDGE9_CR0_OUT6_POL_HIGH 0x1000
158 #define HBRIDGE9_CR0_OUT6_POL_LOW 0x0040
159 #define HBRIDGE9_CR0_OUT6_POL_MASK 0x1040
160 #define HBRIDGE9_CR0_OUT5_POL_HIGH 0x0800
161 #define HBRIDGE9_CR0_OUT5_POL_LOW 0x0020
162 #define HBRIDGE9_CR0_OUT5_POL_MASK 0x0820
163 #define HBRIDGE9_CR0_OUT4_POL_HIGH 0x0400
164 #define HBRIDGE9_CR0_OUT4_POL_LOW 0x0010
165 #define HBRIDGE9_CR0_OUT4_POL_MASK 0x0410
166 #define HBRIDGE9_CR0_OUT3_POL_HIGH 0x0200
167 #define HBRIDGE9_CR0_OUT3_POL_LOW 0x0008
168 #define HBRIDGE9_CR0_OUT3_POL_MASK 0x0208
169 #define HBRIDGE9_CR0_OUT2_POL_HIGH 0x0100
170 #define HBRIDGE9_CR0_OUT2_POL_LOW 0x0004
171 #define HBRIDGE9_CR0_OUT2_POL_MASK 0x0104
172 #define HBRIDGE9_CR0_OUT1_POL_HIGH 0x0080
173 #define HBRIDGE9_CR0_OUT1_POL_LOW 0x0002
174 #define HBRIDGE9_CR0_OUT1_POL_MASK 0x0082
180 #define HBRIDGE9_CR1_EX_OUT2_ON 0x8000
181 #define HBRIDGE9_CR1_EX_OUT1_ON 0x4000
182 #define HBRIDGE9_CR1_EX_OUT_MASK 0xC000
183 #define HBRIDGE9_CR1_OUT6_ON 0x2000
184 #define HBRIDGE9_CR1_OUT5_ON 0x1000
185 #define HBRIDGE9_CR1_OUT4_ON 0x0800
186 #define HBRIDGE9_CR1_OUT3_ON 0x0400
187 #define HBRIDGE9_CR1_OUT2_ON 0x0200
188 #define HBRIDGE9_CR1_OUT1_ON 0x0100
189 #define HBRIDGE9_CR1_OUT_MASK 0x3F00
190 #define HBRIDGE9_CR1_EMCY_NORMAL_MODE 0x0000
191 #define HBRIDGE9_CR1_EMCY_EMERGENCY_MODE 0x0080
192 #define HBRIDGE9_CR1_EMCY_MASK 0x00C0
193 #define HBRIDGE9_CR1_EX_OUT2_POL_HIGH 0x0020
194 #define HBRIDGE9_CR1_EX_OUT2_POL_LOW 0x0008
195 #define HBRIDGE9_CR1_EX_OUT2_POL_MASK 0x0028
196 #define HBRIDGE9_CR1_EX_OUT1_POL_HIGH 0x0010
197 #define HBRIDGE9_CR1_EX_OUT1_POL_LOW 0x0004
198 #define HBRIDGE9_CR1_EX_OUT1_POL_MASK 0x0014
199 #define HBRIDGE9_CR1_OUT_ON 0x0002
205 #define HBRIDGE9_CR2_DBN_EX2 0x8000
206 #define HBRIDGE9_CR2_DBN_EX1 0x4000
207 #define HBRIDGE9_CR2_DBN_EX_MASK 0xC000
208 #define HBRIDGE9_CR2_DBN_6 0x2000
209 #define HBRIDGE9_CR2_DBN_5 0x1000
210 #define HBRIDGE9_CR2_DBN_4 0x0800
211 #define HBRIDGE9_CR2_DBN_3 0x0400
212 #define HBRIDGE9_CR2_DBN_2 0x0200
213 #define HBRIDGE9_CR2_DBN_1 0x0100
214 #define HBRIDGE9_CR2_DBN_MASK 0x3F00
215 #define HBRIDGE9_CR2_ON_TIME_DUR_100MS 0x0000
216 #define HBRIDGE9_CR2_ON_TIME_DUR_120MS 0x0008
217 #define HBRIDGE9_CR2_ON_TIME_DUR_140MS 0x0010
218 #define HBRIDGE9_CR2_ON_TIME_DUR_160MS 0x0018
219 #define HBRIDGE9_CR2_ON_TIME_DUR_180MS 0x0020
220 #define HBRIDGE9_CR2_ON_TIME_DUR_200MS 0x0028
221 #define HBRIDGE9_CR2_ON_TIME_DUR_220MS 0x0030
222 #define HBRIDGE9_CR2_ON_TIME_DUR_240MS 0x0038
223 #define HBRIDGE9_CR2_ON_TIME_DUR_260MS 0x0040
224 #define HBRIDGE9_CR2_ON_TIME_DUR_280MS 0x0048
225 #define HBRIDGE9_CR2_ON_TIME_DUR_300MS 0x0050
226 #define HBRIDGE9_CR2_ON_TIME_DUR_320MS 0x0058
227 #define HBRIDGE9_CR2_ON_TIME_DUR_340MS 0x0060
228 #define HBRIDGE9_CR2_ON_TIME_DUR_360MS 0x0068
229 #define HBRIDGE9_CR2_ON_TIME_DUR_380MS 0x0070
230 #define HBRIDGE9_CR2_ON_TIME_DUR_400MS 0x0078
231 #define HBRIDGE9_CR2_ON_TIME_DUR_440MS 0x0080
232 #define HBRIDGE9_CR2_ON_TIME_DUR_480MS 0x0088
233 #define HBRIDGE9_CR2_ON_TIME_DUR_520MS 0x0090
234 #define HBRIDGE9_CR2_ON_TIME_DUR_560MS 0x0098
235 #define HBRIDGE9_CR2_ON_TIME_DUR_600MS 0x00A0
236 #define HBRIDGE9_CR2_ON_TIME_DUR_640MS 0x00A8
237 #define HBRIDGE9_CR2_ON_TIME_DUR_680MS 0x00B0
238 #define HBRIDGE9_CR2_ON_TIME_DUR_720MS 0x00B8
239 #define HBRIDGE9_CR2_ON_TIME_DUR_760MS 0x00C0
240 #define HBRIDGE9_CR2_ON_TIME_DUR_800MS 0x00C8
241 #define HBRIDGE9_CR2_ON_TIME_DUR_840MS 0x00D0
242 #define HBRIDGE9_CR2_ON_TIME_DUR_880MS 0x00D8
243 #define HBRIDGE9_CR2_ON_TIME_DUR_920MS 0x00E0
244 #define HBRIDGE9_CR2_ON_TIME_DUR_960MS 0x00E8
245 #define HBRIDGE9_CR2_ON_TIME_DUR_1000MS 0x00F0
246 #define HBRIDGE9_CR2_ON_TIME_DUR_1040MS 0x00F8
247 #define HBRIDGE9_CR2_ON_TIME_DUR_MASK 0x00F8
248 #define HBRIDGE9_CR2_BRAKING_DUR_0MS 0x0000
249 #define HBRIDGE9_CR2_BRAKING_DUR_100MS 0x0002
250 #define HBRIDGE9_CR2_BRAKING_DUR_200MS 0x0004
251 #define HBRIDGE9_CR2_BRAKING_DUR_100MS_IND 0x0006
252 #define HBRIDGE9_CR2_BRAKING_DUR_MASK 0x0006
258 #define HBRIDGE9_CR3_GFI 0x0080
259 #define HBRIDGE9_CR3_TSD_ACT 0x0040
260 #define HBRIDGE9_CR3_DITHN 0x0020
261 #define HBRIDGE9_CR3_NO_GROUP 0x0000
262 #define HBRIDGE9_CR3_GROUP_1_2 0x0002
263 #define HBRIDGE9_CR3_GROUP_1_3 0x0004
264 #define HBRIDGE9_CR3_GROUP_1_2_3 0x0006
265 #define HBRIDGE9_CR3_GROUP_4_5 0x0008
266 #define HBRIDGE9_CR3_GROUP_4_6 0x0010
267 #define HBRIDGE9_CR3_GROUP_4_5_6 0x0018
268 #define HBRIDGE9_CR3_GROUP_MASK 0x001E
274 #define HBRIDGE9_CR4_OCP1_SHIFT_BITS 0x0001
275 #define HBRIDGE9_CR4_OCP2_SHIFT_BITS 0x0006
276 #define HBRIDGE9_CR4_OCP3_SHIFT_BITS 0x000B
277 #define HBRIDGE9_CR5_OCP4_SHIFT_BITS 0x0001
278 #define HBRIDGE9_CR5_OCP5_SHIFT_BITS 0x0006
279 #define HBRIDGE9_CR5_OCP6_SHIFT_BITS 0x000B
280 #define HBRIDGE9_DUTY_CYCLE_6p25 0x0000
281 #define HBRIDGE9_DUTY_CYCLE_12p5 0x0001
282 #define HBRIDGE9_DUTY_CYCLE_18p75 0x0002
283 #define HBRIDGE9_DUTY_CYCLE_25 0x0003
284 #define HBRIDGE9_DUTY_CYCLE_31p25 0x0004
285 #define HBRIDGE9_DUTY_CYCLE_37p5 0x0005
286 #define HBRIDGE9_DUTY_CYCLE_43p75 0x0006
287 #define HBRIDGE9_DUTY_CYCLE_50 0x0007
288 #define HBRIDGE9_DUTY_CYCLE_56p25 0x0008
289 #define HBRIDGE9_DUTY_CYCLE_62p5 0x0009
290 #define HBRIDGE9_DUTY_CYCLE_68p75 0x000A
291 #define HBRIDGE9_DUTY_CYCLE_75 0x000B
292 #define HBRIDGE9_DUTY_CYCLE_81p25 0x000C
293 #define HBRIDGE9_DUTY_CYCLE_87p5 0x000D
294 #define HBRIDGE9_DUTY_CYCLE_93p75 0x000E
295 #define HBRIDGE9_DUTY_CYCLE_100 0x000F
296 #define HBRIDGE9_DUTY_CYCLE_MASK 0x001F
297 #define HBRIDGE9_CURRENT_1A 0x0010
298 #define HBRIDGE9_CURRENT_1p2A 0x0011
299 #define HBRIDGE9_CURRENT_1p4A 0x0012
300 #define HBRIDGE9_CURRENT_1p6A 0x0013
301 #define HBRIDGE9_CURRENT_1p8A 0x0014
302 #define HBRIDGE9_CURRENT_2A 0x0015
303 #define HBRIDGE9_CURRENT_2p2A 0x0016
304 #define HBRIDGE9_CURRENT_2p4A 0x0017
305 #define HBRIDGE9_CURRENT_2p6A 0x0018
306 #define HBRIDGE9_CURRENT_2p8A 0x0019
307 #define HBRIDGE9_CURRENT_3A 0x001A
308 #define HBRIDGE9_CURRENT_3p2A 0x001B
309 #define HBRIDGE9_CURRENT_3p4A 0x001C
310 #define HBRIDGE9_CURRENT_3p6A 0x001D
311 #define HBRIDGE9_CURRENT_3p8A 0x001E
312 #define HBRIDGE9_CURRENT_4A 0x001F
313 #define HBRIDGE9_CURRENT_MASK 0x001F
319 #define HBRIDGE9_CR6_HBDCL2 0x8000
320 #define HBRIDGE9_CR6_HBDCH2 0x4000
321 #define HBRIDGE9_CR6_HBDC2_MASK 0xC000
322 #define HBRIDGE9_CR6_STBY1 0x2000
323 #define HBRIDGE9_CR6_EXT2_VDT_1US 0x0000
324 #define HBRIDGE9_CR6_EXT2_VDT_2US 0x0800
325 #define HBRIDGE9_CR6_EXT2_VDT_3US 0x1000
326 #define HBRIDGE9_CR6_EXT2_VDT_4US 0x1800
327 #define HBRIDGE9_CR6_EXT2_VDT_MASK 0x1800
328 #define HBRIDGE9_CR6_EXT1_VDT_1US 0x0000
329 #define HBRIDGE9_CR6_EXT1_VDT_2US 0x0200
330 #define HBRIDGE9_CR6_EXT1_VDT_3US 0x0400
331 #define HBRIDGE9_CR6_EXT1_VDT_4US 0x0600
332 #define HBRIDGE9_CR6_EXT1_VDT_MASK 0x0600
333 #define HBRIDGE9_CR6_EXT2_VDS_OFF 0x0000
334 #define HBRIDGE9_CR6_EXT2_VDS_0p25V 0x0100
335 #define HBRIDGE9_CR6_EXT2_VDS_0p5V 0x0120
336 #define HBRIDGE9_CR6_EXT2_VDS_0p75V 0x0140
337 #define HBRIDGE9_CR6_EXT2_VDS_1V 0x0160
338 #define HBRIDGE9_CR6_EXT2_VDS_1p25V 0x0180
339 #define HBRIDGE9_CR6_EXT2_VDS_1p5V 0x01A0
340 #define HBRIDGE9_CR6_EXT2_VDS_1p75V 0x01C0
341 #define HBRIDGE9_CR6_EXT2_VDS_2V 0x01E0
342 #define HBRIDGE9_CR6_EXT2_VDS_MASK 0x01E0
343 #define HBRIDGE9_CR6_EXT1_VDS_OFF 0x0000
344 #define HBRIDGE9_CR6_EXT1_VDS_0p25V 0x0010
345 #define HBRIDGE9_CR6_EXT1_VDS_0p5V 0x0012
346 #define HBRIDGE9_CR6_EXT1_VDS_0p75V 0x0014
347 #define HBRIDGE9_CR6_EXT1_VDS_1V 0x0016
348 #define HBRIDGE9_CR6_EXT1_VDS_1p25V 0x0018
349 #define HBRIDGE9_CR6_EXT1_VDS_1p5V 0x001A
350 #define HBRIDGE9_CR6_EXT1_VDS_1p75V 0x001C
351 #define HBRIDGE9_CR6_EXT1_VDS_2V 0x001E
352 #define HBRIDGE9_CR6_EXT1_VDS_MASK 0x001E
358 #define HBRIDGE9_CR7_HBDCL1 0x8000
359 #define HBRIDGE9_CR7_HBDCH1 0x4000
360 #define HBRIDGE9_CR7_HBDC1_MASK 0xC000
361 #define HBRIDGE9_CR7_STBY2 0x2000
362 #define HBRIDGE9_CR7_ODCL6 0x1000
363 #define HBRIDGE9_CR7_ODCH6 0x0800
364 #define HBRIDGE9_CR7_ODC6_MASK 0x1800
365 #define HBRIDGE9_CR7_ODCL5 0x0400
366 #define HBRIDGE9_CR7_ODCH5 0x0200
367 #define HBRIDGE9_CR7_ODC5_MASK 0x0600
368 #define HBRIDGE9_CR7_ODCL4 0x0100
369 #define HBRIDGE9_CR7_ODCH4 0x0080
370 #define HBRIDGE9_CR7_ODC4_MASK 0x0180
371 #define HBRIDGE9_CR7_ODCL3 0x0040
372 #define HBRIDGE9_CR7_ODCH3 0x0020
373 #define HBRIDGE9_CR7_ODC3_MASK 0x0060
374 #define HBRIDGE9_CR7_ODCL2 0x0010
375 #define HBRIDGE9_CR7_ODCH2 0x0008
376 #define HBRIDGE9_CR7_ODC2_MASK 0x0018
377 #define HBRIDGE9_CR7_ODCL1 0x0004
378 #define HBRIDGE9_CR7_ODCH1 0x0002
379 #define HBRIDGE9_CR7_ODC1_MASK 0x0006
385 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_128 0x0000
386 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_64 0x0010
387 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_32 0x0020
388 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_16 0x0030
389 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_8 0x0040
390 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_4 0x0050
391 #define HBRIDGE9_CR8_KI_GAIN_1_OVER_2 0x0060
392 #define HBRIDGE9_CR8_KI_GAIN_1 0x0070
393 #define HBRIDGE9_CR8_KI_GAIN_MASK 0x0070
394 #define HBRIDGE9_CR8_KP_GAIN_2 0x0000
395 #define HBRIDGE9_CR8_KP_GAIN_4 0x0001
396 #define HBRIDGE9_CR8_KP_GAIN_8 0x0002
397 #define HBRIDGE9_CR8_KP_GAIN_16 0x0003
398 #define HBRIDGE9_CR8_KP_GAIN_32 0x0004
399 #define HBRIDGE9_CR8_KP_GAIN_64 0x0005
400 #define HBRIDGE9_CR8_KP_GAIN_128 0x0006
401 #define HBRIDGE9_CR8_KP_GAIN_256 0x0007
402 #define HBRIDGE9_CR8_KP_GAIN_MASK 0x0007
412 #define HBRIDGE9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
413 #define HBRIDGE9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
431 #define HBRIDGE9_MAP_MIKROBUS( cfg, mikrobus ) \
432 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
433 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
434 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
435 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
436 cfg.en_out = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
437 cfg.dout = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t hbridge9_read_info_register(hbridge9_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 9 read info register function.
@ HBRIDGE9_OK
Definition: hbridge9.h:492
err_t hbridge9_modify_register_bits(hbridge9_t *ctx, uint8_t reg, uint16_t clr_mask, uint16_t set_mask)
H-Bridge 9 modify register bits function.
err_t hbridge9_clear_all_status(hbridge9_t *ctx)
H-Bridge 9 clear all status function.
This file contains SPI specific macros, functions, etc.
err_t hbridge9_read_register_and_clear(hbridge9_t *ctx, uint8_t reg, uint16_t *data_out)
H-Bridge 9 read register and clear function.
spi_master_mode_t spi_mode
Definition: hbridge9.h:481
pin_name_t cs
Definition: hbridge9.h:473
err_t hbridge9_init(hbridge9_t *ctx, hbridge9_cfg_t *cfg)
H-Bridge 9 initialization function.
@ HBRIDGE9_ERROR
Definition: hbridge9.h:493
spi_master_t spi
Definition: hbridge9.h:455
hbridge9_return_value_t
H-Bridge 9 Click return value data.
Definition: hbridge9.h:491
spi_master_chip_select_polarity_t cs_polarity
Definition: hbridge9.h:482
pin_name_t en_out
Definition: hbridge9.h:476
err_t hbridge9_spi_transfer(hbridge9_t *ctx, uint8_t *data_in, uint8_t tx_len, uint8_t *data_out, uint8_t rx_len)
H-Bridge 9 spi transfer function.
pin_name_t chip_select
Definition: hbridge9.h:457
digital_out_t en_out
Definition: hbridge9.h:449
uint8_t global_status
Definition: hbridge9.h:459
err_t hbridge9_read_register(hbridge9_t *ctx, uint8_t reg, uint16_t *data_out)
H-Bridge 9 read register function.
H-Bridge 9 Click context object.
Definition: hbridge9.h:447
err_t hbridge9_check_communication(hbridge9_t *ctx)
H-Bridge 9 check communication function.
err_t hbridge9_write_register(hbridge9_t *ctx, uint8_t reg, uint16_t data_in)
H-Bridge 9 write register function.
pin_name_t miso
Definition: hbridge9.h:470
void hbridge9_cfg_setup(hbridge9_cfg_t *cfg)
H-Bridge 9 configuration object setup function.
pin_name_t dout
Definition: hbridge9.h:477
pin_name_t mosi
Definition: hbridge9.h:471
H-Bridge 9 Click configuration object.
Definition: hbridge9.h:468
digital_in_t dout
Definition: hbridge9.h:452
pin_name_t sck
Definition: hbridge9.h:472
void hbridge9_set_en_out_pin(hbridge9_t *ctx, uint8_t state)
H-Bridge 9 set en out pin function.
err_t hbridge9_set_default(hbridge9_t *ctx)
H-Bridge 9 set default function.
uint32_t spi_speed
Definition: hbridge9.h:480
err_t hbridge9_default_cfg(hbridge9_t *ctx)
H-Bridge 9 default configuration function.
void hbridge9_send_actuation_pulse(hbridge9_t *ctx)
H-Bridge 9 send actuation pulse function.
uint8_t hbridge9_get_dout_pin(hbridge9_t *ctx)
H-Bridge 9 get dout pin function.