stepper15  2.0.0.0
stepper15.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 STEPPER15_H
29 #define STEPPER15_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 
40 
61 #define STEPPER15_REG_INPUT_PORT 0x00
62 #define STEPPER15_REG_OUTPUT_PORT 0x01
63 #define STEPPER15_REG_POLARITY_INVERSION 0x02
64 #define STEPPER15_REG_CONFIGURATION 0x03
65 
70 #define STEPPER15_REG_FAULT_STATUS 0x00
71 #define STEPPER15_REG_DIAG_STATUS_1 0x01
72 #define STEPPER15_REG_DIAG_STATUS_2 0x02
73 #define STEPPER15_REG_CTRL_1 0x03
74 #define STEPPER15_REG_CTRL_2 0x04
75 #define STEPPER15_REG_CTRL_3 0x05
76 #define STEPPER15_REG_CTRL_4 0x06
77 #define STEPPER15_REG_CTRL_5 0x07
78 #define STEPPER15_REG_CTRL_6 0x08
79 #define STEPPER15_REG_CTRL_7 0x09
80 #define STEPPER15_REG_CTRL_8 0x0A
81  // stepper15_reg
83 
98 #define STEPPER15_SET_DIRECTION_BIT_MASK 0xFB
99 #define STEPPER15_SET_DIRECTION_CCW 0x00
100 #define STEPPER15_SET_DIRECTION_CW 0x04
101 
106 #define STEPPER15_SET_WORK_MODE_BIT_MASK 0xFE
107 #define STEPPER15_SET_WORK_MODE_SLEEP 0x00
108 #define STEPPER15_SET_WORK_MODE_ENABLE_DEVICE 0x01
109 
114 #define STEPPER15_SET_OUT_MODE_BIT_MASK 0xFD
115 #define STEPPER15_SET_OUT_MODE_DEVICE_OUTPUTS_ENABLE 0x00
116 #define STEPPER15_SET_OUT_MODE_DEVICE_OUTPUTS_DISABLE 0x02
117 
122 #define STEPPER15_SET_CONFIG_DEFAULT 0xF8
123 
128 #define STEPPER15_FAULT_ST_OL_MASK 0x01
129 #define STEPPER15_FAULT_ST_OT_MASK 0x02
130 #define STEPPER15_FAULT_ST_STL_SLIP_MASK 0x04
131 #define STEPPER15_FAULT_ST_OCP_MASK 0x08
132 #define STEPPER15_FAULT_ST_CPUV_MASK 0x10
133 #define STEPPER15_FAULT_ST_UVLO_MASK 0x20
134 #define STEPPER15_FAULT_ST_SPI_ERROR_MASK 0x40
135 #define STEPPER15_FAULT_ST_FAULT_MASK 0x80
136 
141 #define STEPPER15_DIAG_1_OCP_HS1_A_MASK 0x01
142 #define STEPPER15_DIAG_1_OCP_LS1_A_MASK 0x02
143 #define STEPPER15_DIAG_1_OCP_HS2_A_MASK 0x04
144 #define STEPPER15_DIAG_1_OCP_LS2_A_MASK 0x08
145 #define STEPPER15_DIAG_1_OCP_HS1_B_MASK 0x10
146 #define STEPPER15_DIAG_1_OCP_LS1_B_MASK 0x20
147 #define STEPPER15_DIAG_1_OCP_HS2_B_MASK 0x40
148 #define STEPPER15_DIAG_1_OCP_LS2_B_MASK 0x80
149 
155 #define STEPPER15_DIAG_2_OL_A_MASK 0x01
156 #define STEPPER15_DIAG_2_OL_B_MASK 0x02
157 #define STEPPER15_DIAG_2_SLIP_MASK 0x04
158 #define STEPPER15_DIAG_2_STALL_MASK 0x08
159 #define STEPPER15_DIAG_2_STL_LRN_OK_MASK 0x10
160 #define STEPPER15_DIAG_2_OTS_MASK 0x20
161 #define STEPPER15_DIAG_2_OTW_MASK 0x40
162 #define STEPPER15_DIAG_2_UTW_MASK 0x80
163 
169 #define STEPPER15_CTRL1_SLEW_RATE_MASK 0x03
170 #define STEPPER15_CTRL1_EN_NSR_MASK 0x04
171 #define STEPPER15_CTRL1_RSVD1_MASK 0x08
172 #define STEPPER15_CTRL1_TRQ_DAC_MASK 0xF0
173 #define STEPPER15_SET_CTRL1_TRQ_100 0x00
174 #define STEPPER15_SET_CTRL1_TRQ_93_75 0x10
175 #define STEPPER15_SET_CTRL1_TRQ_87_5 0x20
176 #define STEPPER15_SET_CTRL1_TRQ_81_25 0x30
177 #define STEPPER15_SET_CTRL1_TRQ_75 0x40
178 #define STEPPER15_SET_CTRL1_TRQ_68_75 0x50
179 #define STEPPER15_SET_CTRL1_TRQ_62_5 0x60
180 #define STEPPER15_SET_CTRL1_TRQ_56_25 0x70
181 #define STEPPER15_SET_CTRL1_TRQ_50 0x80
182 #define STEPPER15_SET_CTRL1_TRQ_43_75 0x90
183 #define STEPPER15_SET_CTRL1_TRQ_37_5 0xA0
184 #define STEPPER15_SET_CTRL1_TRQ_31_25 0xB0
185 #define STEPPER15_SET_CTRL1_TRQ_25 0xC0
186 #define STEPPER15_SET_CTRL1_TRQ_18_75 0xD0
187 #define STEPPER15_SET_CTRL1_TRQ_12_5 0xE0
188 #define STEPPER15_SET_CTRL1_TRQ_6_25 0xF0
189 
190 
196 #define STEPPER15_CTRL2_DECAY_MASK 0x07
197 #define STEPPER15_CTRL2_TOFF_MASK 0x18
198 #define STEPPER15_CTRL2_RSVD2_MASK 0x60
199 #define STEPPER15_CTRL2_DIS_OUT_MASK 0x80
200 #define STEPPER15_SET_CTRL2_OUTPUT_ENABLE 0x00
201 #define STEPPER15_SET_CTRL2_OUTPUT_DISABLE 0x80
202 #define STEPPER15_SET_CTRL2_TOFF_7_us 0x00
203 #define STEPPER15_SET_CTRL2_TOFF_16_us 0x08
204 #define STEPPER15_SET_CTRL2_TOFF_24_us 0x10
205 #define STEPPER15_SET_CTRL2_TOFF_32_us 0x18
206 #define STEPPER15_SET_CTRL2_SMART_TUNE_RIPPLE_CTRL 0x07
207 
213 #define STEPPER15_CTRL3_MICROSTEP_MODE_MASK 0x0F
214 #define STEPPER15_CTRL3_SPI_STEP_MASK 0x10
215 #define STEPPER15_CTRL3_SPI_DIR_MASK 0x20
216 #define STEPPER15_CTRL3_STEP_MASK 0x40
217 #define STEPPER15_CTRL3_DIR_MASK 0x80
218 #define STEPPER15_SET_SPI_DIR_INPUT_PIN 0x00
219 #define STEPPER15_SET_SPI_DIR_SPI 0x80
220 #define STEPPER15_SET_SPI_STEP_INPUT_PIN 0x00
221 #define STEPPER15_SET_SPI_STEP_SPI 0x40
222 #define STEPPER15_SET_CTRL3_SET_MICROSTEP_MODE_FULL_STEP 0x00
223 
229 #define STEPPER15_CTRL4_TW_REP_MASK 0x01
230 #define STEPPER15_CTRL4_OTSD_MODE_MASK 0x02
231 #define STEPPER15_CTRL4_OCP_MODE_MASK 0x04
232 #define STEPPER15_CTRL4_EN_OL_MASK 0x08
233 #define STEPPER15_CTRL4_LOCK_MASK 0x70
234 #define STEPPER15_CTRL4_CLR_FLT_MASK 0x80
235 #define STEPPER15_SET_CTRL4_CLR_FLT 0x80
236 #define STEPPER15_SET_CTRL4_UNLOCK_ALL_REG 0x30
237 
243 #define STEPPER15_CTRL5_SLIP_REP_MASK 0x01
244 #define STEPPER15_CTRL5_EN_SLIP_MASK 0x02
245 #define STEPPER15_CTRL5_EN_STLFCHG_MASK 0x04
246 #define STEPPER15_CTRL5_STL_REP_MASK 0x08
247 #define STEPPER15_SET_CTRL5_REPORTED_ON_FAULT 0x08
248 
254 #define STEPPER15_CTRL6_STALL_TH_MASK 0xFF
255 
261 #define STEPPER15_CTRL7_STALL_TH_MASK 0xFF
262 
268 #define STEPPER15_CTRL8_REV_ID_MASK 0x0F
269 #define STEPPER15_CTRL8_STL_UPDATE_MODE_MASK 0x10
270 #define STEPPER15_CTRL8_UTW_REP_MASK 0x20
271 #define STEPPER15_CTRL8_RSVD3_MASK 0xC0
272 
278 #define STEPPER15_SET_DEV_ADDR 0x70
279  // stepper15_set
281 
291 #define STEPPER15_DIRECTION_COUNTERCLOCKWISE 0
292 #define STEPPER15_DIRECTION_CLOCKWISE 1
293  // direction
295 
305 #define STEPPER15_WORK_MODE_SLEEP 0
306 #define STEPPER15_WORK_MODE_ENABLE_DEVICE 1
307  // work_mode
309 
319 #define STEPPER15_OUTPUT_MODE_OUTPUTS_DISABLE 0
320 #define STEPPER15_OUTPUT_MODE_OUTPUTS_ENABLE 1
321  // output_mode
323 
333 #define STEPPER15_FAULT_CONDITION 0
334 #define STEPPER15_CORRECT_CONDITION 1
335  // fault_condition
337 
352 #define STEPPER15_MAP_MIKROBUS( cfg, mikrobus ) \
353  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
354  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
355  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
356  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
357  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
358  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
359  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
360  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
361  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
362  // stepper15_map // stepper15
365 
370 typedef struct stepper15_s
371 {
372  digital_out_t rst;
373  digital_out_t pwm;
375  digital_in_t int_pin;
377  i2c_master_t i2c;
378  spi_master_t spi;
380  uint8_t slave_address;
381  pin_name_t chip_select;
384 
389 typedef struct
390 {
391  pin_name_t scl;
392  pin_name_t sda;
393  pin_name_t miso;
394  pin_name_t mosi;
395  pin_name_t sck;
396  pin_name_t cs;
398  pin_name_t rst;
399  pin_name_t pwm;
400  pin_name_t int_pin;
402  uint32_t i2c_speed;
403  uint8_t i2c_address;
405  uint32_t spi_speed;
406  spi_master_mode_t spi_mode;
407  spi_master_chip_select_polarity_t cs_polarity;
410 
415 typedef enum
416 {
418  STEPPER15_ERROR = -1
419 
421 
438 
454 
469 
485 err_t stepper15_i2c_write ( stepper15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
486 
502 err_t stepper15_i2c_read ( stepper15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
503 
519 err_t stepper15_spi_write ( stepper15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
520 
535 err_t stepper15_spi_read ( stepper15_t *ctx, uint8_t reg, uint8_t *data_out );
536 
549 
563 
578 
594 err_t stepper15_make_one_step ( stepper15_t *ctx, uint8_t step_speed );
595 
613 err_t stepper15_set_direction ( stepper15_t *ctx, uint8_t direction );
614 
632 err_t stepper15_set_work_mode ( stepper15_t *ctx, uint8_t work_mode );
633 
651 err_t stepper15_set_output_mode ( stepper15_t *ctx, uint8_t output_mode );
652 
685 err_t stepper15_set_torque_dac ( stepper15_t *ctx, uint8_t trq_data );
686 
702 err_t stepper15_set_counts ( stepper15_t *ctx, uint8_t counts );
703 
718 
736 err_t stepper15_step_by_angle ( stepper15_t *ctx, uint8_t step_speed, float angle, uint16_t step_360 );
737 
738 #ifdef __cplusplus
739 }
740 #endif
741 #endif // STEPPER15_H
742  // stepper15
744 
745 // ------------------------------------------------------------------------ END
stepper15_s::pwm
digital_out_t pwm
Definition: stepper15.h:373
stepper15_cfg_t::scl
pin_name_t scl
Definition: stepper15.h:391
stepper15_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: stepper15.h:406
STEPPER15_ERROR
@ STEPPER15_ERROR
Definition: stepper15.h:418
stepper15_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper15.h:400
stepper15_i2c_read
err_t stepper15_i2c_read(stepper15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Stepper 15 I2C reading function.
stepper15_return_value_t
stepper15_return_value_t
Stepper 15 Click return value data.
Definition: stepper15.h:416
stepper15_default_cfg
err_t stepper15_default_cfg(stepper15_t *ctx)
Stepper 15 default configuration function.
stepper15_spi_read
err_t stepper15_spi_read(stepper15_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 15 SPI reading function.
stepper15_i2c_write
err_t stepper15_i2c_write(stepper15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Stepper 15 I2C writing function.
stepper15_s::rst
digital_out_t rst
Definition: stepper15.h:372
stepper15_cfg_t::sck
pin_name_t sck
Definition: stepper15.h:395
stepper15_cfg_t::spi_speed
uint32_t spi_speed
Definition: stepper15.h:405
stepper15_t
struct stepper15_s stepper15_t
Stepper 15 Click context object.
stepper15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper15.h:402
stepper15_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper15.h:403
stepper15_s::i2c
i2c_master_t i2c
Definition: stepper15.h:377
stepper15_get_interrupt
uint8_t stepper15_get_interrupt(stepper15_t *ctx)
Stepper 15 get interrupt function.
stepper15_make_one_step
err_t stepper15_make_one_step(stepper15_t *ctx, uint8_t step_speed)
Stepper 15 make one step function.
stepper15_cfg_t::mosi
pin_name_t mosi
Definition: stepper15.h:394
stepper15_s::slave_address
uint8_t slave_address
Definition: stepper15.h:380
stepper15_cfg_t::pwm
pin_name_t pwm
Definition: stepper15.h:399
stepper15_s::chip_select
pin_name_t chip_select
Definition: stepper15.h:381
stepper15_cfg_t::rst
pin_name_t rst
Definition: stepper15.h:398
stepper15_cfg_t::miso
pin_name_t miso
Definition: stepper15.h:393
stepper15_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: stepper15.h:407
stepper15_init
err_t stepper15_init(stepper15_t *ctx, stepper15_cfg_t *cfg)
Stepper 15 initialization function.
stepper15_reset
void stepper15_reset(stepper15_t *ctx)
Stepper 15 reset function.
stepper15_s::int_pin
digital_in_t int_pin
Definition: stepper15.h:375
stepper15_set_work_mode
err_t stepper15_set_work_mode(stepper15_t *ctx, uint8_t work_mode)
Stepper 15 set work mode function.
stepper15_cfg_t::sda
pin_name_t sda
Definition: stepper15.h:392
stepper15_set_torque_dac
err_t stepper15_set_torque_dac(stepper15_t *ctx, uint8_t trq_data)
Stepper 15 set torque DAC function.
stepper15_spi_write
err_t stepper15_spi_write(stepper15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Stepper 15 SPI writing function.
STEPPER15_OK
@ STEPPER15_OK
Definition: stepper15.h:417
stepper15_set_counts
err_t stepper15_set_counts(stepper15_t *ctx, uint8_t counts)
Stepper 15 set counts function.
stepper15_s
Stepper 15 Click context object.
Definition: stepper15.h:371
stepper15_cfg_t::cs
pin_name_t cs
Definition: stepper15.h:396
stepper15_cfg_t
Stepper 15 Click configuration object.
Definition: stepper15.h:390
stepper15_step_by_angle
err_t stepper15_step_by_angle(stepper15_t *ctx, uint8_t step_speed, float angle, uint16_t step_360)
Stepper 15 step by angle function.
stepper15_s::spi
spi_master_t spi
Definition: stepper15.h:378
stepper15_cfg_setup
void stepper15_cfg_setup(stepper15_cfg_t *cfg)
Stepper 15 configuration object setup function.
stepper15_set_direction
err_t stepper15_set_direction(stepper15_t *ctx, uint8_t direction)
Stepper 15 set direction function.
stepper15_get_fault_condition
uint8_t stepper15_get_fault_condition(stepper15_t *ctx)
Stepper 15 get fault condition function.
stepper15_set_output_mode
err_t stepper15_set_output_mode(stepper15_t *ctx, uint8_t output_mode)
Stepper 15 set output mode function.
stepper15_motor_stop
void stepper15_motor_stop(stepper15_t *ctx)
Stepper 15 motor stop function.