Example using the LSM303 MEMS compass onboard the STM32F3-Discovery board.

Dependencies:   LSM303DLHC mbed

Files at this revision

API Documentation at this revision

Comitter:
Foxnec
Date:
Tue May 12 09:17:49 2015 +0000
Parent:
3:9b71b3bf2501
Commit message:
Changes to comments

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9b71b3bf2501 -r 5be48963926c main.cpp
--- a/main.cpp	Sun Mar 22 12:38:50 2015 +0000
+++ b/main.cpp	Tue May 12 09:17:49 2015 +0000
@@ -4,7 +4,7 @@
 * @version V1.00
 * @date    22-March-2015
 * @brief   LEDs blinking with LSM303.
-*          With push button pressed, LEDs are opossite.
+*          With push button pressed, LEDs are opposite.
 ***********************************************************************************/
 
 /**********************************************************************************/
@@ -18,12 +18,13 @@
 /* Includes ----------------------------------------------------------------------*/
 
 #include "mbed.h"
-#include "LSM303DLHC.h" //library necessary to comunicate with LSM303DLHC
+#include "LSM303DLHC.h"         //library necessary to comunicate with LSM303DLHC
 #include "stm32f3xx_hal_gpio.h" //library necessary to blink LEDs on STM32F3 discovery
 
 /* Defines -----------------------------------------------------------------------*/
 
-// In some mbed libraries are not included these definines
+// In some mbed libraries these defines are not included
+// please uncomment if the example is not working
 
 //#define GPIOE_BASE          (AHB2PERIPH_BASE + 0x1000)
 //#define GPIOE               ((GPIO_TypeDef *) GPIOE_BASE)
@@ -52,9 +53,9 @@
 *******************************************************************************/
 void pressed()
 {
-    // Toggle pins PE_15 to PE_8 , where LEDs are attached to
+    // Toggle pins PE_15 to PE_8, where LEDs are attached to
     HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8);
-    // oposit value of oppos
+    //inverts oppos
     oppos = !oppos;
 }
 
@@ -70,27 +71,27 @@
     float ax, ay, az;
     float mx, my, mz;
 
-   //inicialize power (clock source) to port E (GPIOE)
+   //initialize power (clock source) to port E (GPIOE)
     __GPIOE_CLK_ENABLE();
     //  RCC->AHBENR |= RCC_AHBPeriph_GPIOE; // if __GPIOE_CLK_ENABLE(); is not defined
 
-    //inicialize pins
-    // atructure to set GPIO
+    // initialize pins
+    // structure to set GPIO
     GPIO_InitTypeDef        GPIO_InitStruct;
-    //Specifies the operating mode for the selected pins.
+    // Specifies the operating mode for the selected pins.
     // Output Push Pull Mode 
     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-    //Specifies the Pull-up or Pull-Down activation for the selected pins.
-    //Pull-up activation
+    // Specifies the Pull-up or Pull-Down activation for the selected pins.
+    // Pull-up activation
     GPIO_InitStruct.Pull = GPIO_PULLUP;
-    //Specifies the speed for the selected pins.
-    //High speed
+    // Specifies the speed for the selected pins.
+    // High speed
     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    //Specifies the GPIO pins to be configured.
-    //Pins 15 to 8
+    // Specifies the GPIO pins to be configured.
+    // Pins 15 to 8
     GPIO_InitStruct.Pin = GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8;
     
-    //Inicialize pins PE_15 to PE_8
+    // Initialize pins PE_15 to PE_8
     HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); 
     
     // button was pressed, call function pressed
@@ -106,7 +107,7 @@
         heading=heading * (double)180 / 3.14159265359;
         //set LEDs
         if(heading>=338 || heading<23) { // compare angle
-            // on value oppos set (reset) one LED and other reset (set)
+            // on value oppos set (reset) one LED and reset the other (set)
             HAL_GPIO_WritePin(GPIOE,GPIO_PIN_15,oppos?GPIO_PIN_SET:GPIO_PIN_RESET);
             HAL_GPIO_WritePin(GPIOE,GPIO_PIN_14 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_9 | GPIO_PIN_8,oppos?GPIO_PIN_RESET:GPIO_PIN_SET);
         }