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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

基于STM32F0的ADS1118驅動源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:304483 發表于 2018-4-9 16:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
項目用到ADS1118作為AD采集,項目使用MCU為STM32F030,使用STM32CubeMX建立工程

單片機源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   ** This notice applies to any and all portions of this file
  7.   * that are not between comment pairs USER CODE BEGIN and
  8.   * USER CODE END. Other portions of this file, whether
  9.   * inserted by the user or by software development tools
  10.   * are owned by their respective copyright owners.
  11.   *
  12.   * COPYRIGHT(c) 2018 STMicroelectronics
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "stm32f0xx_hal.h"
  41. #include "spi.h"
  42. #include "gpio.h"

  43. /* USER CODE BEGIN Includes */
  44. #include "ads1118.h"
  45. /* USER CODE END Includes */

  46. /* Private variables ---------------------------------------------------------*/

  47. /* USER CODE BEGIN PV */
  48. /* Private variables ---------------------------------------------------------*/

  49. /* USER CODE END PV */

  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);

  52. /* USER CODE BEGIN PFP */
  53. /* Private function prototypes -----------------------------------------------*/

  54. /* USER CODE END PFP */

  55. /* USER CODE BEGIN 0 */
  56. uint16_t ConversionValue;
  57. float ad;
  58. uint16_t count = 0xC283;//0x8283;
  59. /* USER CODE END 0 */
  60. void delay1(uint32_t x)        //x=100W 延時1s(不精確)
  61. {
  62.         uint32_t i=0;
  63.         while(x--)
  64.         {
  65.                 i=10;
  66.                 while(i--);
  67.         }
  68. }
  69.         uint16_t adValue[4];
  70.         uint32_t conversion;
  71.         uint32_t config;
  72.         float adV[4];
  73. int main(void)
  74. {

  75.   /* USER CODE BEGIN 1 */
  76.         int i = 0;

  77.   /* USER CODE END 1 */

  78.   /* MCU Configuration----------------------------------------------------------*/

  79.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  80.   HAL_Init();

  81.   /* USER CODE BEGIN Init */

  82.   /* USER CODE END Init */

  83.   /* Configure the system clock */
  84.   SystemClock_Config();

  85.   /* USER CODE BEGIN SysInit */

  86.   /* USER CODE END SysInit */

  87.   /* Initialize all configured peripherals */
  88.   MX_GPIO_Init();
  89.   MX_SPI1_Init();
  90.        

  91.   /* USER CODE BEGIN 2 */

  92.   /* USER CODE END 2 */

  93.   /* Infinite loop */
  94.   /* USER CODE BEGIN WHILE */
  95.   while (1)
  96.   {
  97.   /* USER CODE END WHILE */

  98.   /* USER CODE BEGIN 3 */
  99.                 switch(i) {
  100.                 case 0:
  101.                         count = 0xc283;
  102.                         break;
  103.                 case 1:
  104.                         count = 0xd283;
  105.                         break;
  106.                 case 2:
  107.                         count = 0xe283;
  108.                         break;
  109.                 case 3:
  110.                         count = 0xf283;
  111.                         break;
  112.                 default:
  113.                         count = 0xc283;
  114.                         i = 0;
  115.                         break;
  116.                 }
  117. //                ConversionValue = SPI_RW_Reg(count);
  118. //                ad = ConversionValue * 4.096 / 32768;
  119.                
  120.                 conversion = SPI_RW_Reg(count);
  121.                 config = conversion & 0x0000FFFE;
  122.                 switch(config) {
  123.                 case 0x4282:
  124.                         adValue[3] = conversion >> 16;
  125.                         adV[3] = adValue[3] * 4.096 / 32768;
  126.                         break;
  127.                 case 0x5282:
  128.                         adValue[0] = conversion >> 16;
  129.                         adV[0] = adValue[0] * 4.096 / 32768;
  130.                         break;
  131.                 case 0x6282:
  132.                         adValue[1] = conversion >> 16;
  133.                         adV[1] = adValue[1] * 4.096 / 32768;
  134.                         break;
  135.                 case 0x7282:
  136.                         adValue[2] = conversion >> 16;
  137.                         adV[2] = adValue[2] * 4.096 / 32768;
  138.                         break;
  139.                 default:

  140.                         break;
  141.                 }
  142. //                adV[i] = adValue[i] * 4.096 / 32768;
  143. //               
  144. //                i++;
  145.                 if(++i > 3)        i = 0;
  146.                
  147.                 delay1(0x00009fff);
  148.   }
  149.   /* USER CODE END 3 */

  150. }

  151. /** System Clock Configuration
  152. */
  153. void SystemClock_Config(void)
  154. {

  155.   RCC_OscInitTypeDef RCC_OscInitStruct;
  156.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  157.     /**Initializes the CPU, AHB and APB busses clocks
  158.     */
  159.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  160.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  161.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  162.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  163.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  164.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  165.   RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  166.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  167.   {
  168.     _Error_Handler(__FILE__, __LINE__);
  169.   }

  170.     /**Initializes the CPU, AHB and APB busses clocks
  171.     */
  172.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  173.                               |RCC_CLOCKTYPE_PCLK1;
  174.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  175.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  176.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  177.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  178.   {
  179.     _Error_Handler(__FILE__, __LINE__);
  180.   }

  181.     /**Configure the Systick interrupt time
  182.     */
  183.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  184.     /**Configure the Systick
  185.     */
  186.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  187.   /* SysTick_IRQn interrupt configuration */
  188.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  189. }

  190. /* USER CODE BEGIN 4 */

  191. /* USER CODE END 4 */

  192. /**
  193.   * @brief  This function is executed in case of error occurrence.
  194.   * @param  None
  195.   * @retval None
  196.   */
  197. void _Error_Handler(char * file, int line)
  198. {
  199.   /* USER CODE BEGIN Error_Handler_Debug */
  200.   /* User can add his own implementation to report the HAL error return state */
  201.   while(1)
  202.   {
  203.   }
  204.   /* USER CODE END Error_Handler_Debug */
  205. }

  206. #ifdef USE_FULL_ASSERT

  207. /**
  208.    * @brief Reports the name of the source file and the source line number
  209.    * where the assert_param error has occurred.
  210.    * @param file: pointer to the source file name
  211.    * @param line: assert_param error line source number
  212.    * @retval None
  213.    */
  214. void assert_failed(uint8_t* file, uint32_t line)
  215. {
  216.   /* USER CODE BEGIN 6 */
  217.   /* User can add his own implementation to report the file name and line number,
  218.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  219.   /* USER CODE END 6 */

  220. }

  221. #endif

  222. /**
  223.   * @}
  224.   */

  225. /**
  226.   * @}
  227. */

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

所有資料51hei提供下載:
ADS1118.rar (3.33 MB, 下載次數: 144)


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

沙發
ID:268693 發表于 2018-5-10 16:56 | 只看該作者
學習了!感謝!
回復

使用道具 舉報

板凳
ID:366340 發表于 2018-7-12 17:11 | 只看該作者
學寫了,一起努力,發放
回復

使用道具 舉報

地板
ID:259517 發表于 2018-7-12 18:53 | 只看該作者
感謝分享
回復

使用道具 舉報

5#
ID:314158 發表于 2019-7-25 18:53 來自觸屏版 | 只看該作者
謝謝分享
回復

使用道具 舉報

6#
ID:457079 發表于 2019-7-29 22:40 | 只看該作者
有點東西啊!謝謝啦
回復

使用道具 舉報

7#
ID:613280 發表于 2019-9-20 15:12 | 只看該作者
已下載,謝謝!
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久91精品国产一区二区 | 亚洲三级在线观看 | 黄色在线免费观看 | 欧美精品一区二区三区在线播放 | 日韩av一区在线观看 | 久久久久国产精品一区二区 | 男女视频在线观看 | 亚洲男人网 | 久久亚洲天堂 | 福利社午夜影院 | 日韩在线一区二区三区 | 欧美一区二区视频 | 色婷婷狠狠 | 亚洲精品欧美 | 性高朝久久久久久久3小时 av一区二区三区四区 | 91国产精品在线 | 99精品视频网 | 婷婷综合| 二区久久| 成年人在线播放 | 国产一区二区三区在线视频 | 亚洲成a| 国产黄色网址在线观看 | 国产伦一区二区三区 | 日韩免费一区 | 亚洲精品中文字幕中文字幕 | 亚洲第一在线视频 | 国产美女精品视频 | 国产精品自产av一区二区三区 | 欧美久久国产精品 | 久久国产免费看 | 日韩成人影院在线观看 | 久久看看| 手机看片169 | 黄色大片毛片 | 日本在线综合 | 亚洲成人av一区二区 | 欧美h版| 岛国av一区二区 | 亚洲精品一区在线观看 | 日韩精品一区二区三区在线播放 |