我正在使用 STM32F767 MCU 和两个屏蔽:IHM02A1 双步进电机驱动器。我还没有调试器,但我的公司正在准备一个...
同时,我一直在取消/注释掉 Mbed 的部分代码。他们的 Hello World 程序可以从这个网站获得,并且可以通过点击“导入程序”直接在他们的在线 IDE 中使用:https ://os.mbed.com/components/X-NUCLEO-IHM02A1/
#include "mbed.h"
#include "DevSPI.h"
#include "XNucleoIHM02A1.h"
#define MPR_1 4 /* Number of movements per revolution. */
#define STEPS_1 (200 * 128) /* 1 revolution given a 200 steps motor configured at 1/128 microstep mode. */
#define STEPS_2 (STEPS_1 * 2)
/* Delay in milliseconds. */
#define DELAY_1 1000
#define DELAY_2 2000
#define DELAY_3 3000
/* Motor Control Expansion Board. */
XNucleoIHM02A1 *x_nucleo_ihm02a1;
XNucleoIHM02A1 *x_nucleo_ihm02a1two;
/* Initialization parameters of the motors connected to the expansion board. */
L6470_init_t init[L6470DAISYCHAINSIZE] = {
/* First Motor. */
{
24.0, /* Motor supply voltage in V. */
200, /* Min number of steps per revolution for the motor. */
1.7, /* Max motor phase voltage in A. */
3.06, /* Max motor phase voltage in V. */
300.0, /* Motor initial speed [step/s]. */
500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
992.0, /* Motor maximum speed [step/s]. */
0.0, /* Motor minimum speed [step/s]. */
602.7, /* Motor full-step speed threshold [step/s]. */
3.06, /* Holding kval [V]. */
3.06, /* Constant speed kval [V]. */
3.06, /* Acceleration starting kval [V]. */
3.06, /* Deceleration starting kval [V]. */
61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */
392.1569e-6, /* Start slope [s/step]. */
643.1372e-6, /* Acceleration final slope [s/step]. */
643.1372e-6, /* Deceleration final slope [s/step]. */
0, /* Thermal compensation factor (range [0, 15]). */
3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
0xFF, /* Alarm conditions enable. */
0x2E88 /* Ic configuration. */
},
/* Second Motor. */
{
24.0, /* Motor supply voltage in V. */
200, /* Min number of steps per revolution for the motor. */
1.7, /* Max motor phase voltage in A. */
3.06, /* Max motor phase voltage in V. */
300.0, /* Motor initial speed [step/s]. */
500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
992.0, /* Motor maximum speed [step/s]. */
0.0, /* Motor minimum speed [step/s]. */
602.7, /* Motor full-step speed threshold [step/s]. */
3.06, /* Holding kval [V]. */
3.06, /* Constant speed kval [V]. */
3.06, /* Acceleration starting kval [V]. */
3.06, /* Deceleration starting kval [V]. */
61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */
392.1569e-6, /* Start slope [s/step]. */
643.1372e-6, /* Acceleration final slope [s/step]. */
643.1372e-6, /* Deceleration final slope [s/step]. */
0, /* Thermal compensation factor (range [0, 15]). */
3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
0xFF, /* Alarm conditions enable. */
0x2E88 /* Ic configuration. */
}
};
int main()
{
/* Initializing SPI bus. */
#ifdef TARGET_STM32F429
DevSPI dev_spi(D11, D12, D13);
#else
DevSPI dev_spi(D11, D12, D13);
#endif
/* Initializing Motor Control Expansion Board. */
x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D2, &dev_spi);
x_nucleo_ihm02a1two = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
/* Building a list of motor control components. */
L6470 **motors = x_nucleo_ihm02a1->get_components();
L6470 **motorstwo = x_nucleo_ihm02a1two->get_components();
/* Setting the home position. */
//motorstwo[1]->set_home();
// wait_ms(DELAY_1);
int position = motorstwo[1]->get_position();
wait_ms(DELAY_1);
// motors[1]->move(StepperMotor::FWD, STEPS_2);
// motors[0]->move(StepperMotor::FWD, STEPS_2);
// wait_ms(DELAY_2);
motorstwo[1]->move(StepperMotor::FWD, STEPS_2);
motorstwo[0]->move(StepperMotor::FWD, STEPS_2);
position = motorstwo[1]->get_position();
wait_ms(DELAY_1);
}
这是完整程序的最小可重现示例。如果您想自己尝试一下,只需将其复制/粘贴到 main.cpp(在上面提到的在线 IDE 中)。
一切都符合,没有警告。下面的任何一条线(及其匹配的指针等)都通过移动电机来工作。即,motorstwo[x] 和motors[x] 都可以自己解决。但是当两条线都加载到板上时……没有任何作用,电机不动。步进器甚至没有发出非常柔和的声音。
x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, D2, &dev_spi);
x_nucleo_ihm02a1two = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
为什么这两行不能一起上传?如何解决这个问题?
编辑
该类包括“XNucleoIHM02A1”的两个函数。有七个周长的那个是要剖析的...倒数第二个参数声音被改变(塞尔:)
查看 Nucleo 原理图,您会注意到 L6470_1_SDO(串行数据输出)连接到 L6470_0_SDI(串行数据输入)。这是菊花链配置。还要注意桥接 SB7 是如何连接到板上的 D2 引脚的。
查看零件数据表,它将在 /CS 为低电平时开始读取数据,并将一直移出数据,直到 /CS 为高电平。
通过堆叠第二块板,这种配置结果——它是菊花链和上述单独寻址版本的组合: