Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more

Fork of X_NUCLEO_IHM02A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM02A1 Motor Control Expansion Board based on the the L6470 component.

Daisy-Chain Configuration

The two L6470 components mounted on this board are connected in daisy-chain configuration. This board can be stacked up to four times so that the eight L6470 components will be connected two-by-two in daisy-chain configuration.

Concerning the SSEL pin of the SPI communication, each expansion board must be in one of the following configuration:

  • SB_23 resistor connected only: SSEL on pin A2;
  • SB_7 resistor connected only: SSEL on pin D2;
  • SB_8 resistor connected only: SSEL on pin D10;
  • SB_9 resistor connected only: SSEL on pin D5.

Arduino Connector Compatibility Warning

X-NUCLEO-IHM02A1 is Arduino compatible with one exception: instead of using D13 pin to drive the SPI clock, it uses D3 pin, hence the default configuration for this library is with the SPI clock on D3 pin.

To be fully Arduino compatible the following patch is required:

  • to remove the SB34 resistor;
  • to solder the SB12 resistor.

Alternatively, you can route the Nucleo board’s D13 pin directly to the expansion board’s D3 pin with a wire. In case you patch your expansion board or route the pin, the SPI clock will be driven on D13 pin rather than on D3 pin, and you have also to initialize the sclk PinName variable with D13 rather than D3. This patch is known to be required, for example, on the following boards: NUCLEO-F103RB, NUCLEO-F302RB, NUCLEO-F411RE, and NUCLEO-F429ZI.

If you use D13 pin for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to the D13 pin.

Example Applications

Committer:
Davidroid
Date:
Fri Nov 20 18:07:45 2015 +0000
Revision:
0:92706998571a
Child:
11:1aca63b2f034
Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the the L6470 component.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:92706998571a 1 /**
Davidroid 0:92706998571a 2 ******************************************************************************
Davidroid 0:92706998571a 3 * @file L6470.h
Davidroid 0:92706998571a 4 * @date 01/10/2014 12:00:00
Davidroid 0:92706998571a 5 * @brief This file contains definitions, exported variables and function
Davidroid 0:92706998571a 6 * prototypes related to the L6470.
Davidroid 0:92706998571a 7 ******************************************************************************
Davidroid 0:92706998571a 8 *
Davidroid 0:92706998571a 9 * COPYRIGHT(c) 2014 STMicroelectronics
Davidroid 0:92706998571a 10 *
Davidroid 0:92706998571a 11 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 0:92706998571a 12 * are permitted provided that the following conditions are met:
Davidroid 0:92706998571a 13 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 0:92706998571a 14 * this list of conditions and the following disclaimer.
Davidroid 0:92706998571a 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 0:92706998571a 16 * this list of conditions and the following disclaimer in the documentation
Davidroid 0:92706998571a 17 * and/or other materials provided with the distribution.
Davidroid 0:92706998571a 18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 0:92706998571a 19 * may be used to endorse or promote products derived from this software
Davidroid 0:92706998571a 20 * without specific prior written permission.
Davidroid 0:92706998571a 21 *
Davidroid 0:92706998571a 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 0:92706998571a 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 0:92706998571a 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 0:92706998571a 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 0:92706998571a 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 0:92706998571a 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 0:92706998571a 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 0:92706998571a 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 0:92706998571a 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 0:92706998571a 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 0:92706998571a 32 *
Davidroid 0:92706998571a 33 ******************************************************************************
Davidroid 0:92706998571a 34 */
Davidroid 0:92706998571a 35
Davidroid 0:92706998571a 36 /* Define to prevent recursive inclusion -------------------------------------*/
Davidroid 0:92706998571a 37 #ifndef __L6470_H
Davidroid 0:92706998571a 38 #define __L6470_H
Davidroid 0:92706998571a 39
Davidroid 0:92706998571a 40 #ifdef __cplusplus
Davidroid 0:92706998571a 41 extern "C" {
Davidroid 0:92706998571a 42 #endif
Davidroid 0:92706998571a 43
Davidroid 0:92706998571a 44 /* Includes ------------------------------------------------------------------*/
Davidroid 0:92706998571a 45 #include "microstepping_motor.h"
Davidroid 0:92706998571a 46
Davidroid 0:92706998571a 47 /**
Davidroid 0:92706998571a 48 * @addtogroup BSP
Davidroid 0:92706998571a 49 * @{
Davidroid 0:92706998571a 50 */
Davidroid 0:92706998571a 51
Davidroid 0:92706998571a 52 /**
Davidroid 0:92706998571a 53 * @addtogroup Components
Davidroid 0:92706998571a 54 * @{
Davidroid 0:92706998571a 55 */
Davidroid 0:92706998571a 56
Davidroid 0:92706998571a 57 /**
Davidroid 0:92706998571a 58 * @defgroup L6470
Davidroid 0:92706998571a 59 * @brief Tools to manage the L6470 Stepper Motor Driver.
Davidroid 0:92706998571a 60 * @{
Davidroid 0:92706998571a 61 */
Davidroid 0:92706998571a 62
Davidroid 0:92706998571a 63 /**
Davidroid 0:92706998571a 64 * @defgroup L6470_Exported_Types
Davidroid 0:92706998571a 65 * @brief L6470 Exported Types.
Davidroid 0:92706998571a 66 * @{
Davidroid 0:92706998571a 67 */
Davidroid 0:92706998571a 68
Davidroid 0:92706998571a 69 /**
Davidroid 0:92706998571a 70 * @brief The structure to store some features of the L6470 Registers.
Davidroid 0:92706998571a 71 */
Davidroid 0:92706998571a 72 typedef struct {
Davidroid 0:92706998571a 73 uint8_t Address; //!< Register Address
Davidroid 0:92706998571a 74 uint8_t Name[12]; //!< Register Name
Davidroid 0:92706998571a 75 uint8_t LengthBit; //!< Register Length in bits
Davidroid 0:92706998571a 76 uint8_t LengthByte; //!< Register Length in bytes
Davidroid 0:92706998571a 77 uint32_t ResetValue; //!< Register Reset Value
Davidroid 0:92706998571a 78 } sL6470_Register_t;
Davidroid 0:92706998571a 79
Davidroid 0:92706998571a 80 /**
Davidroid 0:92706998571a 81 * @brief The structure to store some features of the L6470 Application Commands.
Davidroid 0:92706998571a 82 */
Davidroid 0:92706998571a 83 typedef struct {
Davidroid 0:92706998571a 84 uint8_t Mnemonic[12]; //!< AppCmd Mnemonic
Davidroid 0:92706998571a 85 uint8_t BinaryCode; //!< AppCmd Binary Code
Davidroid 0:92706998571a 86 uint8_t NrOfParameters; //!< AppCmd number of needed parameters
Davidroid 0:92706998571a 87 } sL6470_ApplicationCommand_t;
Davidroid 0:92706998571a 88
Davidroid 0:92706998571a 89 /**
Davidroid 0:92706998571a 90 * @brief The structure to store some features about the L6470 Motor Direction.
Davidroid 0:92706998571a 91 */
Davidroid 0:92706998571a 92 typedef struct {
Davidroid 0:92706998571a 93 uint8_t Mnemonic[8]; //!< L6470 Direction Mnemonic
Davidroid 0:92706998571a 94 uint8_t BinaryCode; //!< L6470 Direction Binary Code
Davidroid 0:92706998571a 95 } sL6470_Direction_t;
Davidroid 0:92706998571a 96
Davidroid 0:92706998571a 97 /**
Davidroid 0:92706998571a 98 * @brief The structure to store some features about the action taken with the L6470 ABS_POS register.
Davidroid 0:92706998571a 99 */
Davidroid 0:92706998571a 100 typedef struct {
Davidroid 0:92706998571a 101 uint8_t Mnemonic[4]; //!< ACT Mnemonic
Davidroid 0:92706998571a 102 uint8_t BinaryCode; //!< ACT Binary Code
Davidroid 0:92706998571a 103 } sL6470_ACT_t;
Davidroid 0:92706998571a 104
Davidroid 0:92706998571a 105 /**
Davidroid 0:92706998571a 106 * @brief The structure used to store the identifier of the L6470 application
Davidroid 0:92706998571a 107 * command and its the needed parameters.
Davidroid 0:92706998571a 108 * @note The data stored into this structure will be used to fill the matrix
Davidroid 0:92706998571a 109 * used by SPI to send the command to the L6470.
Davidroid 0:92706998571a 110 */
Davidroid 0:92706998571a 111 typedef struct {
Davidroid 0:92706998571a 112 eL6470_AppCmdId_t L6470_AppCmdId; //!< The identifier of the actual L6470 Application Command
Davidroid 0:92706998571a 113 uint32_t p1; //!< The 1st parameter if needed
Davidroid 0:92706998571a 114 uint32_t p2; //!< The 2nd parameter if needed
Davidroid 0:92706998571a 115 uint32_t p3; //!< The 3rd parameter if needed
Davidroid 0:92706998571a 116 } sL6470_AppCmdPkg_t;
Davidroid 0:92706998571a 117
Davidroid 0:92706998571a 118 /**
Davidroid 0:92706998571a 119 * @}
Davidroid 0:92706998571a 120 */ /* End of L6470_Exported_Types */
Davidroid 0:92706998571a 121
Davidroid 0:92706998571a 122 /**
Davidroid 0:92706998571a 123 * @defgroup L6470_Exported_Constants
Davidroid 0:92706998571a 124 * @brief L6470 Exported Constants.
Davidroid 0:92706998571a 125 * @{
Davidroid 0:92706998571a 126 */
Davidroid 0:92706998571a 127
Davidroid 0:92706998571a 128 /**
Davidroid 0:92706998571a 129 * @defgroup L6470_Register_Max_Values
Davidroid 0:92706998571a 130 * @brief Maximum values for L6470 registers.
Davidroid 0:92706998571a 131 * @{
Davidroid 0:92706998571a 132 */
Davidroid 0:92706998571a 133
Davidroid 0:92706998571a 134 #define L6470_MAX_POSITION (0x1FFFFF) //!< Max position
Davidroid 0:92706998571a 135 #define L6470_MIN_POSITION (-(0x200000)) //!< Min position
Davidroid 0:92706998571a 136 #define L6470_POSITION_RANGE ((uint32_t)(L6470_MAX_POSITION - L6470_MIN_POSITION)) //!< Position range
Davidroid 0:92706998571a 137 #define L6470_MAX_SPEED (0xFFFFF) //!< max value of SPEED
Davidroid 0:92706998571a 138 #define L6470_MAX_ACC (0xFFF) //!< max value of ACC
Davidroid 0:92706998571a 139 #define L6470_MAX_DEC (0xFFF) //!< max value of DEC
Davidroid 0:92706998571a 140 #define L6470_MAX_MAX_SPEED (0x3FF) //!< max value of MAX_SPEED
Davidroid 0:92706998571a 141 #define L6470_MAX_MIN_SPEED (0xFFF) //!< max value of MIN_SPEED
Davidroid 0:92706998571a 142 #define L6470_MAX_FS_SPD (0x3FF) //!< max value of FS_SPD
Davidroid 0:92706998571a 143 #define L6470_MAX_INT_SPEED (0x3FFF) //!< max value of INT_SPEED
Davidroid 0:92706998571a 144 #define L6470_MAX_ST_SLP (0xFF) //!< max value of ST_SLP
Davidroid 0:92706998571a 145 #define L6470_MAX_FN_SLP_ACC (0xFF) //!< max value of FN_SLP_ACC
Davidroid 0:92706998571a 146 #define L6470_MAX_FN_SLP_DEC (0xFF) //!< max value of FN_SLP_DEC
Davidroid 0:92706998571a 147 #define L6470_MAX_OCD_TH (0xF) //!< max value of OCD_TH
Davidroid 0:92706998571a 148 #define L6470_MAX_STALL_TH (0x7F) //!< max value of STALL_TH
Davidroid 0:92706998571a 149
Davidroid 0:92706998571a 150 /**
Davidroid 0:92706998571a 151 * @}
Davidroid 0:92706998571a 152 */ /* End of L6470_Register_Max_Values */
Davidroid 0:92706998571a 153
Davidroid 0:92706998571a 154 #define L6470REGIDSIZE 25 //!< Max number of identifiers of L6470 Registers
Davidroid 0:92706998571a 155 #define L6470APPCMDIDSIZE 19 //!< Max number of identifiers of L6470 Application Commands
Davidroid 0:92706998571a 156 #define L6470DIRIDSIZE 2 //!< Max number of identifiers of L6470 directions
Davidroid 0:92706998571a 157 #define L6470ACTIDSIZE 2 //!< Max number of identifiers of actions to perform about ABS_POS register
Davidroid 0:92706998571a 158 #define L6470MAXSPICMDBYTESIZE 4 //!< Max number of byte to send via SPI to perform an application command
Davidroid 0:92706998571a 159 #define L6470DAISYCHAINSIZE 2 //!< Max number of identifiers of L6470 in daisy chain configuration
Davidroid 0:92706998571a 160
Davidroid 0:92706998571a 161 #define L6470_MAX_SPEED_VALUE ((float)15610) //!< max value for the speed in step/s
Davidroid 0:92706998571a 162 #define L6470_MAX_ACC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2
Davidroid 0:92706998571a 163 #define L6470_MAX_DEC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2
Davidroid 0:92706998571a 164 #define L6470_MAX_DEC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2
Davidroid 0:92706998571a 165
Davidroid 0:92706998571a 166 #define OCD_TH_STEP ((float)375) //!< Minimum step for OCD_TH register in mAmpere
Davidroid 0:92706998571a 167 #define STALL_TH_STEP ((float)31.25) //!< Minimum step for STALL_TH register in mAmpere
Davidroid 0:92706998571a 168
Davidroid 0:92706998571a 169 #define L6470_ACC_CONV ((float)0.068719) //!< Conversion factor for acceleration value from step/s^2 to the right value
Davidroid 0:92706998571a 170 #define L6470_DEC_CONV ((float)0.068719) //!< Conversion factor for deceleration value from step/s^2 to the right value
Davidroid 0:92706998571a 171 #define L6470_MAXSPEED_CONV ((float)0.065536) //!< Conversion factor for max speed value from step/s to the right value
Davidroid 0:92706998571a 172 #define L6470_MINSPEED_CONV ((float)4.194304) //!< Conversion factor for min speed value from step/s to the right value
Davidroid 0:92706998571a 173 #define L6470_SPEED_CONV ((float)67.108864) //!< Conversion factor for speed value from step/s to the right value
Davidroid 0:92706998571a 174
Davidroid 0:92706998571a 175
Davidroid 0:92706998571a 176 /**
Davidroid 0:92706998571a 177 * @brief L6470 driver data structure definition.
Davidroid 0:92706998571a 178 */
Davidroid 0:92706998571a 179 /* ACTION --------------------------------------------------------------------*
Davidroid 0:92706998571a 180 * Declare here the structure of component's data, if any, one variable per *
Davidroid 0:92706998571a 181 * line without initialization. *
Davidroid 0:92706998571a 182 * *
Davidroid 0:92706998571a 183 * Example: *
Davidroid 0:92706998571a 184 * typedef struct *
Davidroid 0:92706998571a 185 * { *
Davidroid 0:92706998571a 186 * int T0_out; *
Davidroid 0:92706998571a 187 * int T1_out; *
Davidroid 0:92706998571a 188 * float T0_degC; *
Davidroid 0:92706998571a 189 * float T1_degC; *
Davidroid 0:92706998571a 190 * } COMPONENT_DrvDataTypeDef; *
Davidroid 0:92706998571a 191 * ---------------------------------------------------------------------------*/
Davidroid 0:92706998571a 192 typedef struct
Davidroid 0:92706998571a 193 {
Davidroid 0:92706998571a 194 uint8_t L6470_Id; //!< The L6470 identifier inside the daisy chain
Davidroid 0:92706998571a 195 sL6470_Register_t *L6470_Register; //[L6470REGIDSIZE]; //!< Array whose elements are a structure in which store information about the L6470 Registers (the address, the names, the length in bits, the reset value)
Davidroid 0:92706998571a 196 sL6470_ApplicationCommand_t *L6470_ApplicationCommand; //[L6470APPCMDIDSIZE]; //!< Array whose elements are a structure in which store information about the L6470 Application Commands (the mnemonic name, the number of needed parameters, the related funtion to call)
Davidroid 0:92706998571a 197 sL6470_Direction_t *L6470_Direction; //[L6470DIRIDSIZE]; //!< The mnemonic names for the L6470 direction
Davidroid 0:92706998571a 198 sL6470_ACT_t *L6470_ACT; //[L6470ACTIDSIZE]; //!< Action taken about ABS_POS register
Davidroid 0:92706998571a 199 sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; //!< To store the identifier of the actual L6470 application command and its the needed parameters
Davidroid 0:92706998571a 200 uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; //!< To store the matrix that contains the command data that are going to be sent by SPI to the L6470 daisy chain
Davidroid 0:92706998571a 201 uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; //!< To store the matrix that contains the received data by SPI from the L6470 daisy chain
Davidroid 0:92706998571a 202 eFlagStatus_t L6470_DaisyChain_HalfPrepared; /* = ZERO_F; */ //!< Boolean variable used when more than one L6470 into the daisy chain is going to be addressed for commanding
Davidroid 0:92706998571a 203 sL6470_StatusRegister_t L6470_StatusRegister; //!< To store the received L6470_StatusRegister
Davidroid 0:92706998571a 204 sL6470_StatusRegister_t *pL6470_StatusRegister; /* = &L6470_StatusRegister; */ //!< Pointer to the L6470_StatusRegister variable
Davidroid 0:92706998571a 205 } L6470_DrvDataTypeDef;
Davidroid 0:92706998571a 206
Davidroid 0:92706998571a 207
Davidroid 0:92706998571a 208 /* Functions -----------------------------------------------------------------*/
Davidroid 0:92706998571a 209
Davidroid 0:92706998571a 210 /** @addtogroup BSP
Davidroid 0:92706998571a 211 * @{
Davidroid 0:92706998571a 212 */
Davidroid 0:92706998571a 213
Davidroid 0:92706998571a 214 /** @addtogroup Components
Davidroid 0:92706998571a 215 * @{
Davidroid 0:92706998571a 216 */
Davidroid 0:92706998571a 217
Davidroid 0:92706998571a 218 /** @addtogroup L6470
Davidroid 0:92706998571a 219 * @{
Davidroid 0:92706998571a 220 */
Davidroid 0:92706998571a 221
Davidroid 0:92706998571a 222 /** @defgroup L6470_IO_Functions L6470_IO_Functions
Davidroid 0:92706998571a 223 * @{
Davidroid 0:92706998571a 224 */
Davidroid 0:92706998571a 225 /* ACTION --------------------------------------------------------------------*
Davidroid 0:92706998571a 226 * Declare here extern I/O functions you need and implemented them in a glue *
Davidroid 0:92706998571a 227 * logic file on the target environment, for example within the expansion *
Davidroid 0:92706998571a 228 * board "*.c" file. E.g.: *
Davidroid 0:92706998571a 229 * extern DrvStatusTypeDef COMPONENT_IO_Read (handle, buf, regadd, bytes); *
Davidroid 0:92706998571a 230 * extern DrvStatusTypeDef COMPONENT_IO_Write(handle, buf, regadd, bytes); *
Davidroid 0:92706998571a 231 *----------------------------------------------------------------------------*/
Davidroid 0:92706998571a 232 extern void L6470_DISABLE(void);
Davidroid 0:92706998571a 233 extern void L6470_ENABLE(void);
Davidroid 0:92706998571a 234 extern void L6470_nCS_LOW(void);
Davidroid 0:92706998571a 235 extern void L6470_nCS_HIGH(void);
Davidroid 0:92706998571a 236 extern void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
Davidroid 0:92706998571a 237
Davidroid 0:92706998571a 238 /**
Davidroid 0:92706998571a 239 * @}
Davidroid 0:92706998571a 240 */ /* End of L6470_Exported_Variables */
Davidroid 0:92706998571a 241
Davidroid 0:92706998571a 242 /**
Davidroid 0:92706998571a 243 * @}
Davidroid 0:92706998571a 244 */ /* End of L6470 */
Davidroid 0:92706998571a 245
Davidroid 0:92706998571a 246 /**
Davidroid 0:92706998571a 247 * @}
Davidroid 0:92706998571a 248 */ /* End of Components */
Davidroid 0:92706998571a 249
Davidroid 0:92706998571a 250 /**
Davidroid 0:92706998571a 251 * @}
Davidroid 0:92706998571a 252 */ /* End of BSP */
Davidroid 0:92706998571a 253
Davidroid 0:92706998571a 254 #ifdef __cplusplus
Davidroid 0:92706998571a 255 }
Davidroid 0:92706998571a 256 #endif
Davidroid 0:92706998571a 257
Davidroid 0:92706998571a 258 #endif /* __L6470_H */
Davidroid 0:92706998571a 259
Davidroid 0:92706998571a 260 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/