stepper14 2.1.0.0
stepper14.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 STEPPER14_H
29#define STEPPER14_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 STEPPER14_PCA9538A_REG_INPUT 0x00
74#define STEPPER14_PCA9538A_REG_OUTPUT 0x01
75#define STEPPER14_PCA9538A_REG_POLARITY 0x02
76#define STEPPER14_PCA9538A_REG_CONFIG 0x03
77
78 // stepper14_reg
79
94#define STEPPER14_PIN_IN1 0x01
95#define STEPPER14_PIN_IN2 0x02
96#define STEPPER14_PIN_MODE 0x04
97#define STEPPER14_PIN_IN3 0x08
98#define STEPPER14_PIN_IN4 0x10
99#define STEPPER14_PIN_TRQ 0x20
100
105#define STEPPER14_PCA9538A_DEFAULT_CONFIG 0xC0
106
111#define STEPPER14_DIR_CW 0
112#define STEPPER14_DIR_CCW 1
113
118#define STEPPER14_PIN_STATE_LOW 0
119#define STEPPER14_PIN_STATE_HIGH 1
120
125#define STEPPER14_INTERFACE_4_PIN 0
126#define STEPPER14_INTERFACE_2_PIN 1
127
132#define STEPPER14_SPEED_VERY_SLOW 0
133#define STEPPER14_SPEED_SLOW 1
134#define STEPPER14_SPEED_MEDIUM 2
135#define STEPPER14_SPEED_FAST 3
136#define STEPPER14_SPEED_VERY_FAST 4
137
142#define STEPPER14_MODE_FULL_STEP 0
143#define STEPPER14_MODE_HALF_STEP 1
144
150#define STEPPER14_DEVICE_ADDRESS_A1A0_00 0x70
151#define STEPPER14_DEVICE_ADDRESS_A1A0_01 0x71
152#define STEPPER14_DEVICE_ADDRESS_A1A0_10 0x72
153#define STEPPER14_DEVICE_ADDRESS_A1A0_11 0x73
154
155 // stepper14_set
156
171#define STEPPER14_MAP_MIKROBUS( cfg, mikrobus ) \
172 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
174 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
175 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
176 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
177
178 // stepper14_map
179 // stepper14
180
185typedef struct
186{
187 // Output pins
188 digital_out_t en;
189 digital_out_t rst;
191 // Input pins
192 digital_in_t flt;
194 // Modules
195 i2c_master_t i2c;
197 // I2C slave address
200 uint8_t pin_mode;
201 uint8_t step_mode;
202 uint8_t direction;
205
210typedef struct
211{
212 pin_name_t scl;
213 pin_name_t sda;
215 pin_name_t en;
216 pin_name_t rst;
217 pin_name_t flt;
219 uint32_t i2c_speed;
220 uint8_t i2c_address;
223
234
251
266
280
294err_t stepper14_pca_write_reg ( stepper14_t *ctx, uint8_t reg, uint8_t data_in );
295
308err_t stepper14_pca_read_reg ( stepper14_t *ctx, uint8_t reg, uint8_t *data_out );
309
320void stepper14_set_rst_pin ( stepper14_t *ctx, uint8_t state );
321
331
341
351
361
374err_t stepper14_set_in1_pin ( stepper14_t *ctx, uint8_t state );
375
388err_t stepper14_set_in2_pin ( stepper14_t *ctx, uint8_t state );
389
402err_t stepper14_set_in3_pin ( stepper14_t *ctx, uint8_t state );
403
416err_t stepper14_set_in4_pin ( stepper14_t *ctx, uint8_t state );
417
430err_t stepper14_set_mode_pin ( stepper14_t *ctx, uint8_t state );
431
444err_t stepper14_set_trq_pin ( stepper14_t *ctx, uint8_t state );
445
459err_t stepper14_set_interface_mode ( stepper14_t *ctx, uint8_t mode );
460
472void stepper14_set_step_mode ( stepper14_t *ctx, uint8_t mode );
473
484void stepper14_set_direction ( stepper14_t *ctx, uint8_t dir );
485
495
513err_t stepper14_drive_motor ( stepper14_t *ctx, uint32_t steps, uint8_t speed );
514
515#ifdef __cplusplus
516}
517#endif
518#endif // STEPPER14_H
519
520 // stepper14
521
522// ------------------------------------------------------------------------ END
void stepper14_enable_device(stepper14_t *ctx)
Stepper 14 enable device function.
err_t stepper14_default_cfg(stepper14_t *ctx)
Stepper 14 default configuration function.
void stepper14_set_step_mode(stepper14_t *ctx, uint8_t mode)
Stepper 14 set step mode function.
void stepper14_set_rst_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set rst pin function.
void stepper14_switch_direction(stepper14_t *ctx)
Stepper 14 switch direction function.
err_t stepper14_set_mode_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set MODE pin function.
void stepper14_set_direction(stepper14_t *ctx, uint8_t dir)
Stepper 14 set direction function.
err_t stepper14_pca_read_reg(stepper14_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 14 pca read reg function.
void stepper14_cfg_setup(stepper14_cfg_t *cfg)
Stepper 14 configuration object setup function.
err_t stepper14_init(stepper14_t *ctx, stepper14_cfg_t *cfg)
Stepper 14 initialization function.
void stepper14_reset_pca(stepper14_t *ctx)
Stepper 14 reset device function.
err_t stepper14_pca_write_reg(stepper14_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 14 pca write reg function.
err_t stepper14_set_in1_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN1 pin function.
err_t stepper14_set_in3_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN3 pin function.
void stepper14_disable_device(stepper14_t *ctx)
Stepper 14 disable device function.
err_t stepper14_set_in4_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN4 pin function.
uint8_t stepper14_get_fault_pin(stepper14_t *ctx)
Stepper 14 get FAULT pin function.
err_t stepper14_set_trq_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set TRQ pin function.
err_t stepper14_set_in2_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN2 pin function.
err_t stepper14_set_interface_mode(stepper14_t *ctx, uint8_t mode)
Stepper 14 set interface mode function.
err_t stepper14_drive_motor(stepper14_t *ctx, uint32_t steps, uint8_t speed)
Stepper 14 driver motor function.
stepper14_return_value_t
Stepper 14 Click return value data.
Definition stepper14.h:229
@ STEPPER14_ERROR
Definition stepper14.h:231
@ STEPPER14_OK
Definition stepper14.h:230
Stepper 14 Click configuration object.
Definition stepper14.h:211
uint32_t i2c_speed
Definition stepper14.h:219
pin_name_t flt
Definition stepper14.h:217
pin_name_t scl
Definition stepper14.h:212
pin_name_t en
Definition stepper14.h:215
pin_name_t sda
Definition stepper14.h:213
pin_name_t rst
Definition stepper14.h:216
uint8_t i2c_address
Definition stepper14.h:220
Stepper 14 Click context object.
Definition stepper14.h:186
digital_in_t flt
Definition stepper14.h:192
uint8_t step_mode
Definition stepper14.h:201
i2c_master_t i2c
Definition stepper14.h:195
uint8_t pin_mode
Definition stepper14.h:200
digital_out_t en
Definition stepper14.h:188
digital_out_t rst
Definition stepper14.h:189
uint8_t direction
Definition stepper14.h:202
uint8_t slave_address
Definition stepper14.h:198