-

Dependencies:   X_NUCLEO_IHM01A1 mbed

Fork of joy_buttons_versao_2 by InsperX

Revision:
5:8065b587ade0
Parent:
3:fffa53c7aed2
Child:
6:32166bfc04b0
--- a/main.cpp	Thu Nov 19 14:26:05 2015 +0000
+++ b/main.cpp	Fri Nov 20 18:02:01 2015 +0000
@@ -63,6 +63,82 @@
 L6474 *motor;
 
 
+/* Functions -----------------------------------------------------------------*/
+
+/**
+  * @brief  This is an example of user handler for the flag interrupt.
+  * @param  None
+  * @retval None
+  * @note   If needed, implement it, and then attach and enable it:
+  *           + motor->AttachFlagIRQ(&FlagIRQHandler);
+  *           + motor->EnableFlagIRQ();
+  *         To disable it:
+  *           + motor->DisbleFlagIRQ();
+  */
+void FlagIRQHandler(void)
+{
+    /* Set ISR flag. */
+    motor->isrFlag = TRUE;
+
+    /* Get the value of the status register. */
+    unsigned int status = motor->GetStatus();
+    
+    /* Check HIZ flag: if set, power brigdes are disabled. */
+    if ((status & L6474_STATUS_HIZ) == L6474_STATUS_HIZ)
+    { /* HIZ state. Action to be customized. */ }
+    
+    /* Check direction. */
+    if ((status & L6474_STATUS_DIR) == L6474_STATUS_DIR)
+    { /* Forward direction is set. Action to be customized. */ }
+    else
+    { /* Backward direction is set. Action to be customized. */ }
+    
+    /* 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 in HIZ state. */
+    if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD)
+    { /* Command received by SPI can't be performed. Action to be customized. */ }
+    
+    /* Check WRONG_CMD flag: if set, the command does not exist. */
+    if ((status & L6474_STATUS_WRONG_CMD) == L6474_STATUS_WRONG_CMD)
+    { /* The command received by SPI does not exist. Action to be customized. */ }
+    
+    /* Check UVLO flag: if not set, there is an undervoltage lock-out. */
+    if ((status & L6474_STATUS_UVLO) == 0)
+    { /* Undervoltage lock-out. Action to be customized. */ }
+    
+    /* Check TH_WRN flag: if not set, the thermal warning threshold is reached. */
+    if ((status & L6474_STATUS_TH_WRN) == 0)
+    { /* Thermal warning threshold is reached. Action to be customized. */ }
+    
+    /* Check TH_SHD flag: if not set, the thermal shut down threshold is reached. */
+    if ((status & L6474_STATUS_TH_SD) == 0)
+    { /* Thermal shut down threshold is reached. Action to be customized. */ }
+    
+    /* Check OCD  flag: if not set, there is an overcurrent detection. */
+    if ((status & L6474_STATUS_OCD) == 0)
+    { /* Overcurrent detection. Action to be customized. */ }
+
+    /* Reset ISR flag. */
+    motor->isrFlag = FALSE;
+}
+
+/**
+  * @brief  This is an example of user handler for the errors.
+  * @param  error error-code.
+  * @retval None
+  * @note   If needed, implement it, and then attach it:
+  *           + motor->AttachErrorHandler(&ErrorHandler);
+  */
+void ErrorHandler(uint16_t error)
+{
+    /* Printing to the console. */
+    printf("Error: %d.\r\n", error);
+    
+    /* Aborting the program. */
+    exit(EXIT_FAILURE);
+}
+
+
 /* Main ----------------------------------------------------------------------*/
 
 int main()
@@ -71,7 +147,7 @@
     DevSPI dev_spi(D11, D12, D13);
 
     /* Initializing Motor Control Component. */
-    motor = new L6474(D8, D7, D9, D10, dev_spi);
+    motor = new L6474(D2, D8, D7, D9, D10, dev_spi);
     if (motor->Init(NULL) != COMPONENT_OK)
         return false;