39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
75#define SILENTSTEP2_REG_GCONF 0x00
76#define SILENTSTEP2_REG_GSTAT 0x01
77#define SILENTSTEP2_REG_IOIN 0x04
78#define SILENTSTEP2_REG_IHOLD_IRUN 0x10
79#define SILENTSTEP2_REG_TPOWERDOWN 0x11
80#define SILENTSTEP2_REG_TSTEP 0x12
81#define SILENTSTEP2_REG_TPWMTHRS 0x13
82#define SILENTSTEP2_REG_TCOOLTHRS 0x14
83#define SILENTSTEP2_REG_THIGH 0x15
84#define SILENTSTEP2_REG_XDIRECT 0x2D
85#define SILENTSTEP2_REG_VDCMIN 0x33
86#define SILENTSTEP2_REG_MSLUT0 0x60
87#define SILENTSTEP2_REG_MSLUT1 0x61
88#define SILENTSTEP2_REG_MSLUT2 0x62
89#define SILENTSTEP2_REG_MSLUT3 0x63
90#define SILENTSTEP2_REG_MSLUT4 0x64
91#define SILENTSTEP2_REG_MSLUT5 0x65
92#define SILENTSTEP2_REG_MSLUT6 0x66
93#define SILENTSTEP2_REG_MSLUT7 0x67
94#define SILENTSTEP2_REG_MSLUTSEL 0x68
95#define SILENTSTEP2_REG_MSLUTSTART 0x69
96#define SILENTSTEP2_REG_MSCNT 0x6A
97#define SILENTSTEP2_REG_MSCURACT 0x6B
98#define SILENTSTEP2_REG_CHOPCONF 0x6C
99#define SILENTSTEP2_REG_COOLCONF 0x6D
100#define SILENTSTEP2_REG_DCCTRL 0x6E
101#define SILENTSTEP2_REG_DRV_STATUS 0x6F
102#define SILENTSTEP2_REG_PWMCONF 0x70
103#define SILENTSTEP2_REG_PWM_SCALE 0x71
104#define SILENTSTEP2_REG_ENCM_CTRL 0x72
105#define SILENTSTEP2_REG_LOST_STEPS 0x73
106#define SILENTSTEP2_REG_EXP_IN_PORT 0x00
107#define SILENTSTEP2_REG_EXP_OUT_PORT 0x01
108#define SILENTSTEP2_REG_EXP_POL_INV 0x02
109#define SILENTSTEP2_REG_EXP_CONFIG 0x03
127#define SILENTSTEP2_GSTAT_RESET 0x00000001ul
128#define SILENTSTEP2_GSTAT_DRV_ERR 0x00000002ul
129#define SILENTSTEP2_GSTAT_UV_CP 0x00000004ul
135#define SILENTSTEP2_GCONF_I_SC_AN_OP_NORMAL 0x00
136#define SILENTSTEP2_GCONF_I_SC_AN_AIN 0x01
137#define SILENTSTEP2_GCONF_INT_RSE_OP_NORMAL 0x00
138#define SILENTSTEP2_GCONF_INT_RSE_INT_RSE 0x01
139#define SILENTSTEP2_GCONF_DISABLE 0x00
140#define SILENTSTEP2_GCONF_ENABLE 0x01
146#define SILENTSTEP2_THIGH_DEFAULT 0x00000300ul
147#define SILENTSTEP2_THIGH_MAX 0x000FFFFFul
155#define SILENTSTEP2_TCOOLTHRS_DEFAULT 0x00002700ul
156#define SILENTSTEP2_TCOOLTHRS_MAX 0x000FFFFFul
164#define SILENTSTEP2_CHOPCONF_SEMIN_0 0x00
165#define SILENTSTEP2_CHOPCONF_SEMIN_BIT_MASK 0x0F
166#define SILENTSTEP2_CHOPCONF_SEUP_1 0x00
167#define SILENTSTEP2_CHOPCONF_SEUP_2 0x01
168#define SILENTSTEP2_CHOPCONF_SEUP_3 0x02
169#define SILENTSTEP2_CHOPCONF_SEUP_8 0x03
170#define SILENTSTEP2_CHOPCONF_SEMAX_0 0x00
171#define SILENTSTEP2_CHOPCONF_SEMAX_BIT_MASK 0x0F
172#define SILENTSTEP2_CHOPCONF_SEDN_32 0x00
173#define SILENTSTEP2_CHOPCONF_SEDN_8 0x01
174#define SILENTSTEP2_CHOPCONF_SEDN_2 0x02
175#define SILENTSTEP2_CHOPCONF_SEDN_1 0x03
176#define SILENTSTEP2_CHOPCONF_SEIMIN_1_2 0x00
177#define SILENTSTEP2_CHOPCONF_SEIMIN_1_4 0x01
178#define SILENTSTEP2_CHOPCONF_SGT_M64 0x00
179#define SILENTSTEP2_CHOPCONF_SGT_P64 0x7F
180#define SILENTSTEP2_CHOPCONF_SFILT_MODE_STD 0x00
181#define SILENTSTEP2_CHOPCONF_SFILT_MODE_FLTR 0x01
189#define SILENTSTEP2_IHOLD_10_32 0x0A
190#define SILENTSTEP2_IHOLD_BIT_MASK 0x1F
191#define SILENTSTEP2_IRUN_10_32 0x0A
192#define SILENTSTEP2_IRUN_BIT_MASK 0x1F
193#define SILENTSTEP2_IHOLDDELAY_PWR_DOWN 0x00
194#define SILENTSTEP2_IHOLDDELAY_32 0x05
195#define SILENTSTEP2_IHOLDDELAY_BIT_MASK 0x0F
201#define SILENTSTEP2_TOFF_DIS 0x00
202#define SILENTSTEP2_TOFF_NCLK_140 0x04
203#define SILENTSTEP2_TOFF_BIT_MASK 0x0F
209#define SILENTSTEP2_STEP_SPEED_MIN 1
210#define SILENTSTEP2_STEP_SPEED_MAX 100
211#define SILENTSTEP2_ANGLE_360_DEGREES 360.0f
217#define SILENTSTEP2_CHOPCONF_CHM_MODE_STND 0x00
218#define SILENTSTEP2_CHOPCONF_CHM_CONST_OFF_TIME 0x01
219#define SILENTSTEP2_CHOPCONF_CHM_BIT_MASK 0x00004000ul
220#define SILENTSTEP2_CHOPCONF_HE_OS_M3 0x00
221#define SILENTSTEP2_CHOPCONF_HE_OS_M2 0x01
222#define SILENTSTEP2_CHOPCONF_HE_OS_M1 0x02
223#define SILENTSTEP2_CHOPCONF_HE_OS_0 0x03
224#define SILENTSTEP2_CHOPCONF_HE_OS_1 0x04
225#define SILENTSTEP2_CHOPCONF_HE_OS_2 0x05
226#define SILENTSTEP2_CHOPCONF_HE_OS_3 0x06
227#define SILENTSTEP2_CHOPCONF_HE_OS_4 0x07
228#define SILENTSTEP2_CHOPCONF_HE_OS_5 0x08
229#define SILENTSTEP2_CHOPCONF_HE_OS_6 0x09
230#define SILENTSTEP2_CHOPCONF_HE_OS_7 0x0A
231#define SILENTSTEP2_CHOPCONF_HE_OS_8 0x0B
232#define SILENTSTEP2_CHOPCONF_HE_OS_9 0x0C
233#define SILENTSTEP2_CHOPCONF_HE_OS_10 0x0D
234#define SILENTSTEP2_CHOPCONF_HE_OS_11 0x0E
235#define SILENTSTEP2_CHOPCONF_HE_OS_12 0x0F
236#define SILENTSTEP2_CHOPCONF_HE_OS_BIT_MASK 0x00000780ul
237#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_0 0x00
238#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_1 0x01
239#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_2 0x02
240#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_3 0x03
241#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_4 0x04
242#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_5 0x05
243#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_6 0x06
244#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_7 0x07
245#define SILENTSTEP2_CHOPCONF_HSTRT_TFD_BIT_MASK 0x00000070ul
251#define SILENTSTEP2_MSLUT_SEL_0 0x00
252#define SILENTSTEP2_MSLUT_SEL_1 0x01
253#define SILENTSTEP2_MSLUT_SEL_2 0x02
254#define SILENTSTEP2_MSLUT_SEL_3 0x03
255#define SILENTSTEP2_MSLUT_SEL_4 0x04
256#define SILENTSTEP2_MSLUT_SEL_5 0x05
257#define SILENTSTEP2_MSLUT_SEL_6 0x06
258#define SILENTSTEP2_MSLUT_SEL_7 0x07
259#define SILENTSTEP2_MSLUTSEL_WIDTH_BIT_MASK 0x000000FFul
260#define SILENTSTEP2_MSLUTSEL_SEG_BIT_MASK 0x00FFFFFFul
266#define SILENTSTEP2_MSLUTSTART_SIN_BIT_MASK 0x000000FFul
267#define SILENTSTEP2_MSLUTSTART_SIN90_BIT_MASK 0x000000FFul
273#define SILENTSTEP2_CHOPCONF_MRES_BIT_MASK 0xF0FFFFFFul
274#define SILENTSTEP2_CHOPCONF_DEDGE_BIT_MASK 0xDFFFFFFFul
275#define SILENTSTEP2_CHOPCONF_INTPOL_BIT_MASK 0xEFFFFFFFul
276#define SILENTSTEP2_CHOPCONF_TBL_BIT_MASK 0xFFFE7FFFul
277#define SILENTSTEP2_CHOPCONF_TOFF_BIT_MASK 0xFFFFFFF0ul
283#define SILENTSTEP2_PIN_NONE 0x00
284#define SILENTSTEP2_PIN_EN 0x01
285#define SILENTSTEP2_PIN_FT1 0x02
286#define SILENTSTEP2_PIN_FT2 0x04
287#define SILENTSTEP2_PIN_ALL 0x07
293#define SILENTSTEP2_DIRECTION_COUNTERCLOCKWISE 0
294#define SILENTSTEP2_DIRECTION_CLOCKWISE 1
300#define SILENTSTEP2_STEP_DELAY_DEFAULT_100US 100ul
307#define SILENTSTEP2_DEVICE_ADDRESS_0 0x70
308#define SILENTSTEP2_DEVICE_ADDRESS_1 0x72
309#define SILENTSTEP2_DEVICE_ADDRESS_2 0x74
310#define SILENTSTEP2_DEVICE_ADDRESS_3 0x76
320#define SILENTSTEP2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
321#define SILENTSTEP2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
339#define SILENTSTEP2_MAP_MIKROBUS( cfg, mikrobus ) \
340 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
341 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
342 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
343 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
344 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
345 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
346 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
347 cfg.stp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
348 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t silentstep2_make_one_step(silentstep2_t *ctx, uint8_t step_speed)
Silent Step 2 make the one step function.
err_t silentstep2_set_intpol(silentstep2_t *ctx, uint8_t intpol_en)
Silent Step 2 enable the actual microstep resolution function.
uint8_t silentstep2_get_interrupt(silentstep2_t *ctx)
Silent Step 2 get the interrupt function.
err_t silentstep2_get_gstat(silentstep2_t *ctx, uint32_t *gstat)
Silent Step 2 get global status function.
err_t silentstep2_get_drv_status(silentstep2_t *ctx, silentstep2_drv_status_t *drv_status)
Silent Step 2 get driver status error flags function.
err_t silentstep2_set_dedge(silentstep2_t *ctx, uint8_t dedge_en)
Silent Step 2 sets the step impulsen function.
err_t silentstep2_set_coolconf(silentstep2_t *ctx, silentstep2_coolconf_t coolconf)
Silent Step 2 sets the coolStep smart current control function.
err_t silentstep2_set_tcoolthrs(silentstep2_t *ctx, uint32_t tcoolthrs)
Silent Step 2 sets lower threshold velocity for switching on smart energy function.
err_t silentstep2_set_ihold_irun(silentstep2_t *ctx, uint8_t ihold, uint8_t irun, uint8_t ihold_delay)
Silent Step 2 sets driver current control function.
err_t silentstep2_set_tbl_blank_time(silentstep2_t *ctx, silentstep2_tbl_t tbl)
Silent Step 2 enable the blank time select function.
err_t silentstep2_set_mstep_res(silentstep2_t *ctx, silentstep2_mres_t step_width)
Silent Step 2 sets the micro step resolution function.
err_t silentstep2_get_diag1(silentstep2_t *ctx, uint8_t *diag1)
Silent Step 2 get the diagnostics output DIAG1 function.
err_t silentstep2_get_diag0(silentstep2_t *ctx, uint8_t *diag0)
Silent Step 2 get the diagnostics output DIAG0 function.
err_t silentstep2_set_pwmconf(silentstep2_t *ctx, silentstep2_pwmconf_t pwmconf)
Silent Step 2 sets the voltage PWM Mode stealthChop function.
err_t silentstep2_set_mslutstart(silentstep2_t *ctx, uint32_t start_sin, uint32_t start_sin90)
Silent Step 2 sets the absolute current microstep table function.
err_t silentstep2_set_mslutsel(silentstep2_t *ctx, uint32_t lut_seg_str, uint32_t lut_width_sel)
Silent Step 2 sets the microstep segments function.
err_t silentstep2_reg_write(silentstep2_t *ctx, uint8_t reg, uint32_t data_in)
Silent Step 2 data writing function.
err_t silentstep2_set_mslut(silentstep2_t *ctx, uint8_t mslut_sel, uint32_t mslut)
Silent Step 2 sets the microstep table entries function.
err_t silentstep2_set_pins(silentstep2_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Silent Step 2 sets the pin states function.
void silentstep2_set_step(silentstep2_t *ctx, uint8_t step)
Silent Step 2 set the step pin state function.
void silentstep2_cfg_setup(silentstep2_cfg_t *cfg)
Silent Step 2 configuration object setup function.
err_t silentstep2_init(silentstep2_t *ctx, silentstep2_cfg_t *cfg)
Silent Step 2 initialization function.
void silentstep2_set_direction(silentstep2_t *ctx, uint8_t dir)
Silent Step 2 sets the clockwise or counterclockwise direction movement function.
err_t silentstep2_reg_read(silentstep2_t *ctx, uint8_t reg, uint32_t *data_in)
Silent Step 2 data reading function.
err_t silentstep2_set_gconf(silentstep2_t *ctx, silentstep2_gconf_t gconf)
Silent Step 2 sets global configuration function.
err_t silentstep2_switch_off(silentstep2_t *ctx)
Silent Step 2 sets the power OFF function.
err_t silentstep2_set_toff(silentstep2_t *ctx, uint8_t off_time)
Silent Step 2 sets the off time and driver enable function.
err_t silentstep2_default_cfg(silentstep2_t *ctx)
Silent Step 2 default configuration function.
err_t silentstep2_set_h_end_strt(silentstep2_t *ctx, uint8_t chm, uint8_t h_end_offset, uint8_t hstrt_tfd)
Silent Step 2 sets the chopper mode config function.
err_t silentstep2_port_exp_write(silentstep2_t *ctx, uint8_t reg, uint8_t data_in)
Silent Step 2 port expander data writing function.
err_t silentstep2_input_enable(silentstep2_t *ctx)
Silent Step 2 enable input function.
err_t silentstep2_port_exp_read(silentstep2_t *ctx, uint8_t reg, uint8_t *data_out)
Silent Step 2 port expander data reading function.
err_t silentstep2_set_thigh(silentstep2_t *ctx, uint32_t thigh)
Silent Step 2 sets the velocity setting function.
err_t silentstep2_rotate_by_angle(silentstep2_t *ctx, uint8_t step_speed, float angle, uint16_t res_360)
Silent Step 2 rotates the shaft through a desired angle function.
silentstep2_drv_t
Silent Step 2 Click driver selector.
Definition silentstep2.h:358
@ SILENTSTEP2_DRV_SEL_I2C
Definition silentstep2.h:360
@ SILENTSTEP2_DRV_SEL_SPI
Definition silentstep2.h:359
silentstep2_return_value_t
Silent Step 2 Click return value data.
Definition silentstep2.h:494
@ SILENTSTEP2_OK
Definition silentstep2.h:495
@ SILENTSTEP2_ERROR
Definition silentstep2.h:496
silentstep2_tbl_t
Silent Step 2 Click comparator blank time value data.
Definition silentstep2.h:523
@ SILENTSTEP2_TBL_CLOCKS_36
Definition silentstep2.h:526
@ SILENTSTEP2_TBL_CLOCKS_16
Definition silentstep2.h:524
@ SILENTSTEP2_TBL_CLOCKS_54
Definition silentstep2.h:527
@ SILENTSTEP2_TBL_CLOCKS_24
Definition silentstep2.h:525
silentstep2_mres_t
Silent Step 2 Click reduced microstep resolution value data.
Definition silentstep2.h:505
@ SILENTSTEP2_MRES_128
Definition silentstep2.h:507
@ SILENTSTEP2_MRES_32
Definition silentstep2.h:509
@ SILENTSTEP2_MRES_64
Definition silentstep2.h:508
@ SILENTSTEP2_MRES_8
Definition silentstep2.h:511
@ SILENTSTEP2_MRES_2
Definition silentstep2.h:513
@ SILENTSTEP2_MRES_16
Definition silentstep2.h:510
@ SILENTSTEP2_MRES_256
Definition silentstep2.h:506
@ SILENTSTEP2_MRES_4
Definition silentstep2.h:512
@ SILENTSTEP2_MRES_NATIVE
Definition silentstep2.h:514
This file contains SPI specific macros, functions, etc.
Silent Step 2 Click configuration object.
Definition silentstep2.h:390
uint32_t step_delay
Definition silentstep2.h:401
pin_name_t stp
Definition silentstep2.h:398
uint32_t i2c_speed
Definition silentstep2.h:403
spi_master_chip_select_polarity_t cs_polarity
Definition silentstep2.h:408
pin_name_t sck
Definition silentstep2.h:395
spi_master_mode_t spi_mode
Definition silentstep2.h:407
pin_name_t mosi
Definition silentstep2.h:394
uint32_t spi_speed
Definition silentstep2.h:406
pin_name_t dir
Definition silentstep2.h:397
pin_name_t scl
Definition silentstep2.h:391
pin_name_t int_pin
Definition silentstep2.h:399
pin_name_t miso
Definition silentstep2.h:393
pin_name_t sda
Definition silentstep2.h:392
pin_name_t cs
Definition silentstep2.h:396
uint8_t i2c_address
Definition silentstep2.h:404
Silent Step 2 Click smart energy control coolStep and stallGuard2 object.
Definition silentstep2.h:443
uint8_t sedn
Definition silentstep2.h:447
uint8_t seimin
Definition silentstep2.h:448
uint8_t sfilt
Definition silentstep2.h:450
uint8_t sgt
Definition silentstep2.h:449
uint8_t semin
Definition silentstep2.h:444
uint8_t semax
Definition silentstep2.h:446
uint8_t seup
Definition silentstep2.h:445
Silent Step 2 Click stallGuard2 value and driver error flags object.
Definition silentstep2.h:474
uint8_t s2gb
Definition silentstep2.h:482
uint16_t sg_result
Definition silentstep2.h:475
uint8_t s2ga
Definition silentstep2.h:481
uint8_t stst
Definition silentstep2.h:485
uint8_t stall_guard
Definition silentstep2.h:478
uint8_t olb
Definition silentstep2.h:484
uint8_t cs_actual
Definition silentstep2.h:477
uint8_t ola
Definition silentstep2.h:483
uint8_t otpw
Definition silentstep2.h:480
uint8_t ot
Definition silentstep2.h:479
uint8_t fsactive
Definition silentstep2.h:476
Silent Step 2 Click global configuration object.
Definition silentstep2.h:417
uint8_t direct_mode
Definition silentstep2.h:434
uint8_t internal_rsense
Definition silentstep2.h:419
uint8_t diag1_index
Definition silentstep2.h:427
uint8_t diag0_int_pushpull
Definition silentstep2.h:430
uint8_t diag1_stall
Definition silentstep2.h:426
uint8_t i_scale_analog
Definition silentstep2.h:418
uint8_t en_pwm_mode
Definition silentstep2.h:420
uint8_t diag0_stall
Definition silentstep2.h:425
uint8_t small_hysteresis
Definition silentstep2.h:432
uint8_t diag0_otpw
Definition silentstep2.h:424
uint8_t diag1_onstate
Definition silentstep2.h:428
uint8_t stop_enable
Definition silentstep2.h:433
uint8_t diag0_error
Definition silentstep2.h:423
uint8_t diag1_pushpull
Definition silentstep2.h:431
uint8_t diag1_steps_skipped
Definition silentstep2.h:429
uint8_t shaft
Definition silentstep2.h:422
uint8_t enc_commutation
Definition silentstep2.h:421
Silent Step 2 Click voltage mode pwm stealthChop object.
Definition silentstep2.h:459
uint8_t pwm_grad
Definition silentstep2.h:461
uint8_t pwm_autoscale
Definition silentstep2.h:463
uint8_t pwm_symmetric
Definition silentstep2.h:464
uint8_t freewheel
Definition silentstep2.h:465
uint8_t pwm_ampl
Definition silentstep2.h:460
uint8_t pwm_freq
Definition silentstep2.h:462
Silent Step 2 Click context object.
Definition silentstep2.h:369
uint32_t step_delay
Definition silentstep2.h:381
spi_master_t spi
Definition silentstep2.h:376
digital_out_t stp
Definition silentstep2.h:371
digital_in_t int_pin
Definition silentstep2.h:373
i2c_master_t i2c
Definition silentstep2.h:375
uint8_t slave_address
Definition silentstep2.h:378
pin_name_t chip_select
Definition silentstep2.h:379
digital_out_t dir
Definition silentstep2.h:370