Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "main.h"
  3. #include "dma.h"
  4. #include "spi.h"
  5. #include "gpio.h"
  6. #include "lis3dsh.h"
  7.  
  8. /* Private includes ----------------------------------------------------------*/
  9.  
  10. /* Private typedef -----------------------------------------------------------*/
  11.  
  12. /* Private define ------------------------------------------------------------*/
  13.  
  14. /* Private macro -------------------------------------------------------------*/
  15.  
  16. /* Private variables ---------------------------------------------------------*/
  17. uint8_t ACCEL_DRDY = 1;
  18. LIS3DSH_DataScaled LIS3DSHData;
  19. /* Private function prototypes -----------------------------------------------*/
  20. void SystemClock_Config(void);
  21.  
  22. /* Private user code ---------------------------------------------------------*/
  23.  
  24. /**
  25. * @brief The application entry point.
  26. * @retval int
  27. */
  28. int main(void)
  29. {
  30. HAL_Init();
  31. SystemClock_Config();
  32.  
  33. MX_GPIO_Init();
  34. MX_DMA_Init();
  35. MX_SPI1_Init();
  36.  
  37. LIS3DSH_Init();
  38.  
  39. while (1)
  40. {
  41. if (ACCEL_DRDY == 1)
  42. {
  43. ACCEL_DRDY = 0;
  44. LIS3DSHData = LIS3DSH_GetDataScaled();
  45. HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
  46. }
  47. }
  48. }
  49.  
  50. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  51. {
  52. if (GPIO_Pin == LIS3DSH_INT_Pin)
  53. {
  54. ACCEL_DRDY = 1;
  55. HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
  56. }
  57. }
  58.  
  59.  
  60. /**
  61. * @brief System Clock Configuration
  62. * @retval None
  63. */
  64. void SystemClock_Config(void)
  65. {
  66. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  67. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  68.  
  69. /** Configure the main internal regulator output voltage
  70. */
  71. __HAL_RCC_PWR_CLK_ENABLE();
  72. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  73. /** Initializes the CPU, AHB and APB busses clocks
  74. */
  75. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  76. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  77. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  78. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  79. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  80. RCC_OscInitStruct.PLL.PLLM = 8;
  81. RCC_OscInitStruct.PLL.PLLN = 50;
  82. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  83. RCC_OscInitStruct.PLL.PLLQ = 7;
  84. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  85. {
  86. Error_Handler();
  87. }
  88. /** Initializes the CPU, AHB and APB busses clocks
  89. */
  90. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
  91. | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  92. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  93. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  94. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  95. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
  96.  
  97. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  98. {
  99. Error_Handler();
  100. }
  101. }
  102.  
  103. /**
  104. * @brief This function is executed in case of error occurrence.
  105. * @retval None
  106. */
  107. void Error_Handler(void)
  108. {
  109. }
  110.  
  111. #ifdef USE_FULL_ASSERT
  112. /**
  113. * @brief Reports the name of the source file and the source line number
  114. * where the assert_param error has occurred.
  115. * @param file: pointer to the source file name
  116. * @param line: assert_param error line source number
  117. * @retval None
  118. */
  119. void assert_failed(uint8_t *file, uint32_t line)
  120. {
  121. /* USER CODE BEGIN 6 */
  122. /* User can add his own implementation to report the file name and line number,
  123. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  124. /* USER CODE END 6 */
  125. }
  126. #endif /* USE_FULL_ASSERT */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement