multisteppertb67s101 2.0.0.0
multisteppertb67s101.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 MULTISTEPPERTB67S101_H
29#define MULTISTEPPERTB67S101_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_i2c_master.h"
51
72#define MULTISTEPPERTB67S101_REG_INPUT 0x00
73#define MULTISTEPPERTB67S101_REG_OUTPUT 0x01
74#define MULTISTEPPERTB67S101_REG_POLARITY 0x02
75#define MULTISTEPPERTB67S101_REG_CONFIG 0x03
76
77 // multisteppertb67s101_reg
78
93#define MULTISTEPPERTB67S101_PHASEA_PIN 0x02
94#define MULTISTEPPERTB67S101_PHASEB_PIN 0x04
95
100#define MULTISTEPPERTB67S101_DEFAULT_CONFIG 0xF9
101
106#define MULTISTEPPERTB67S101_DIR_CW 0
107#define MULTISTEPPERTB67S101_DIR_CCW 1
108
113#define MULTISTEPPERTB67S101_PIN_LOW_LEVEL 0
114#define MULTISTEPPERTB67S101_PIN_HIGH_LEVEL 1
115
120#define MULTISTEPPERTB67S101_MODE_FULL_STEP 0x00
121#define MULTISTEPPERTB67S101_MODE_HALF_STEP 0x01
122#define MULTISTEPPERTB67S101_MODE_QUARTER_STEP 0x02
123
128#define MULTISTEPPERTB67S101_SPEED_VERY_SLOW 0
129#define MULTISTEPPERTB67S101_SPEED_SLOW 1
130#define MULTISTEPPERTB67S101_SPEED_MEDIUM 2
131#define MULTISTEPPERTB67S101_SPEED_FAST 3
132#define MULTISTEPPERTB67S101_SPEED_VERY_FAST 4
133
139#define MULTISTEPPERTB67S101_DEVICE_ADDRESS_A1A0_00 0x70
140#define MULTISTEPPERTB67S101_DEVICE_ADDRESS_A1A0_01 0x71
141#define MULTISTEPPERTB67S101_DEVICE_ADDRESS_A1A0_10 0x72
142#define MULTISTEPPERTB67S101_DEVICE_ADDRESS_A1A0_11 0x73
143
144 // multisteppertb67s101_set
145
160#define MULTISTEPPERTB67S101_MAP_MIKROBUS( cfg, mikrobus ) \
161 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
162 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
163 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
164 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
165 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
166 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
167 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
168
169 // multisteppertb67s101_map
170 // multisteppertb67s101
171
176typedef struct
177{
178 // Output pins
179 digital_out_t an;
180 digital_out_t int_pin;
181 digital_out_t clk;
182 digital_out_t en;
183 digital_out_t rst;
185 // Modules
186 i2c_master_t i2c;
188 // I2C slave address
191 uint8_t step_mode;
192 uint8_t direction;
193
195
200typedef struct
201{
202 pin_name_t scl;
203 pin_name_t sda;
205 pin_name_t an;
206 pin_name_t int_pin;
207 pin_name_t clk;
208 pin_name_t en;
209 pin_name_t rst;
211 uint32_t i2c_speed;
212 uint8_t i2c_address;
215
226
243
258
273
287err_t multisteppertb67s101_write_register ( multisteppertb67s101_t *ctx, uint8_t reg, uint8_t data_in );
288
301err_t multisteppertb67s101_read_register ( multisteppertb67s101_t *ctx, uint8_t reg, uint8_t *data_out );
302
320err_t multisteppertb67s101_drive_motor ( multisteppertb67s101_t *ctx, uint32_t steps, uint8_t speed );
321
331
341
353
365
377
389
403
415
425
426#ifdef __cplusplus
427}
428#endif
429#endif // MULTISTEPPERTB67S101_H
430
431 // multisteppertb67s101
432
433// ------------------------------------------------------------------------ END
void multisteppertb67s101_cfg_setup(multisteppertb67s101_cfg_t *cfg)
Multi Stepper TB67S101 configuration object setup function.
void multisteppertb67s101_switch_direction(multisteppertb67s101_t *ctx)
Multi Stepper TB67S101 switch direction function.
void multisteppertb67s101_disable_device(multisteppertb67s101_t *ctx)
Multi Stepper TB67S101 disable device function.
err_t multisteppertb67s101_default_cfg(multisteppertb67s101_t *ctx)
Multi Stepper TB67S101 default configuration function.
err_t multisteppertb67s101_write_register(multisteppertb67s101_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB67S101 write register function.
err_t multisteppertb67s101_read_register(multisteppertb67s101_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB67S101 read register function.
void multisteppertb67s101_set_step_mode(multisteppertb67s101_t *ctx, uint8_t mode)
Multi Stepper TB67S101 set step mode function.
void multisteppertb67s101_set_inb1_pin(multisteppertb67s101_t *ctx, uint8_t state)
Multi Stepper TB67S101 set inb1 pin function.
void multisteppertb67s101_set_direction(multisteppertb67s101_t *ctx, uint8_t dir)
Multi Stepper TB67S101 set direction function.
err_t multisteppertb67s101_init(multisteppertb67s101_t *ctx, multisteppertb67s101_cfg_t *cfg)
Multi Stepper TB67S101 initialization function.
err_t multisteppertb67s101_drive_motor(multisteppertb67s101_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB67S101 driver motor function.
void multisteppertb67s101_enable_device(multisteppertb67s101_t *ctx)
Multi Stepper TB67S101 enable device function.
void multisteppertb67s101_set_ina2_pin(multisteppertb67s101_t *ctx, uint8_t state)
Multi Stepper TB67S101 set ina2 pin function.
void multisteppertb67s101_set_ina1_pin(multisteppertb67s101_t *ctx, uint8_t state)
Multi Stepper TB67S101 set ina1 pin function.
void multisteppertb67s101_set_inb2_pin(multisteppertb67s101_t *ctx, uint8_t state)
Multi Stepper TB67S101 set inb2 pin function.
multisteppertb67s101_return_value_t
Multi Stepper TB67S101 Click return value data.
Definition multisteppertb67s101.h:221
@ MULTISTEPPERTB67S101_ERROR
Definition multisteppertb67s101.h:223
@ MULTISTEPPERTB67S101_OK
Definition multisteppertb67s101.h:222
Multi Stepper TB67S101 Click configuration object.
Definition multisteppertb67s101.h:201
pin_name_t clk
Definition multisteppertb67s101.h:207
uint32_t i2c_speed
Definition multisteppertb67s101.h:211
pin_name_t scl
Definition multisteppertb67s101.h:202
pin_name_t en
Definition multisteppertb67s101.h:208
pin_name_t int_pin
Definition multisteppertb67s101.h:206
pin_name_t sda
Definition multisteppertb67s101.h:203
pin_name_t rst
Definition multisteppertb67s101.h:209
pin_name_t an
Definition multisteppertb67s101.h:205
uint8_t i2c_address
Definition multisteppertb67s101.h:212
Multi Stepper TB67S101 Click context object.
Definition multisteppertb67s101.h:177
uint8_t step_mode
Definition multisteppertb67s101.h:191
i2c_master_t i2c
Definition multisteppertb67s101.h:186
digital_out_t int_pin
Definition multisteppertb67s101.h:180
digital_out_t clk
Definition multisteppertb67s101.h:181
digital_out_t en
Definition multisteppertb67s101.h:182
digital_out_t rst
Definition multisteppertb67s101.h:183
uint8_t direction
Definition multisteppertb67s101.h:192
uint8_t slave_address
Definition multisteppertb67s101.h:189
digital_out_t an
Definition multisteppertb67s101.h:179