久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3980|回復: 4
打印 上一主題 下一主題
收起左側

stm32f411通過硬件i2c讀取mup9250數(shù)據(jù)的程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:336587 發(fā)表于 2018-5-25 11:57 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
stm32f411通過硬件i2c讀取數(shù)據(jù)的程序

單片機源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "main.h"
  3. #include "stm32f4xx_hal.h"
  4. #include "i2c.h"
  5. #include "usart.h"
  6. #include "gpio.h"
  7. #include "mpu9250.h"


  8. /* Private function prototypes -----------------------------------------------*/
  9. void SystemClock_Config(void);

  10. int main(void)
  11. {
  12.          short Accel[3];
  13.        
  14.   HAL_Init();
  15.   SystemClock_Config();
  16.   MX_GPIO_Init();
  17.   MX_USART2_UART_Init();
  18.   MX_I2C1_Init();
  19.         MPU9250_Init();
  20.         MPU9250_ID();

  21.   while (1)
  22.   {
  23.                 MPU9250ReadAcc(Accel);
  24.                 printf("%8d ,%8d ,%8d\r\n",Accel[0],Accel[1],Accel[2]);
  25.                 HAL_Delay(1);


  26.   }

  27. }

  28. /**
  29.   * @brief System Clock Configuration
  30.   * @retval None
  31.   */
  32. void SystemClock_Config(void)
  33. {

  34.   RCC_OscInitTypeDef RCC_OscInitStruct;
  35.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  36.     /**Configure the main internal regulator output voltage
  37.     */
  38.   __HAL_RCC_PWR_CLK_ENABLE();

  39.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  40.     /**Initializes the CPU, AHB and APB busses clocks
  41.     */
  42.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  43.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  44.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  45.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  46.   RCC_OscInitStruct.PLL.PLLM = 8;
  47.   RCC_OscInitStruct.PLL.PLLN = 144;
  48.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  49.   RCC_OscInitStruct.PLL.PLLQ = 4;
  50.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  51.   {
  52.     _Error_Handler(__FILE__, __LINE__);
  53.   }

  54.     /**Initializes the CPU, AHB and APB busses clocks
  55.     */
  56.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  57.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  58.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  59.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  60.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  61.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  62.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  63.   {
  64.     _Error_Handler(__FILE__, __LINE__);
  65.   }

  66.     /**Configure the Systick interrupt time
  67.     */
  68.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  69.     /**Configure the Systick
  70.     */
  71.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  72.   /* SysTick_IRQn interrupt configuration */
  73.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  74. }


  75. void _Error_Handler(char *file, int line)
  76. {
  77.   /* USER CODE BEGIN Error_Handler_Debug */
  78.   /* User can add his own implementation to report the HAL error return state */
  79.   while(1)
  80.   {
  81.   }
  82.   /* USER CODE END Error_Handler_Debug */
  83. }

  84. #ifdef  USE_FULL_ASSERT
  85. /**
  86.   * @brief  Reports the name of the source file and the source line number
  87.   *         where the assert_param error has occurred.
  88.   * @param  file: pointer to the source file name
  89.   * @param  line: assert_param error line source number
  90.   * @retval None
  91.   */
  92. void assert_failed(uint8_t* file, uint32_t line)
  93. {
  94.   /* USER CODE BEGIN 6 */
  95.   /* User can add his own implementation to report the file name and line number,
  96.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  97.   /* USER CODE END 6 */
  98. }
  99. #endif /* USE_FULL_ASSERT */

  100. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復制代碼

所有資料51hei提供下載:
stm32f411_mup9250.rar (504.16 KB, 下載次數(shù): 57)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:170522 發(fā)表于 2018-7-26 11:29 | 只看該作者
謝謝分享
回復

使用道具 舉報

板凳
ID:96552 發(fā)表于 2018-7-26 19:04 | 只看該作者

謝謝分享
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 啪啪免费 | 日韩欧美专区 | 国产精品综合色区在线观看 | 91tv在线观看 | 91精品国产一区二区三区蜜臀 | 黑色丝袜三级在线播放 | 91不卡| 午夜影院网站 | 欧美日韩在线精品 | 91资源在线| 在线观看你懂的网站 | 91在线第一页 | 欧美一区二区成人 | 欧美日韩成人在线 | 久久久久免费精品国产小说色大师 | 欧洲成人 | 欧美日韩高清在线一区 | 精品不卡 | 免费一区二区 | 国产精品mv在线观看 | 国产精品综合网 | 久久精品国产99国产精品 | 中文字幕第100页 | 欧美成人精品欧美一级 | 中文天堂在线观看 | 干一干操一操 | 欧美精品网站 | 日本手机在线 | 国产成人高清视频 | 99精品免费久久久久久久久日本 | 中文字幕1区2区 | 丝袜美腿一区二区三区动态图 | 亚洲国产成人精品久久久国产成人一区 | 国产精品一区一区三区 | 热99| 午夜伦理影院 | 成人影音| 国产ts人妖系列高潮 | 亚洲 中文 欧美 日韩 在线观看 | 国产精品一区二区欧美黑人喷潮水 | 欧美国产在线一区 |