Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EsmacatShield X_NUCLEO_IHM01A1
Revision 5:8065b587ade0, committed 2015-11-20
- Comitter:
- Davidroid
- Date:
- Fri Nov 20 18:02:01 2015 +0000
- Parent:
- 4:cd1b33180e79
- Child:
- 6:32166bfc04b0
- Commit message:
- + FlagIRQHandler and ErrorHandler examples added.
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 Thu Nov 19 14:26:05 2015 +0000 +++ b/X_NUCLEO_IHM01A1.lib Fri Nov 20 18:02:01 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_IHM01A1/#a47569fc7534 +https://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_IHM01A1/#f7e0c3621f77
--- 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;