Simple test application for the STMicroelectronics X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board, built against mbed OS.
Dependencies: X_NUCLEO_IHM01A1
Fork of HelloWorld_IHM01A1 by
This application provides a simple example of usage of the X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board. It shows how to use one stepper motor connected to the board, moving the rotor to a specific position, with a given speed value, direction of rotation, etc.
Revision 34:543d0d1147d9, committed 2017-03-01
- Comitter:
- Davidroid
- Date:
- Wed Mar 01 13:31:48 2017 +0000
- Parent:
- 33:b7c72f06bc38
- Child:
- 35:2b44ed4ec7a0
- Commit message:
- Fitting mbed coding style.
Changed in this revision
| X_NUCLEO_IHM01A1.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/X_NUCLEO_IHM01A1.lib Fri Oct 28 13:50:25 2016 +0000 +++ b/X_NUCLEO_IHM01A1.lib Wed Mar 01 13:31:48 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM01A1/#c4d0fee5ce75 +http://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM01A1/#6e5198e46287
--- a/main.cpp Fri Oct 28 13:50:25 2016 +0000
+++ b/main.cpp Wed Mar 01 13:31:48 2017 +0000
@@ -70,8 +70,7 @@
/* Variables -----------------------------------------------------------------*/
/* Initialization parameters. */
-L6474_Init_t init =
-{
+L6474_Init_t init = {
160, /* Acceleration rate in pps^2. Range: (0..+inf). */
160, /* Deceleration rate in pps^2. Range: (0..+inf). */
1600, /* Maximum speed in pps. Range: (30..10000]. */
@@ -120,11 +119,12 @@
/* Get the value of the status register. */
unsigned int status = motor->GetStatus();
-
+
/* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed. */
/* This often occures when a command is sent to the L6474 while it is not in HiZ state. */
- if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD)
+ if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD) {
printf(" WARNING: \"FLAG\" interrupt triggered. Non-performable command detected when updating L6474's registers while not in HiZ state.\r\n");
+ }
/* Reset ISR flag. */
motor->isr_flag = FALSE;
@@ -142,8 +142,9 @@
/* Initializing Motor Control Component. */
motor = new L6474(D2, D8, D7, D9, D10, dev_spi);
- if (motor->Init(&init) != COMPONENT_OK)
+ if (motor->Init(&init) != COMPONENT_OK) {
exit(EXIT_FAILURE);
+ }
/* Attaching and enabling interrupt handlers. */
motor->AttachFlagIRQ(&FlagIRQHandler);
@@ -186,8 +187,9 @@
printf("--> Doubling the microsteps.\r\n");
/* Doubling the microsteps. */
- if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_1_16))
+ if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_1_16)) {
printf(" Step Mode not allowed.\r\n");
+ }
/* Waiting. */
wait_ms(DELAY_1);
@@ -348,8 +350,7 @@
motor->SetHome();
/* Infinite Loop. */
- while (1)
- {
+ while (true) {
/* Requesting to go to a specified position. */
motor->GoTo(STEPS_1 >> 1);
