multisteppertb62261  2.0.0.0
multisteppertb62261.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 MULTISTEPPERTB62261_H
29 #define MULTISTEPPERTB62261_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_i2c_master.h"
47 
68 #define MULTISTEPPERTB62261_REG_INPUT 0x00
69 #define MULTISTEPPERTB62261_REG_OUTPUT 0x01
70 #define MULTISTEPPERTB62261_REG_POLARITY 0x02
71 #define MULTISTEPPERTB62261_REG_CONFIG 0x03
72  // multisteppertb62261_reg
74 
89 #define MULTISTEPPERTB62261_PHASEA_PIN 0x02
90 #define MULTISTEPPERTB62261_PHASEB_PIN 0x04
91 
96 #define MULTISTEPPERTB62261_DEFAULT_CONFIG 0xF9
97 
102 #define MULTISTEPPERTB62261_DIR_CW 0
103 #define MULTISTEPPERTB62261_DIR_CCW 1
104 
109 #define MULTISTEPPERTB62261_PIN_LOW_LEVEL 0
110 #define MULTISTEPPERTB62261_PIN_HIGH_LEVEL 1
111 
116 #define MULTISTEPPERTB62261_MODE_FULL_STEP 0x00
117 #define MULTISTEPPERTB62261_MODE_HALF_STEP 0x01
118 #define MULTISTEPPERTB62261_MODE_QUARTER_STEP 0x02
119 
124 #define MULTISTEPPERTB62261_SPEED_VERY_SLOW 0
125 #define MULTISTEPPERTB62261_SPEED_SLOW 1
126 #define MULTISTEPPERTB62261_SPEED_MEDIUM 2
127 #define MULTISTEPPERTB62261_SPEED_FAST 3
128 #define MULTISTEPPERTB62261_SPEED_VERY_FAST 4
129 
135 #define MULTISTEPPERTB62261_DEVICE_ADDRESS_A1A0_00 0x70
136 #define MULTISTEPPERTB62261_DEVICE_ADDRESS_A1A0_01 0x71
137 #define MULTISTEPPERTB62261_DEVICE_ADDRESS_A1A0_10 0x72
138 #define MULTISTEPPERTB62261_DEVICE_ADDRESS_A1A0_11 0x73
139  // multisteppertb62261_set
141 
156 #define MULTISTEPPERTB62261_MAP_MIKROBUS( cfg, mikrobus ) \
157  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
158  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
159  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
160  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
161  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
162  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
163  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
164  // multisteppertb62261_map // multisteppertb62261
167 
172 typedef struct
173 {
174  // Output pins
175  digital_out_t an;
176  digital_out_t int_pin;
177  digital_out_t clk;
178  digital_out_t en;
179  digital_out_t rst;
181  // Modules
182  i2c_master_t i2c;
184  // I2C slave address
185  uint8_t slave_address;
187  uint8_t step_mode;
188  uint8_t direction;
189 
191 
196 typedef struct
197 {
198  pin_name_t scl;
199  pin_name_t sda;
201  pin_name_t an;
202  pin_name_t int_pin;
203  pin_name_t clk;
204  pin_name_t en;
205  pin_name_t rst;
207  uint32_t i2c_speed;
208  uint8_t i2c_address;
211 
216 typedef enum
217 {
220 
222 
239 
254 
269 
283 err_t multisteppertb62261_write_register ( multisteppertb62261_t *ctx, uint8_t reg, uint8_t data_in );
284 
297 err_t multisteppertb62261_read_register ( multisteppertb62261_t *ctx, uint8_t reg, uint8_t *data_out );
298 
316 err_t multisteppertb62261_drive_motor ( multisteppertb62261_t *ctx, uint32_t steps, uint8_t speed );
317 
327 
337 
349 
361 
373 
385 
399 
411 
421 
422 #ifdef __cplusplus
423 }
424 #endif
425 #endif // MULTISTEPPERTB62261_H
426  // multisteppertb62261
428 
429 // ------------------------------------------------------------------------ END
multisteppertb62261_disable_device
void multisteppertb62261_disable_device(multisteppertb62261_t *ctx)
Multi Stepper TB62261 disable device function.
multisteppertb62261_t::direction
uint8_t direction
Definition: multisteppertb62261.h:188
multisteppertb62261_cfg_t
Multi Stepper TB62261 Click configuration object.
Definition: multisteppertb62261.h:197
MULTISTEPPERTB62261_ERROR
@ MULTISTEPPERTB62261_ERROR
Definition: multisteppertb62261.h:219
multisteppertb62261_t::en
digital_out_t en
Definition: multisteppertb62261.h:178
multisteppertb62261_cfg_setup
void multisteppertb62261_cfg_setup(multisteppertb62261_cfg_t *cfg)
Multi Stepper TB62261 configuration object setup function.
multisteppertb62261_set_direction
void multisteppertb62261_set_direction(multisteppertb62261_t *ctx, uint8_t dir)
Multi Stepper TB62261 set direction function.
multisteppertb62261_t::an
digital_out_t an
Definition: multisteppertb62261.h:175
multisteppertb62261_t::clk
digital_out_t clk
Definition: multisteppertb62261.h:177
multisteppertb62261_t::int_pin
digital_out_t int_pin
Definition: multisteppertb62261.h:176
MULTISTEPPERTB62261_OK
@ MULTISTEPPERTB62261_OK
Definition: multisteppertb62261.h:218
multisteppertb62261_return_value_t
multisteppertb62261_return_value_t
Multi Stepper TB62261 Click return value data.
Definition: multisteppertb62261.h:217
multisteppertb62261_cfg_t::clk
pin_name_t clk
Definition: multisteppertb62261.h:203
multisteppertb62261_write_register
err_t multisteppertb62261_write_register(multisteppertb62261_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB62261 write register function.
multisteppertb62261_t::slave_address
uint8_t slave_address
Definition: multisteppertb62261.h:185
multisteppertb62261_switch_direction
void multisteppertb62261_switch_direction(multisteppertb62261_t *ctx)
Multi Stepper TB62261 switch direction function.
multisteppertb62261_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: multisteppertb62261.h:207
multisteppertb62261_t::rst
digital_out_t rst
Definition: multisteppertb62261.h:179
multisteppertb62261_set_inb1_pin
void multisteppertb62261_set_inb1_pin(multisteppertb62261_t *ctx, uint8_t state)
Multi Stepper TB62261 set inb1 pin function.
multisteppertb62261_t::step_mode
uint8_t step_mode
Definition: multisteppertb62261.h:187
multisteppertb62261_drive_motor
err_t multisteppertb62261_drive_motor(multisteppertb62261_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB62261 driver motor function.
multisteppertb62261_cfg_t::en
pin_name_t en
Definition: multisteppertb62261.h:204
multisteppertb62261_read_register
err_t multisteppertb62261_read_register(multisteppertb62261_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB62261 read register function.
multisteppertb62261_enable_device
void multisteppertb62261_enable_device(multisteppertb62261_t *ctx)
Multi Stepper TB62261 enable device function.
multisteppertb62261_cfg_t::int_pin
pin_name_t int_pin
Definition: multisteppertb62261.h:202
multisteppertb62261_cfg_t::an
pin_name_t an
Definition: multisteppertb62261.h:201
multisteppertb62261_cfg_t::scl
pin_name_t scl
Definition: multisteppertb62261.h:198
multisteppertb62261_t
Multi Stepper TB62261 Click context object.
Definition: multisteppertb62261.h:173
multisteppertb62261_cfg_t::i2c_address
uint8_t i2c_address
Definition: multisteppertb62261.h:208
multisteppertb62261_init
err_t multisteppertb62261_init(multisteppertb62261_t *ctx, multisteppertb62261_cfg_t *cfg)
Multi Stepper TB62261 initialization function.
multisteppertb62261_set_step_mode
void multisteppertb62261_set_step_mode(multisteppertb62261_t *ctx, uint8_t mode)
Multi Stepper TB62261 set step mode function.
multisteppertb62261_default_cfg
err_t multisteppertb62261_default_cfg(multisteppertb62261_t *ctx)
Multi Stepper TB62261 default configuration function.
multisteppertb62261_t::i2c
i2c_master_t i2c
Definition: multisteppertb62261.h:182
multisteppertb62261_set_ina1_pin
void multisteppertb62261_set_ina1_pin(multisteppertb62261_t *ctx, uint8_t state)
Multi Stepper TB62261 set ina1 pin function.
multisteppertb62261_cfg_t::sda
pin_name_t sda
Definition: multisteppertb62261.h:199
multisteppertb62261_set_ina2_pin
void multisteppertb62261_set_ina2_pin(multisteppertb62261_t *ctx, uint8_t state)
Multi Stepper TB62261 set ina2 pin function.
multisteppertb62261_set_inb2_pin
void multisteppertb62261_set_inb2_pin(multisteppertb62261_t *ctx, uint8_t state)
Multi Stepper TB62261 set inb2 pin function.
multisteppertb62261_cfg_t::rst
pin_name_t rst
Definition: multisteppertb62261.h:205