历史上的今天
今天是:2024年10月14日(星期一)
2019年10月14日 | 基于STM32F0的ADS1118驱动源程序
2019-10-14 来源:eefocus
项目用到ADS1118作为AD采集,项目使用MCU为STM32F030,使用STM32CubeMX建立工程
单片机源程序如下:
/**
******************************************************************************
* File Name : main.c
* Description : Main program body
******************************************************************************
** This notice applies to any and all portions of this file
* that are not between comment pairs USER CODE BEGIN and
* USER CODE END. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* COPYRIGHT(c) 2018 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f0xx_hal.h"
#include "spi.h"
#include "gpio.h"
/* USER CODE BEGIN Includes */
#include "ads1118.h"
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
uint16_t ConversionValue;
float ad;
uint16_t count = 0xC283;//0x8283;
/* USER CODE END 0 */
void delay1(uint32_t x) //x=100W 延时1s(不精确)
{
uint32_t i=0;
while(x--)
{
i=10;
while(i--);
}
}
uint16_t adValue[4];
uint32_t conversion;
uint32_t config;
float adV[4];
int main(void)
{
/* USER CODE BEGIN 1 */
int i = 0;
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
switch(i) {
case 0:
count = 0xc283;
break;
case 1:
count = 0xd283;
break;
case 2:
count = 0xe283;
break;
case 3:
count = 0xf283;
break;
default:
count = 0xc283;
i = 0;
break;
}
// ConversionValue = SPI_RW_Reg(count);
// ad = ConversionValue * 4.096 / 32768;
conversion = SPI_RW_Reg(count);
config = conversion & 0x0000FFFE;
switch(config) {
case 0x4282:
adValue[3] = conversion >> 16;
adV[3] = adValue[3] * 4.096 / 32768;
break;
case 0x5282:
adValue[0] = conversion >> 16;
adV[0] = adValue[0] * 4.096 / 32768;
break;
case 0x6282:
adValue[1] = conversion >> 16;
adV[1] = adValue[1] * 4.096 / 32768;
break;
case 0x7282:
adValue[2] = conversion >> 16;
adV[2] = adValue[2] * 4.096 / 32768;
break;
default:
break;
}
// adV[i] = adValue[i] * 4.096 / 32768;
//
// i++;
if(++i > 3) i = 0;
delay1(0x00009fff);
}
/* USER CODE END 3 */
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
史海拾趣
|
当我在对一个电路进行仿真时总是出现这些错误,但我又不知道什么意思,请各位高手指点一下。 非常感谢! C3 Error: Pin order data (PINS=1:[]) not in READ ONLY field 4. Pins sorted by pin-name. C3 Error ...… 查看全部问答> |
|
做了一个手写识别软件,用伪驱动的方法截获了全屏书写的轨迹。用手写笔在屏幕上书写的时候是可以收到轨迹信息的,也可以做出识别,但是手写笔在屏幕上画过的笔迹无法显示,在没有实现全屏书写的时候我在窗口里写实可以实时绘出手写轨迹的。下面是绘 ...… 查看全部问答> |
|
找两名兼职的WinCE内核开发人员,要求熟悉Marvell Xscale 系列CPU的内核和驱动开发工作, 要求熟悉一款以上以下的CPU: PXA255,PXA270,PXA310,PXA300,PXA320,PXA168. 地点在北京.有PDA或智能手机开发经验的人最佳. 熟悉三星的S3C6410的也可以,我 ...… 查看全部问答> |
|
我知道NK.bin文件头中是包含有NK的起始地址信息的,不知道nb0文件是否有? 我现在想通过NK.nb0进行升级,但是升级后需要保存NK.nb0拷贝到内存的地址到NAND Flash中,不知道NK.nb0文件是否有这个信息?… 查看全部问答> |
|
各位高手,本人基于课题需要,打算开发设计一个高速AD采样系统, 也许需要外检测电路+独立AD模块+嵌入式CPU组合实现 主要有以下要求: 1. AD模块的采样+转换时间=10MHz 2. CPU工作主频足够高,CPU内开辟一个足够大的缓存区,通过 ...… 查看全部问答> |
|
有冇朋友EDA编程叻噶??帮帮手啊·~~ 用VHDL设计一个倒计时计数器,预置一个四位十进制数,每个时钟脉冲到来减1,减到0即停止,发出时间到的报警信号。报警时,用50hz驱动蜂鸣器,发出报警声音。只提供一个1khz信号的 ...… 查看全部问答> |
|
小弟超菜 现在领的任务是用CETK测试无线网卡驱动 系统wince5.0,无线网卡i8686 开发板是自己公司做的,上面带的无线网卡驱动不是微软cetk中默认测试例子,看说明这种第三方驱动需要自行加入CETK 眼下问题关键就是怎么把Tux.dll和驱动的.dll连接 ...… 查看全部问答> |




