X-CUBE-SPN1-20150128 example source code for one motor compiled under mbed. Tested OK on Nucleo F401. l6474.cpp is modified from original with defines in l6474_target_config.h to select the original behaviour (motor de-energised when halted), or new mode to continue powering with a (reduced) current in the coils (braking/position hold capability). On F401 avoid using mbed's InterruptIn on pins 10-15 (any port). Beware of other conflicts! L0 & F0 are included but untested.

Dependencies:   mbed

Committer:
gregeric
Date:
Tue Oct 13 10:46:01 2015 +0000
Revision:
6:19c1b4a04c24
Parent:
1:75a41f0c0586
Ensure bridge is disabled before resetting the L6474.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gregeric 0:b9444a40a999 1 /**
gregeric 0:b9444a40a999 2 ******************************************************************************
gregeric 0:b9444a40a999 3 * @file Multi/Examples/MotionControl/IHM01A1_ExampleFor1Motor/Src/main.c
gregeric 0:b9444a40a999 4 * @author IPC Rennes
gregeric 0:b9444a40a999 5 * @version V1.5.0
gregeric 0:b9444a40a999 6 * @date November 12, 2014
gregeric 0:b9444a40a999 7 * @brief This example shows how to use 1 IHM01A1 expansion board
gregeric 0:b9444a40a999 8 ******************************************************************************
gregeric 0:b9444a40a999 9 * @attention
gregeric 0:b9444a40a999 10 *
gregeric 0:b9444a40a999 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
gregeric 0:b9444a40a999 12 *
gregeric 0:b9444a40a999 13 * Redistribution and use in source and binary forms, with or without modification,
gregeric 0:b9444a40a999 14 * are permitted provided that the following conditions are met:
gregeric 0:b9444a40a999 15 * 1. Redistributions of source code must retain the above copyright notice,
gregeric 0:b9444a40a999 16 * this list of conditions and the following disclaimer.
gregeric 0:b9444a40a999 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
gregeric 0:b9444a40a999 18 * this list of conditions and the following disclaimer in the documentation
gregeric 0:b9444a40a999 19 * and/or other materials provided with the distribution.
gregeric 0:b9444a40a999 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gregeric 0:b9444a40a999 21 * may be used to endorse or promote products derived from this software
gregeric 0:b9444a40a999 22 * without specific prior written permission.
gregeric 0:b9444a40a999 23 *
gregeric 0:b9444a40a999 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gregeric 0:b9444a40a999 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gregeric 0:b9444a40a999 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gregeric 0:b9444a40a999 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gregeric 0:b9444a40a999 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gregeric 0:b9444a40a999 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gregeric 0:b9444a40a999 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gregeric 0:b9444a40a999 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gregeric 0:b9444a40a999 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gregeric 0:b9444a40a999 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gregeric 0:b9444a40a999 34 *
gregeric 0:b9444a40a999 35 ******************************************************************************
gregeric 0:b9444a40a999 36 */
gregeric 0:b9444a40a999 37
gregeric 0:b9444a40a999 38 /* Includes ------------------------------------------------------------------*/
gregeric 0:b9444a40a999 39 #include "mbed.h"
gregeric 1:75a41f0c0586 40 #include "ihm01a1.h"
gregeric 0:b9444a40a999 41
gregeric 0:b9444a40a999 42 /** @defgroup IHM01A1_Example_for_1_motor_device
gregeric 0:b9444a40a999 43 * @{
gregeric 0:b9444a40a999 44 */
gregeric 0:b9444a40a999 45
gregeric 0:b9444a40a999 46 /* Private typedef -----------------------------------------------------------*/
gregeric 0:b9444a40a999 47 /* Private define ------------------------------------------------------------*/
gregeric 0:b9444a40a999 48 /* Private macro -------------------------------------------------------------*/
gregeric 0:b9444a40a999 49 /* Private variables ---------------------------------------------------------*/
gregeric 0:b9444a40a999 50 static volatile uint16_t gLastError;
gregeric 0:b9444a40a999 51
gregeric 0:b9444a40a999 52 /* Private function prototypes -----------------------------------------------*/
gregeric 0:b9444a40a999 53 static void MyFlagInterruptHandler(void);
gregeric 0:b9444a40a999 54
gregeric 0:b9444a40a999 55 /* Private functions ---------------------------------------------------------*/
gregeric 0:b9444a40a999 56
gregeric 0:b9444a40a999 57 /**
gregeric 0:b9444a40a999 58 * @brief Main program
gregeric 0:b9444a40a999 59 * @param None
gregeric 0:b9444a40a999 60 * @retval None
gregeric 0:b9444a40a999 61 */
gregeric 0:b9444a40a999 62 int main(void)
gregeric 0:b9444a40a999 63 {
gregeric 0:b9444a40a999 64 int32_t pos;
gregeric 0:b9444a40a999 65 uint16_t mySpeed;
gregeric 0:b9444a40a999 66
gregeric 0:b9444a40a999 67 /* STM32xx HAL library initialization */
gregeric 0:b9444a40a999 68 // HAL_Init();
gregeric 0:b9444a40a999 69
gregeric 0:b9444a40a999 70 /* Configure the system clock */
gregeric 0:b9444a40a999 71 //mbed SystemClock_Config();
gregeric 0:b9444a40a999 72
gregeric 0:b9444a40a999 73 //----- Init of the Motor control library
gregeric 0:b9444a40a999 74 /* Start the L6474 library to use 1 device */
gregeric 0:b9444a40a999 75 /* The L6474 registers are set with the predefined values */
gregeric 0:b9444a40a999 76 /* from file l6474_target_config.h*/
gregeric 0:b9444a40a999 77 BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6474, 1);
gregeric 0:b9444a40a999 78
gregeric 0:b9444a40a999 79 /* Attach the function MyFlagInterruptHandler (defined below) to the flag interrupt */
gregeric 0:b9444a40a999 80 BSP_MotorControl_AttachFlagInterrupt(MyFlagInterruptHandler);
gregeric 0:b9444a40a999 81
gregeric 0:b9444a40a999 82 /* Attach the function Error_Handler (defined below) to the error Handler*/
gregeric 0:b9444a40a999 83 BSP_MotorControl_AttachErrorHandler(Error_Handler);
gregeric 0:b9444a40a999 84
gregeric 0:b9444a40a999 85 //----- Move of 16000 steps in the FW direction
gregeric 0:b9444a40a999 86
gregeric 0:b9444a40a999 87 /* Move device 0 of 16000 steps in the FORWARD direction*/
gregeric 0:b9444a40a999 88 BSP_MotorControl_Move(0, FORWARD, 16000);
gregeric 0:b9444a40a999 89
gregeric 0:b9444a40a999 90 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 91 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 92
gregeric 0:b9444a40a999 93 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 94 HAL_Delay(2000);
gregeric 0:b9444a40a999 95
gregeric 0:b9444a40a999 96 //----- Move of 16000 steps in the BW direction
gregeric 0:b9444a40a999 97
gregeric 0:b9444a40a999 98 /* Move device 0 of 16000 steps in the BACKWARD direction*/
gregeric 0:b9444a40a999 99 BSP_MotorControl_Move(0, BACKWARD, 16000);
gregeric 0:b9444a40a999 100
gregeric 0:b9444a40a999 101 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 102 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 103
gregeric 0:b9444a40a999 104 /* Set the current position of device 0 to be the Home position */
gregeric 0:b9444a40a999 105 BSP_MotorControl_SetHome(0);
gregeric 0:b9444a40a999 106
gregeric 0:b9444a40a999 107 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 108 HAL_Delay(2000);
gregeric 0:b9444a40a999 109
gregeric 0:b9444a40a999 110 //----- Go to position -6400
gregeric 0:b9444a40a999 111
gregeric 0:b9444a40a999 112 /* Request device 0 to go to position -6400 */
gregeric 0:b9444a40a999 113 BSP_MotorControl_GoTo(0,-6400);
gregeric 0:b9444a40a999 114
gregeric 0:b9444a40a999 115 /* Wait for the motor ends moving */
gregeric 0:b9444a40a999 116 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 117
gregeric 0:b9444a40a999 118 /* Get current position of device 0*/
gregeric 0:b9444a40a999 119 pos = BSP_MotorControl_GetPosition(0);
gregeric 0:b9444a40a999 120
gregeric 0:b9444a40a999 121 if (pos != -6400)
gregeric 0:b9444a40a999 122 {
gregeric 0:b9444a40a999 123 Error_Handler(11);
gregeric 0:b9444a40a999 124 }
gregeric 0:b9444a40a999 125
gregeric 0:b9444a40a999 126 /* Set the current position of device 0 to be the Mark position */
gregeric 0:b9444a40a999 127 BSP_MotorControl_SetMark(0);
gregeric 0:b9444a40a999 128
gregeric 0:b9444a40a999 129 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 130 HAL_Delay(2000);
gregeric 0:b9444a40a999 131
gregeric 0:b9444a40a999 132 //----- Go Home
gregeric 0:b9444a40a999 133
gregeric 0:b9444a40a999 134 /* Request device 0 to go to Home */
gregeric 0:b9444a40a999 135 BSP_MotorControl_GoHome(0);
gregeric 0:b9444a40a999 136 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 137
gregeric 0:b9444a40a999 138 /* Get current position of device 0 */
gregeric 0:b9444a40a999 139 pos = BSP_MotorControl_GetPosition(0);
gregeric 0:b9444a40a999 140
gregeric 0:b9444a40a999 141 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 142 HAL_Delay(2000);
gregeric 0:b9444a40a999 143
gregeric 0:b9444a40a999 144 //----- Go to position 6400
gregeric 0:b9444a40a999 145
gregeric 0:b9444a40a999 146 /* Request device 0 to go to position 6400 */
gregeric 0:b9444a40a999 147 BSP_MotorControl_GoTo(0,6400);
gregeric 0:b9444a40a999 148
gregeric 0:b9444a40a999 149 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 150 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 151
gregeric 0:b9444a40a999 152 /* Get current position of device 0*/
gregeric 0:b9444a40a999 153 pos = BSP_MotorControl_GetPosition(0);
gregeric 0:b9444a40a999 154
gregeric 0:b9444a40a999 155 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 156 HAL_Delay(2000);
gregeric 0:b9444a40a999 157
gregeric 0:b9444a40a999 158 //----- Go Mark which was set previously after go to -6400
gregeric 0:b9444a40a999 159
gregeric 0:b9444a40a999 160 /* Request device 0 to go to Mark position */
gregeric 0:b9444a40a999 161 BSP_MotorControl_GoMark(0);
gregeric 0:b9444a40a999 162
gregeric 0:b9444a40a999 163 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 164 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 165
gregeric 0:b9444a40a999 166 /* Get current position of device 0 */
gregeric 0:b9444a40a999 167 pos = BSP_MotorControl_GetPosition(0);
gregeric 0:b9444a40a999 168
gregeric 0:b9444a40a999 169 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 170 HAL_Delay(2000);
gregeric 0:b9444a40a999 171
gregeric 0:b9444a40a999 172 //----- Run the motor BACKWARD
gregeric 0:b9444a40a999 173
gregeric 0:b9444a40a999 174 /* Request device 0 to run BACKWARD */
gregeric 0:b9444a40a999 175 BSP_MotorControl_Run(0,BACKWARD);
gregeric 0:b9444a40a999 176 HAL_Delay(5000);
gregeric 0:b9444a40a999 177
gregeric 0:b9444a40a999 178 /* Get current speed of device 0 */
gregeric 0:b9444a40a999 179 mySpeed = BSP_MotorControl_GetCurrentSpeed(0);
gregeric 0:b9444a40a999 180
gregeric 0:b9444a40a999 181 //----- Increase the speed while running
gregeric 0:b9444a40a999 182
gregeric 0:b9444a40a999 183 /* Increase speed of device 0 to 2400 step/s */
gregeric 0:b9444a40a999 184 BSP_MotorControl_SetMaxSpeed(0,4800);
gregeric 0:b9444a40a999 185 HAL_Delay(9000);
gregeric 0:b9444a40a999 186
gregeric 0:b9444a40a999 187 /* Get current speed of device 0 */
gregeric 0:b9444a40a999 188 mySpeed = BSP_MotorControl_GetCurrentSpeed(0);
gregeric 0:b9444a40a999 189
gregeric 0:b9444a40a999 190 //----- Decrease the speed while running
gregeric 0:b9444a40a999 191
gregeric 0:b9444a40a999 192 /* Decrease speed of device 0 to 1200 step/s */
gregeric 0:b9444a40a999 193 BSP_MotorControl_SetMaxSpeed(0,1200);
gregeric 0:b9444a40a999 194 HAL_Delay(5000);
gregeric 0:b9444a40a999 195
gregeric 0:b9444a40a999 196 /* Get current speed */
gregeric 0:b9444a40a999 197 mySpeed = BSP_MotorControl_GetCurrentSpeed(0);
gregeric 0:b9444a40a999 198
gregeric 0:b9444a40a999 199 //----- Increase acceleration while running
gregeric 0:b9444a40a999 200
gregeric 0:b9444a40a999 201 /* Increase acceleration of device 0 to 480 step/s^2 */
gregeric 0:b9444a40a999 202 BSP_MotorControl_SetAcceleration(0,480);
gregeric 0:b9444a40a999 203 HAL_Delay(5000);
gregeric 0:b9444a40a999 204
gregeric 0:b9444a40a999 205 /* Increase speed of device 0 to 2400 step/s */
gregeric 0:b9444a40a999 206 BSP_MotorControl_SetMaxSpeed(0,2400);
gregeric 0:b9444a40a999 207 HAL_Delay(5000);
gregeric 0:b9444a40a999 208
gregeric 0:b9444a40a999 209 /* Get current speed of device 0 */
gregeric 0:b9444a40a999 210 mySpeed = BSP_MotorControl_GetCurrentSpeed(0);
gregeric 0:b9444a40a999 211
gregeric 0:b9444a40a999 212 if (mySpeed != 2400)
gregeric 0:b9444a40a999 213 {
gregeric 0:b9444a40a999 214 Error_Handler(10);
gregeric 0:b9444a40a999 215 }
gregeric 0:b9444a40a999 216 //----- Increase deceleration while running
gregeric 0:b9444a40a999 217
gregeric 0:b9444a40a999 218 /* Increase deceleration of device 0 to 480 step/s^2 */
gregeric 0:b9444a40a999 219 BSP_MotorControl_SetDeceleration(0,480);
gregeric 0:b9444a40a999 220 HAL_Delay(5000);
gregeric 0:b9444a40a999 221
gregeric 0:b9444a40a999 222 /* Decrease speed of device 0 to 1200 step/s */
gregeric 0:b9444a40a999 223 BSP_MotorControl_SetMaxSpeed(0,1200);
gregeric 0:b9444a40a999 224 HAL_Delay(5000);
gregeric 0:b9444a40a999 225
gregeric 0:b9444a40a999 226 /* Get current speed */
gregeric 0:b9444a40a999 227 mySpeed = BSP_MotorControl_GetCurrentSpeed(0);
gregeric 0:b9444a40a999 228
gregeric 0:b9444a40a999 229 //----- Soft stopped required while running
gregeric 0:b9444a40a999 230
gregeric 0:b9444a40a999 231 /* Request soft stop of device 0 */
gregeric 0:b9444a40a999 232 BSP_MotorControl_SoftStop(0);
gregeric 0:b9444a40a999 233
gregeric 0:b9444a40a999 234 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 235 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 236
gregeric 0:b9444a40a999 237 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 238 HAL_Delay(2000);
gregeric 0:b9444a40a999 239
gregeric 0:b9444a40a999 240 //----- Run stopped by hardstop
gregeric 0:b9444a40a999 241
gregeric 0:b9444a40a999 242 /* Request device 0 to run in FORWARD direction */
gregeric 0:b9444a40a999 243 BSP_MotorControl_Run(0,FORWARD);
gregeric 0:b9444a40a999 244 HAL_Delay(5000);
gregeric 0:b9444a40a999 245
gregeric 0:b9444a40a999 246 /* Request device 0 to immediatly stop */
gregeric 0:b9444a40a999 247 BSP_MotorControl_HardStop(0);
gregeric 0:b9444a40a999 248 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 249
gregeric 0:b9444a40a999 250 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 251 HAL_Delay(2000);
gregeric 0:b9444a40a999 252
gregeric 0:b9444a40a999 253 //----- GOTO stopped by softstop
gregeric 0:b9444a40a999 254
gregeric 0:b9444a40a999 255 /* Request device 0 to go to position 20000 */
gregeric 0:b9444a40a999 256 BSP_MotorControl_GoTo(0,20000);
gregeric 0:b9444a40a999 257 HAL_Delay(5000);
gregeric 0:b9444a40a999 258
gregeric 0:b9444a40a999 259 /* Request device 0 to perform a soft stop */
gregeric 0:b9444a40a999 260 BSP_MotorControl_SoftStop(0);
gregeric 0:b9444a40a999 261 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 262
gregeric 0:b9444a40a999 263 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 264 HAL_Delay(2000);
gregeric 0:b9444a40a999 265
gregeric 0:b9444a40a999 266 //----- Read inexistent register to test MyFlagInterruptHandler
gregeric 0:b9444a40a999 267
gregeric 0:b9444a40a999 268 /* Try to read an inexistent register */
gregeric 0:b9444a40a999 269 /* the flag interrupt should be raised */
gregeric 0:b9444a40a999 270 /* and the MyFlagInterruptHandler function called */
gregeric 0:b9444a40a999 271 BSP_MotorControl_CmdGetParam(0,0x1F);
gregeric 0:b9444a40a999 272 HAL_Delay(500);
gregeric 0:b9444a40a999 273
gregeric 0:b9444a40a999 274 //----- Change step mode to full step mode
gregeric 0:b9444a40a999 275
gregeric 0:b9444a40a999 276 /* Select full step mode for device 0 */
gregeric 0:b9444a40a999 277 BSP_MotorControl_SelectStepMode(0,STEP_MODE_FULL);
gregeric 0:b9444a40a999 278
gregeric 0:b9444a40a999 279 /* Set speed and acceleration to be consistent with full step mode */
gregeric 0:b9444a40a999 280 BSP_MotorControl_SetMaxSpeed(0,100);
gregeric 0:b9444a40a999 281 BSP_MotorControl_SetMinSpeed(0,50);
gregeric 0:b9444a40a999 282 BSP_MotorControl_SetAcceleration(0,10);
gregeric 0:b9444a40a999 283 BSP_MotorControl_SetDeceleration(0,10);
gregeric 0:b9444a40a999 284
gregeric 0:b9444a40a999 285 /* Request device 0 to go position 200 */
gregeric 0:b9444a40a999 286 BSP_MotorControl_GoTo(0,200);
gregeric 0:b9444a40a999 287
gregeric 0:b9444a40a999 288 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 289 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 290
gregeric 0:b9444a40a999 291 /* Get current position */
gregeric 0:b9444a40a999 292 pos = BSP_MotorControl_GetPosition(0);
gregeric 0:b9444a40a999 293
gregeric 0:b9444a40a999 294 /* Wait for 2 seconds */
gregeric 0:b9444a40a999 295 HAL_Delay(2000);
gregeric 0:b9444a40a999 296
gregeric 0:b9444a40a999 297 //----- Restore 1/16 microstepping mode
gregeric 0:b9444a40a999 298
gregeric 0:b9444a40a999 299 /* Reset device 0 to 1/16 microstepping mode */
gregeric 0:b9444a40a999 300 BSP_MotorControl_SelectStepMode(0,STEP_MODE_1_16); //_FULL _HALF 1_16
gregeric 0:b9444a40a999 301
gregeric 0:b9444a40a999 302 /* Update speed, acceleration, deceleration for 1/16 microstepping mode*/
gregeric 0:b9444a40a999 303 BSP_MotorControl_SetMaxSpeed(0,40000);
gregeric 0:b9444a40a999 304 BSP_MotorControl_SetMinSpeed(0,800);
gregeric 0:b9444a40a999 305 BSP_MotorControl_SetAcceleration(0,160);
gregeric 0:b9444a40a999 306 BSP_MotorControl_SetDeceleration(0,160);
gregeric 0:b9444a40a999 307
gregeric 0:b9444a40a999 308 /* Infinite loop */
gregeric 0:b9444a40a999 309 while(1)
gregeric 0:b9444a40a999 310 {
gregeric 0:b9444a40a999 311 /* Request device 0 to go position -6400 */
gregeric 0:b9444a40a999 312 BSP_MotorControl_GoTo(0,-6400);
gregeric 0:b9444a40a999 313
gregeric 0:b9444a40a999 314 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 315 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 316
gregeric 0:b9444a40a999 317 /* Request device 0 to go position 6400 */
gregeric 0:b9444a40a999 318 BSP_MotorControl_GoTo(0,6400);
gregeric 0:b9444a40a999 319
gregeric 0:b9444a40a999 320 /* Wait for the motor of device 0 ends moving */
gregeric 0:b9444a40a999 321 BSP_MotorControl_WaitWhileActive(0);
gregeric 0:b9444a40a999 322 }
gregeric 0:b9444a40a999 323 }
gregeric 0:b9444a40a999 324
gregeric 0:b9444a40a999 325 /**
gregeric 0:b9444a40a999 326 * @brief This function is the User handler for the flag interrupt
gregeric 0:b9444a40a999 327 * @param None
gregeric 0:b9444a40a999 328 * @retval None
gregeric 0:b9444a40a999 329 */
gregeric 0:b9444a40a999 330 void MyFlagInterruptHandler(void)
gregeric 0:b9444a40a999 331 {
gregeric 0:b9444a40a999 332 /* Get the value of the status register via the L6474 command GET_STATUS */
gregeric 0:b9444a40a999 333 uint16_t statusRegister = BSP_MotorControl_CmdGetStatus(0);
gregeric 0:b9444a40a999 334
gregeric 0:b9444a40a999 335 /* Check HIZ flag: if set, power brigdes are disabled */
gregeric 0:b9444a40a999 336 if ((statusRegister & L6474_STATUS_HIZ) == L6474_STATUS_HIZ)
gregeric 0:b9444a40a999 337 {
gregeric 0:b9444a40a999 338 // HIZ state
gregeric 0:b9444a40a999 339 // Action to be customized
gregeric 0:b9444a40a999 340 }
gregeric 0:b9444a40a999 341
gregeric 0:b9444a40a999 342 /* Check direction bit */
gregeric 0:b9444a40a999 343 if ((statusRegister & L6474_STATUS_DIR) == L6474_STATUS_DIR)
gregeric 0:b9444a40a999 344 {
gregeric 0:b9444a40a999 345 // Forward direction is set
gregeric 0:b9444a40a999 346 // Action to be customized
gregeric 0:b9444a40a999 347 }
gregeric 0:b9444a40a999 348 else
gregeric 0:b9444a40a999 349 {
gregeric 0:b9444a40a999 350 // Backward direction is set
gregeric 0:b9444a40a999 351 // Action to be customized
gregeric 0:b9444a40a999 352 }
gregeric 0:b9444a40a999 353
gregeric 0:b9444a40a999 354 /* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed */
gregeric 0:b9444a40a999 355 /* This often occures when a command is sent to the L6474 */
gregeric 0:b9444a40a999 356 /* while it is in HIZ state */
gregeric 0:b9444a40a999 357 if ((statusRegister & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD)
gregeric 0:b9444a40a999 358 {
gregeric 0:b9444a40a999 359 // Command received by SPI can't be performed
gregeric 0:b9444a40a999 360 // Action to be customized
gregeric 0:b9444a40a999 361 }
gregeric 0:b9444a40a999 362
gregeric 0:b9444a40a999 363 /* Check WRONG_CMD flag: if set, the command does not exist */
gregeric 0:b9444a40a999 364 if ((statusRegister & L6474_STATUS_WRONG_CMD) == L6474_STATUS_WRONG_CMD)
gregeric 0:b9444a40a999 365 {
gregeric 0:b9444a40a999 366 //command received by SPI does not exist
gregeric 0:b9444a40a999 367 // Action to be customized
gregeric 0:b9444a40a999 368 }
gregeric 0:b9444a40a999 369
gregeric 0:b9444a40a999 370 /* Check UVLO flag: if not set, there is an undervoltage lock-out */
gregeric 0:b9444a40a999 371 if ((statusRegister & L6474_STATUS_UVLO) == 0)
gregeric 0:b9444a40a999 372 {
gregeric 0:b9444a40a999 373 //undervoltage lock-out
gregeric 0:b9444a40a999 374 // Action to be customized
gregeric 0:b9444a40a999 375 }
gregeric 0:b9444a40a999 376
gregeric 0:b9444a40a999 377 /* Check TH_WRN flag: if not set, the thermal warning threshold is reached */
gregeric 0:b9444a40a999 378 if ((statusRegister & L6474_STATUS_TH_WRN) == 0)
gregeric 0:b9444a40a999 379 {
gregeric 0:b9444a40a999 380 //thermal warning threshold is reached
gregeric 0:b9444a40a999 381 // Action to be customized
gregeric 0:b9444a40a999 382 }
gregeric 0:b9444a40a999 383
gregeric 0:b9444a40a999 384 /* Check TH_SHD flag: if not set, the thermal shut down threshold is reached */
gregeric 0:b9444a40a999 385 if ((statusRegister & L6474_STATUS_TH_SD) == 0)
gregeric 0:b9444a40a999 386 {
gregeric 0:b9444a40a999 387 //thermal shut down threshold is reached
gregeric 0:b9444a40a999 388 // Action to be customized
gregeric 0:b9444a40a999 389 }
gregeric 0:b9444a40a999 390
gregeric 0:b9444a40a999 391 /* Check OCD flag: if not set, there is an overcurrent detection */
gregeric 0:b9444a40a999 392 if ((statusRegister & L6474_STATUS_OCD) == 0)
gregeric 0:b9444a40a999 393 {
gregeric 0:b9444a40a999 394 //overcurrent detection
gregeric 0:b9444a40a999 395 // Action to be customized
gregeric 0:b9444a40a999 396 }
gregeric 0:b9444a40a999 397
gregeric 0:b9444a40a999 398 }
gregeric 0:b9444a40a999 399
gregeric 0:b9444a40a999 400 /**
gregeric 0:b9444a40a999 401 * @brief This function is executed in case of error occurrence.
gregeric 0:b9444a40a999 402 * @param error number of the error
gregeric 0:b9444a40a999 403 * @retval None
gregeric 0:b9444a40a999 404 */
gregeric 0:b9444a40a999 405 void Error_Handler(uint16_t error)
gregeric 0:b9444a40a999 406 {
gregeric 0:b9444a40a999 407 /* Backup error number */
gregeric 0:b9444a40a999 408 gLastError = error;
gregeric 0:b9444a40a999 409
gregeric 0:b9444a40a999 410 /* Infinite loop */
gregeric 0:b9444a40a999 411 while(1)
gregeric 0:b9444a40a999 412 {
gregeric 0:b9444a40a999 413 }
gregeric 0:b9444a40a999 414 }
gregeric 0:b9444a40a999 415
gregeric 0:b9444a40a999 416 #ifdef USE_FULL_ASSERT
gregeric 0:b9444a40a999 417
gregeric 0:b9444a40a999 418 /**
gregeric 0:b9444a40a999 419 * @brief Reports the name of the source file and the source line number
gregeric 0:b9444a40a999 420 * where the assert_param error has occurred.
gregeric 0:b9444a40a999 421 * @param file: pointer to the source file name
gregeric 0:b9444a40a999 422 * @param line: assert_param error line source number
gregeric 0:b9444a40a999 423 * @retval None
gregeric 0:b9444a40a999 424 */
gregeric 0:b9444a40a999 425 void assert_failed(uint8_t* file, uint32_t line)
gregeric 0:b9444a40a999 426 {
gregeric 0:b9444a40a999 427 /* User can add his own implementation to report the file name and line number,
gregeric 0:b9444a40a999 428 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
gregeric 0:b9444a40a999 429
gregeric 0:b9444a40a999 430 /* Infinite loop */
gregeric 0:b9444a40a999 431 while (1)
gregeric 0:b9444a40a999 432 {
gregeric 0:b9444a40a999 433 }
gregeric 0:b9444a40a999 434 }
gregeric 0:b9444a40a999 435 #endif
gregeric 0:b9444a40a999 436
gregeric 0:b9444a40a999 437 /**
gregeric 0:b9444a40a999 438 * @}
gregeric 0:b9444a40a999 439 */
gregeric 0:b9444a40a999 440
gregeric 0:b9444a40a999 441
gregeric 0:b9444a40a999 442 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/