当前位置:   article > 正文

STM32模拟SPI协议获取24位模数转换(24bit ADC)芯片AD7791电压采样数据

ad7791

STM32模拟SPI协议获取24位模数转换(24bit ADC)芯片AD7791电压采样数据

STM32大部分芯片只有12位的ADC采样性能,如果要实现更高精度的模数转换如24位ADC采样,则需要连接外部ADC实现。AD7791是亚德诺(ADI)半导体一款用于低功耗、24位Σ-Δ型模数转换器(ADC) ,适合低频测量应用,提供50 Hz/60 Hz同步抑制。

这里介绍基于AD7791的24位ADC采样实现。

AD7791控制协议

AD7791的管脚如下所示:
在这里插入图片描述
AD7791可以工作在2.5V~5.25V供电范围(VDD),而用于模数转换的参考电压可以通过引脚REFIN(+)和REFIN(–)单独设置,从而可以针对特定电压范围更高精度的采样。如果REFIN(+) - REFIN(–) = 1V, 则对应24位采样分辨率率为1/(2^24)=0.00000006V。当然要使得这个级别的电压分辨率有效,对电路噪声的控制要求也很高。
AIN(+)和AIN(-)用于连接输入信号,通过芯片内部寄存器配置,有两种转换模式,即AIN(+)相对AIN(-)是单边电压或双边电压。单边电压模式,采样值0x000000对应AIN(+)-AIN(-)=0,采样值0xFFFFFF对应AIN(+)-AIN(-)=REFIN(+) - REFIN(–) 。双边电压模式,采样值0x000000对应AIN(+)-AIN(-)=-(REFIN(+) - REFIN(–)),采样值0x800000对应AIN(+)-AIN(-)=0,采样值0xFFFFFF对应AIN(+)-AIN(-)=REFIN(+) - REFIN(–) 。
AD7791通过SPI总线进行访问控制,其中数据输出管脚DOUT也是转换完成可读取指示信号/RDY, 访问协议操作主要逻辑如下:

  1. 向通讯寄存器发送指令,设置采样的通道和读操作模式(单次或连续),并且设置下一次访问是对哪个寄存器进行操作,以及进行的是读还是写;
  2. 写模式寄存器,设置采用单次转换还是连续转换模式,单边还是双边转换模式,以及是否buffered模式(buffered模式对应信号接收管脚端接收阻抗高阻模式),以及buffered模式是否在输入端引用100ns电流源;
  3. 在配置模式寄存器后,可以再向通讯寄存器发送指令指示后续读取数据寄存器,然后按照24位格式读取采样到的ADC值;
  4. 芯片支持对供电电压的采样识别,原理为供电电压内部LDO降压到1.17V作为VDD采样电路的参考供电,而VDD本身分压到1/5接到ADC采样端。所以供电电压识别为( VDD采样值 / 16777216 ) * 1.17 * 5 V.
  5. 可配置滤波寄存器以控制采样转换输出频率,影响到噪声抑制级别;
  6. 可以读取状态寄存器获得一些状态信息。

STM32工程配置

这里以STM32F103C6T6及STM32CUBEIDE开发工具为例,介绍AD7791的24位ADC采样实现。

首先建立基本工程并配置时钟:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置一个串口如UART2作为通讯打印输出口
在这里插入图片描述
再选择4根管脚作为模拟协议用的GPIO, 这里用PA15作为CS,PB3作为CLK,PB4作为MISO, PB5作为MOSI,各管脚上外部电阻上拉到AD7791的供电电压,STM32的管脚配置为Open-drain模式,从而可以兼容不同供电电压的AD7791访问连接, 因此STM32的GPIO也都选择为具有FT(5V耐压)能力的管脚。
在这里插入图片描述
保存并生成基本工程代码:
在这里插入图片描述

STM32工程代码

AD7791的ADC数据读取有5种模式:

  1. 单次转换单次单读
  2. 单次转换多次单读(读到同样的数据)
  3. 连续转换单次单读
  4. 连续转换多次单读
  5. 连续抓换多次连读
    其中单读和连续的区别是,单读的每次读取前要发送一次写操作,连续的所有读取前只发送一次写操作。这里的工程代码对5种模式都做了函数实现。

代码采用的微秒级延时函数实现,参考: STM32 HAL us delay(微秒延时)的指令延时实现方式及优化
代码用到串口打印printf函数的重载及采用的浮点转换函数,参考: STM32 UART串口printf函数应用及浮点打印代码空间节省 (HAL)

完整的main.c工程代码如下:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usart.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
__IO float usDelayBase;
void PY_usDelayTest(void)
{
  __IO uint32_t firstms, secondms;
  __IO uint32_t counter = 0;

  firstms = HAL_GetTick()+1;
  secondms = firstms+1;

  while(uwTick!=firstms) ;

  while(uwTick!=secondms) counter++;

  usDelayBase = ((float)counter)/1000;
}

void PY_Delay_us_t(uint32_t Delay)
{
  __IO uint32_t delayReg;
  __IO uint32_t usNum = (uint32_t)(Delay*usDelayBase);

  delayReg = 0;
  while(delayReg!=usNum) delayReg++;
}

void PY_usDelayOptimize(void)
{
  __IO uint32_t firstms, secondms;
  __IO float coe = 1.0;

  firstms = HAL_GetTick();
  PY_Delay_us_t(1000000) ;
  secondms = HAL_GetTick();

  coe = ((float)1000)/(secondms-firstms);
  usDelayBase = coe*usDelayBase;
}


void PY_Delay_us(uint32_t Delay)
{
  __IO uint32_t delayReg;

  __IO uint32_t msNum = Delay/1000;
  __IO uint32_t usNum = (uint32_t)((Delay%1000)*usDelayBase);

  if(msNum>0) HAL_Delay(msNum);

  delayReg = 0;
  while(delayReg!=usNum) delayReg++;
}

/*
*Convert float to string type
*Written by Pegasus Yu in 2022
*stra: string address as mychar from char mychar[];
*float: float input like 12.345
*flen: fraction length as 3 for 12.345
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
void py_f2s4printf(char * stra, float x, uint8_t flen)
{
	uint32_t base;
	int64_t dn;
	char mc[32];

	base = pow(10,flen);
	dn = x*base;
	sprintf(stra, "%d.", (int)(dn/base));
	dn = abs(dn);
	if(dn%base==0)
	{
		for(uint8_t j=1;j<=flen;j++)
		{
			stra = strcat(stra, "0");
		}
		return;
	}
	else
	{
		if(flen==1){
			sprintf(mc, "%d", (int)(dn%base));
			stra = strcat(stra, mc);
			return;
		}

		for(uint8_t j=1;j<flen;j++)
		{
			if((dn%base)<pow(10,j))
			{
				for(uint8_t k=1;k<=(flen-j);k++)
				{
					stra = strcat(stra, "0");
				}
				sprintf(mc, "%d", (int)(dn%base));
				stra = strcat(stra, mc);
				return;
			}
		}
		sprintf(mc, "%d", (int)(dn%base));
		stra = strcat(stra, mc);
		return;
	}
}
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
#define   AD7791_CS_LOW      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET)
#define   AD7791_CS_HIGH     HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET)
#define   AD7791_CLK_LOW     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET)
#define   AD7791_CLK_HIGH    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET)
#define   AD7791_DIN_LOW     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET)
#define   AD7791_DIN_HIGH    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET)
#define   AD7791_DOUT_nRDY         HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4)

void AD7791_RST(void)
{
/*
 * The serial interface can be reset by writing a series of 1s on the DIN input. If a Logic 1 is written to the AD7791 line for at least
 * 32 serial clock cycles, the serial interface is reset.
 *
 * The DOUT/ RDY pin operates as a Data Ready signal also, the line going low when a new data-word is available in the output register.
 * It is reset high when a read operation from the data register is complete.
 * It also goes high prior to the updating of the data register to indicate when not to read from the device to ensure that a data read is
 * not attempted while the register is being updated.
 */
  AD7791_CS_HIGH;
  AD7791_DIN_HIGH;
  AD7791_CLK_HIGH;

  AD7791_CS_LOW;
  PY_Delay_us_t(1);

  for(uint8_t i=0;i<32;i++)
  {
	AD7791_CLK_LOW;
	PY_Delay_us_t(1);
	AD7791_CLK_HIGH;
	PY_Delay_us_t(1);
  }

  AD7791_DIN_LOW;
  AD7791_CS_HIGH;
}

/*
 * write access to any of the other registers on the part begins with a write operation to the communications register followed by a
 * write to the selected register.
 * A read operation from any other register (except when continuous read mode is selected) starts
 * with a write to the communications register followed by a read operation from the selected register.
 */

void AD7791_WR_1BYTE(uint8_t cmd) //write 8-bit data
{
  for(uint8_t i=0; i<8; i++)
	{
	   AD7791_CLK_LOW;
	   if ((cmd<<i)&0x80) AD7791_DIN_HIGH;
       else AD7791_DIN_LOW;
	   PY_Delay_us_t(1);
       AD7791_CLK_HIGH;
       PY_Delay_us_t(1);
	}

}

uint32_t AD7791_RD_3BYTE(void) //read 24-bit data
{
  uint8_t rbit = 0;
  uint32_t rdata = 0;

  for(uint8_t i=1; i<=24; i++)
  {
	PY_Delay_us_t(1);
	AD7791_CLK_LOW;
	PY_Delay_us_t(1);
	AD7791_CLK_HIGH;
	rbit = AD7791_DOUT_nRDY;
	if (rbit != 0) rdata |= (((uint32_t)rbit)<<(24-i));
  }

  return rdata;
}

void AD7791_POWER_DOWN(void)
{
	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x10);
	AD7791_WR_1BYTE(0xc4);

	AD7791_CS_HIGH;
}

uint8_t AD7791_READ_STATUS_REG(void)
{
   uint8_t rbit = 0;
   uint8_t rdata = 0;

    AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x08);

	AD7791_DIN_LOW;
	AD7791_CLK_HIGH;

	for(uint8_t i=1; i<=8; i++)
	{
		PY_Delay_us_t(1);
		AD7791_CLK_LOW;
		PY_Delay_us_t(1);
		AD7791_CLK_HIGH;
		rbit = AD7791_DOUT_nRDY;
		if (rbit != 0) rdata |= ((rbit)<<(8-i));
	}

	AD7791_CS_HIGH;
	return rdata;
}

uint8_t AD7791_SET_FILTER_REG(uint8_t data)
{
	/*
	 * Due to chip fault, 0 or 1 written to lowest bit of filter register will become 1. So to write 0x04 will get back-read value 0x05.
	 * So don't write filter register if you want to keep 0x04 in filter register which will be filled 0x04 when power up.
	 */
	uint8_t mode = 0x04; //default: clock without division, 16.6Hz output rate
	uint8_t rbit = 0;
	uint8_t rdata = 0;

	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x20);

	mode = data;
	AD7791_WR_1BYTE(mode);

	AD7791_CS_HIGH;
	AD7791_RST();
	PY_Delay_us_t(1);

	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x28);

	AD7791_DIN_LOW;
	AD7791_CLK_HIGH;

	for(uint8_t i=1; i<=8; i++)
	{
		PY_Delay_us_t(1);
		AD7791_CLK_LOW;
		PY_Delay_us_t(1);
		AD7791_CLK_HIGH;
		rbit = AD7791_DOUT_nRDY;
		if (rbit != 0) rdata |= ((rbit)<<(8-i));
	}

	AD7791_CS_HIGH;
	return rdata;

}

uint32_t AD7791_SAMPLE_VDD_SINGLE(void)
{
/*
* Along with converting external voltages, the analog input chan-nel can be used to monitor the voltage on the VDD pin.
* When the CH1 and CH0 bits in the communications register are set to 1,
* the voltage on the VDD pin is internally attenuated by 5 and the resultant voltage is applied to the Σ-Δ modulator using an internal 1.17 V reference for analog to digital conversion.
*/
  uint32_t vdd = 0;

  AD7791_CLK_HIGH;
  AD7791_CS_LOW;

  AD7791_WR_1BYTE(0x17);
  AD7791_WR_1BYTE(0x06);

  while(AD7791_DOUT_nRDY) ;

  AD7791_WR_1BYTE(0x3f);
  vdd = AD7791_RD_3BYTE();

  AD7791_CS_HIGH;
  AD7791_RST();

  return vdd;

/*
 * voltage = (vdd/16777216)*1.17*5
 */
}


/* *
 * Mode1: single conversion mode + single read mode : get one-time 24-bit data (write operation advanced before read operation)
 * Mode2: single conversion mode + multi-time single read mode: get multi-time same 24-bit data (write operation advanced before every read operation)
 * Mode3: continuous conversion mode + single read mode: get one-time 24-bit data (write operation advanced before read operation)
 * Mode4: continuous conversion mode + multi-time single read mode: get multi-time individual 24-bit data (write operation advanced before every read operation)
 * Mode5: continuous conversion mode + continuous read mode: get multi-time individual 24-bit data (only once write operation for all read operations)
 */

void AD7791_Mode1_RD(uint32_t *result)
{
	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	//AD7791_WR_1BYTE(0x12); //used for AIN(–) – AIN(–) test only
	AD7791_WR_1BYTE(0x10);
	AD7791_WR_1BYTE(0x86);//single conversion mode, no burn-out current, uni-polar and buffered

	while(AD7791_DOUT_nRDY) ;

	AD7791_WR_1BYTE(0x38);//single read
	(*result) =  AD7791_RD_3BYTE();

	AD7791_CS_HIGH;

	AD7791_RST();
}

void AD7791_Mode2_RD(uint32_t *result, uint32_t times)
{
	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x10);
	AD7791_WR_1BYTE(0x86);//single conversion mode, no burn-out current, uni-polar and buffered

	while(AD7791_DOUT_nRDY) ;

	for(uint32_t i=0; i<times; i++)
	{
		AD7791_WR_1BYTE(0x38);//single read
		result[i] = AD7791_RD_3BYTE();
		PY_Delay_us_t(1);
	}

	AD7791_CS_HIGH;

	AD7791_RST();
}

void AD7791_Mode3_RD(uint32_t *result)
{
	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x10);
	AD7791_WR_1BYTE(0x06);//continuous conversion mode, no burn-out current, uni-polar and buffered

	while(AD7791_DOUT_nRDY) ;

	AD7791_WR_1BYTE(0x38);//single read
	(*result) =  AD7791_RD_3BYTE();

	AD7791_CS_HIGH;

	AD7791_RST();
}

void AD7791_Mode4_RD(uint32_t *result, uint32_t times)
{
	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x10);
	AD7791_WR_1BYTE(0x06);//continuous conversion mode, no burn-out current, uni-polar and buffered

	for(uint32_t i=0; i<times; i++)
	{
		while(AD7791_DOUT_nRDY) ;

		AD7791_WR_1BYTE(0x38);//single read
		result[i] =  AD7791_RD_3BYTE();

		PY_Delay_us_t(1);
	}

	AD7791_CS_HIGH;

	AD7791_RST();
}

void AD7791_Mode5_RD(uint32_t *result, uint32_t times)
{
	AD7791_CLK_HIGH;
	AD7791_CS_LOW;

	AD7791_WR_1BYTE(0x10);
	AD7791_WR_1BYTE(0x06);//continuous conversion mode, no burn-out current, uni-polar and buffered
	AD7791_WR_1BYTE(0x3c);//continuous read

	for(uint32_t i=0; i<times; i++)
	{
		while(AD7791_DOUT_nRDY) ;
		result[i] =  AD7791_RD_3BYTE();
		PY_Delay_us_t(1);
	}

	AD7791_CS_HIGH;

	AD7791_RST();
}
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
	  uint32_t AData[128];
	  float vdd;
	  char mychar[100];
  /* 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_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
  PY_usDelayTest();
  PY_usDelayOptimize();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		 printf("Status Register Read Value=0x%02x\r\n", AD7791_READ_STATUS_REG());

	     printf("Filter Register Set Value=0x%02x\r\n", AD7791_SET_FILTER_REG(0x05));

		 vdd = ((float)AD7791_SAMPLE_VDD_SINGLE())*1.17*5/16777216;
		 py_f2s4printf(mychar, vdd, 6);
		 printf("VDD Sampling Read Value=%s V\r\n", mychar);

		 AD7791_Mode1_RD(AData);
		 printf("Mode 1 Signal Sampling Read Value=%d\r\n", AData[0]);

		 AD7791_Mode2_RD(AData, 4);
		 printf("Mode 2 Signal Sampling Read Value:\r\n%d\r\n%d\r\n%d\r\n%d\r\n", AData[0], AData[1], AData[2], AData[3]);

		 AD7791_Mode3_RD(AData);
		 printf("Mode 3 Signal Sampling Read Value=%d\r\n", AData[0]);

		 AD7791_Mode4_RD(AData, 4);
		 printf("Mode 4 Signal Sampling Read Value:\r\n%d\r\n%d\r\n%d\r\n%d\r\n", AData[0], AData[1], AData[2], AData[3]);

		 AD7791_Mode5_RD(AData, 4);
		 printf("Mode 5 Signal Sampling Read Value:\r\n%d\r\n%d\r\n%d\r\n%d\r\n", AData[0], AData[1], AData[2], AData[3]);

		 PY_Delay_us_t(1000000);
		 printf("\r\n");
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  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_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief USART2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART2_UART_Init(void)
{

  /* USER CODE BEGIN USART2_Init 0 */

  /* USER CODE END USART2_Init 0 */

  /* USER CODE BEGIN USART2_Init 1 */

  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */

  /* USER CODE END USART2_Init 2 */

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5, GPIO_PIN_SET);

  /*Configure GPIO pin : PA15 */
  GPIO_InitStruct.Pin = GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PB3 PB4 PB5 */
  GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683

STM32测试输出

串口测试输出如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

例程下载

STM32F103C6T6模拟SPI协议读取24位模数转换(24bit ADC)芯片AD7791数据例程

–End–

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/512764
推荐阅读
相关标签
  

闽ICP备14008679号