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

Revision:
1:b78dab6d2c58
Parent:
0:92706998571a
Child:
3:e3f6f4474d98
--- a/BSP/x_nucleo_ihm02a1_class.h	Fri Nov 20 18:07:45 2015 +0000
+++ b/BSP/x_nucleo_ihm02a1_class.h	Wed Nov 25 11:59:37 2015 +0000
@@ -79,16 +79,18 @@
     /**
      * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
      * @param flag_irq      pin name of the FLAG pin of the component.
+     * @param busy_irq      pin name of the BUSY pin of the component.
      * @param standby_reset pin name of the STBY\RST pin of the component.
      * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
      * @param spi           SPI device to be used for communication.
      * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
      */
-    static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI *spi = NULL);
+    static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi = NULL);
 
     /**
      * @brief Getting a singleton instance of X_NUCLEO_IHM02A1 class.
      * @param flag_irq      pin name of the FLAG pin of the component.
+     * @param busy_irq      pin name of the BUSY pin of the component.
      * @param standby_reset pin name of the STBY\RST pin of the component.
      * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
      * @param mosi          pin name of the MOSI pin of the SPI device to be used for communication.
@@ -96,7 +98,7 @@
      * @param sclk          pin name of the SCLK pin of the SPI device to be used for communication.
      * @retval a singleton instance of X_NUCLEO_IHM02A1 class.
      */
-    static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName standby_reset, PinName ssel, PinName miso, PinName mosi, PinName sclk);
+    static X_NUCLEO_IHM02A1 *Instance(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, PinName miso, PinName mosi, PinName sclk);
 
     /**
      * @brief Initializing the X_NUCLEO_IHM02A1 board.
@@ -109,6 +111,47 @@
      */
     ~X_NUCLEO_IHM02A1(void) {}
 
+    /**
+     * @brief  Getting the array of components.
+     * @param  None.
+     * @retval The array of components.
+     */
+    L6470 **GetComponents(void)
+    {
+        return components;
+    }
+
+    /**
+      * @brief  Performing the actions set on the motors with calls to a number of
+      *         "Prepare<Action>()" methods, one for each motor of the daisy-chain.
+      * @param  None.
+      * @retval A pointer to the results returned by the components, i.e. an
+      *         integer value for each of them.
+      */
+    virtual uint32_t* PerformPreparedActions(void)
+    {
+        /* Performing pre-actions, if needed. */
+        for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
+        {
+            /*
+               "GetPosition()" is needed by "PrepareSetMark()" at the time when the
+               prepared actions get performed.
+            */
+            if (components[m]->GetPreparedAction() == L6470::PREPARED_SET_MARK)
+                components[m]->PrepareSetMark((uint32_t) components[m]->GetPosition());
+        }
+        
+        /* Performing the prepared actions and getting back raw data. */
+        uint8_t *raw_data = components[0]->PerformPreparedActions();
+
+        /* Processing raw data. */
+        for (int m = 0; m < L6470DAISYCHAINSIZE; m++)
+            results[m] = components[m]->GetResult(raw_data);
+
+        /* Returning results. */
+        return results;
+    }
+
 
     /*** Public Expansion Board Related Attributes ***/
 
@@ -135,11 +178,12 @@
     /**
      * @brief Constructor.
      * @param flag_irq      pin name of the FLAG pin of the component.
+     * @param busy_irq      pin name of the BUSY pin of the component.
      * @param standby_reset pin name of the STBY\RST pin of the component.
      * @param ssel          pin name of the SSEL pin of the SPI device to be used for communication.
      * @param spi           SPI device to be used for communication.
      */
-    X_NUCLEO_IHM02A1(PinName flag_irq, PinName standby_reset, PinName ssel, DevSPI *spi);
+    X_NUCLEO_IHM02A1(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName ssel, DevSPI *spi);
 
 
     /*** Protected Expansion Board Related Initialization Methods ***/
@@ -164,6 +208,12 @@
     /* IO Device. */
     DevSPI *dev_spi;
 
+    /* Components. */
+    L6470 *components[L6470DAISYCHAINSIZE];
+    
+    /* Results of prepared actions. */
+    uint32_t results[L6470DAISYCHAINSIZE];
+
     /* Data. */
     /* ACTION 11 -------------------------------------------------------------*
      * Declare here the component's data, one variable per line.              *