/** ****************************************************************************** * @file main.c * @author Ac6 * @version V1.0 * @date 01-December-2013 * @brief Default main function. ****************************************************************************** */ #include "stm32f4xx.h" #include "stm32f4_discovery.h" #include "tm_stm32f4_lis302dl_lis3dsh.h" TM_LIS302DL_LIS3DSH_t Axes_Data; double x,y,z; double sumakwadratow; int main(void) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); unsigned int i; typedef enum { TM_LIS302DL_LIS3DSH_Device_Error, TM_LIS302DL_LIS3DSH_Device_LIS302DL, TM_LIS302DL_LIS3DSH_Device_LIS3DSH } TM_LIS302DL_LIS3DSH_Device_t; typedef struct { int16_t X; int16_t Y; int16_t Z; } TM_LIS302DL_LIS3DSH_t; TM_LIS302DL_LIS3DSH_Init(TM_LIS302DL_Sensitivity_2_3G, TM_LIS302DL_Filter_2Hz); TM_LIS302DL_LIS3DSH_Device_t IMU_Type; IMU_Type = TM_LIS302DL_LIS3DSH_Detect(); for(;;) { TM_LIS302DL_LIS3DSH_ReadAxes(&Axes_Data); x=(double)Axes_Data.X*0.01796875; y=(double)Axes_Data.Y*0.01796875; z=(double)Axes_Data.Z*0.01796875; sumakwadratow = x*x + y*y + z*z; if(sumakwadratow>=1) { GPIO_SetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); } else { GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); } } }