STM32模拟SPI时序控制双路16位数模转换(16bit DAC)芯片DAC8552电压输出

news2024/11/25 5:32:53

STM32模拟SPI时序控制双路16位数模转换(16bit DAC)芯片DAC8552电压输出

STM32部分芯片具有12位DAC输出能力,要实现16位及以上DAC输出需要外挂DAC转换ASIC。

DAC8552是双路16位DAC输出芯片,通过SPI三线总线进行配置控制输出。这里介绍通过GPIO管脚模拟时序进行控制的方式。

电路连接

DAC8552支持2.7V~5.5V的供电,根据需要提供电源电压,对于STM32可能面对不同供电电压的DAC8552, 因此STM32与DAC8552连接的三线,可以用10K电阻上拉到DAC8552的供电电压,而STM32选择支持FT(5V耐压)的三个管脚,并采用Open-drain无上下拉输出模式,从而可以兼容在各种供电条件下的DAC8552访问控制。对于STM32F103可以采用PB6, PB7和PB8进行连接,对于5V供电的DAC8552的连接如下图所示:

在这里插入图片描述

DAC8552控制协议

STM32通过发送24个位的SPI数据控制DAC8552的工作状态。其中前16个位为单路(通道A或通道B)的DAC配置值,后8个位为控制指令。
在这里插入图片描述
协议控制操作主要由两部分操作构成:

  1. 发送24位数据到某个通道的buffer
  2. 执行buffer里24位数据里的控制指令,即"load"某个通道,指令可能是通道关电,也可能是DAC电压根据配置数据值输出

在关电模式可以配置通道管脚处于1K下拉,100K下拉或高阻状态。操作方式比较多,如下图所示:
在这里插入图片描述
在这里插入图片描述
可以进行简化,对于通道配置只采用这几种指令:
在这里插入图片描述
对于通告关电只采用这几种:
在这里插入图片描述

STM32CUBEIDE工程配置

这里采用STM32CUBEIDE,对STM32F103C6T6芯片进行HAL库工程配置。
首先配置时钟系统:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
然后配置三线的管脚:
在这里插入图片描述
保存并生成基本:
在这里插入图片描述

STM32工程代码

SPI三线只向DAC8552单向发送数据进行控制。在SYNC即片选低电平期间,每个SCLK时钟下降沿DAC8552采样输入数据。

这里采用的微秒级延时函数,参考 STM32 HAL us delay(微秒延时)的指令延时实现方式及优化 。

首先定义管脚输出态:

#define   DAC8552_SYNC_LOW    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
#define   DAC8552_SYNC_HIGH   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
#define   DAC8552_DIN_LOW     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
#define   DAC8552_DIN_HIGH    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
#define   DAC8552_SCLK_LOW    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);
#define   DAC8552_SCLK_HIGH   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);

然后编写通道输出配置函数, 这里提供单通道和双通道配置的函数,以及单通道和双通道关电的函数:

void DAC8552_Set_Channel_A(uint16_t Data)
{
	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x10;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts
}

void DAC8552_Set_Channel_B(uint16_t Data)
{
	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x24;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts
}


void DAC8552_Set_Channel_AB(uint16_t Data)
{
	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x10;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x24;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts
}

void DAC8552_Set_PowerDown_1K_A(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x11;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_1K_B(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x25;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_1K_AB(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x11;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x25;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}


void DAC8552_Set_PowerDown_100K_A(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x12;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_100K_B(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x26;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_100K_AB(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x12;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x26;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_Hz_A(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x13;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_Hz_B(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x27;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_Hz_AB(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x13;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x27;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

就可以进行函数调用实现控制DAC8552双路的电压输出值。如控制A路为DAC8552参考电压的1/2, B路输出为DAC8552参考电压的3/4:

  DAC8552_Set_Channel_A(32768);
  DAC8552_Set_Channel_B(49152);

完整的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 */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
__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++;
}
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define   DAC8552_SYNC_LOW    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
#define   DAC8552_SYNC_HIGH   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
#define   DAC8552_DIN_LOW     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
#define   DAC8552_DIN_HIGH    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
#define   DAC8552_SCLK_LOW    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);
#define   DAC8552_SCLK_HIGH   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);

void DAC8552_Set_Channel_A(uint16_t Data)
{
	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x10;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts
}

void DAC8552_Set_Channel_B(uint16_t Data)
{
	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x24;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts
}


void DAC8552_Set_Channel_AB(uint16_t Data)
{
	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x10;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x24;
	WriteData = (CMD<<16) | Data;

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts
}

void DAC8552_Set_PowerDown_1K_A(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x11;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_1K_B(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x25;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_1K_AB(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x11;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x25;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}


void DAC8552_Set_PowerDown_100K_A(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x12;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_100K_B(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x26;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_100K_AB(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x12;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x26;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_Hz_A(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x13;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_Hz_B(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x27;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}

void DAC8552_Set_PowerDown_Hz_AB(void)
{

	uint8_t CMD = 0;
	uint32_t WriteData = 0;

	__disable_irq() ; //disable all interrupts

    CMD = 0x13;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;


    CMD = 0x27;
    WriteData = (CMD<<16);

	DAC8552_SYNC_HIGH;
	PY_Delay_us_t(1);
	DAC8552_SYNC_LOW;

	for(uint8_t i=0;i<24;i++)
	{
		if( (WriteData << i) & 0x800000 )
		{
			DAC8552_DIN_HIGH;
		}
		else
		{
			DAC8552_DIN_LOW;
		}

		DAC8552_SCLK_HIGH;
		PY_Delay_us_t(1);
		DAC8552_SCLK_LOW;
		PY_Delay_us_t(1);
	}

	DAC8552_SYNC_HIGH;

    __enable_irq() ;  //enable all interrupts

}
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_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 */

  /* 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();
  /* USER CODE BEGIN 2 */
  PY_usDelayTest();
  PY_usDelayOptimize();



  DAC8552_Set_Channel_A(32768);
  DAC8552_Set_Channel_B(49152);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  PY_Delay_us_t(1000000);
    /* 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 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_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8, GPIO_PIN_SET);

  /*Configure GPIO pins : PB6 PB7 PB8 */
  GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8;
  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 */

STM32例程下载

STM32F103C6T6模拟SPI时序控制DAC8552电压输出例程

–End–

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/392387.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

苹果新卫星专利公布,苹果Find My功能知多少

根据美国商标和专利局&#xff08;USPTO&#xff09;公示的清单&#xff0c;苹果公司获得了一项新的卫星专利&#xff0c;可在非地面网络&#xff08;Non-Terrestrial Networks&#xff0c;NTN&#xff09;中定位用户设备&#xff08;iDevice、MacBook 等&#xff09;。 在专利…

Docker(六)--Docker网络--单机与跨主机(macvlan)容器通信

文章目录一、本地节点通信1.DNS2.joind网络模式3.端口映射4.跨主机容器通信二、跨主机容器通信1.相同网段进行通信2.不同网段进行通信一、本地节点通信 1.DNS 容器之间除了使用ip通信外&#xff0c;还可以使用容器名称通信。docker 1.10开始&#xff0c;内嵌了一个DNS server。…

【算法进阶】回溯(backtracking)基本逻辑,以及常见回溯问题(全排列、解数独、八皇后)

文章目录一、引言二、回溯法基本逻辑三、回溯法代码模板三、回溯法常见问题3.1 组合逻辑代码3.2 子集逻辑代码3.3 子集Ⅱ&#xff08;未解答&#xff09;逻辑代码3.4 分割回文串逻辑代码3.5 组合总和Ⅰ逻辑代码3.6 组合总和Ⅱ&#xff08;未解答&#xff09;逻辑代码3.7 组合总…

Mycat

Mycat 1.概述 1.Mycat是数据中间件2.中间件:连接软件组件和应用的计算机软件,便于软件和各部件的交互3.数据中间件:连接Java应用程序与数据库的软件2.适用场景 1.Java与数据库紧耦合(直接连接)2.高访问量高并发对数据库压力(集群)3.读写请求数据不一致(读写分离+主从复制)3.…

关于Gooey复选框CheckBox的使用

折腾了我一下午 官网也没发现具体的使用方法 老是报错 索引超出范围 我就很疑惑 百度也没有答案后来我修改成了非必参 加-- 这是不选中操作这是选中操作他说必须要有一个参数 我有啊 没搞懂 后来 我就这样(根据他报错提示来的)果真就没了问题这样也没问题 具体我还是没搞懂 反正…

K_A16_001 基于STM32等单片机驱动HX711称重模块 串口与OLED0.96双显示

K_A16_001 基于STM32等单片机驱动HX711称重模块 串口与OLED0.96双显示一、资源说明二、基本参数参数引脚说明三、驱动说明对应程序:四、部分代码说明1、接线引脚定义1.1、STC89C52RCHX711称重模块1.2、STM32F103C8T6HX711称重模块五、基础知识学习与相关资料下载六、视频效果展…

项目实战典型案例17——环境混用来带的影响

环境混用来带的影响一&#xff1a;背景介绍背景出现的事故二&#xff1a;思路&方案环境混用的危害如何彻底避免环境混用的问题四&#xff1a;总结五&#xff1a;升华一&#xff1a;背景介绍 本篇博客是对对项目开发中出现的环境混用来带的影响进行的总结并进行的改进。目的…

你想知道的OSPF协议知识点都在这里了

1、OSPF协议概述 1)为什么需要动态路由协议&#xff1f; 静态路由是由工程师手动配置和维护的路由条目&#xff0c;命令行简单明确&#xff0c;适用于小型或稳定的网络。静态路由有以下问题&#xff1a;a)无法适应规模较大的网络&#xff1a;随着设备数量增加&#xff0c;配置量…

SpringBoot学习笔记(三)整合Logback日志框架

一、日志框架介绍1、常见日志框架目前我们常见的日志框架为Log4j、Log4j2、Logback这3种&#xff0c;并且现在很多的工具包里面都会自带日志框架&#xff0c;因此我们使用要格外小心日志框架的冲突。2、三种日志框架之间的关系最先有Log4j&#xff0c;然后因为Log4j有很大的性能…

uniapp系列-图文并茂手把手教你hbuilder进行uniapp云端打包 - 安心打包

什么是安心打包 提交App的模块配置信息到云端&#xff0c;在云端打包机生成原生代码包 为什么使用云打包 更安全&#xff1a;打包时不提交应用代码、证书等信息更快速&#xff1a;非首次打包时不用提交云端打包机排队等待&#xff0c;本地直接出包省流量&#xff1a;减少了打…

Linux开发环境配置--正点原子阿尔法开发板

Linux开发环境配置–正点原子阿尔法开发板 文章目录Linux开发环境配置--正点原子阿尔法开发板1.网络环境设置1.1添加网络适配器1.2虚拟网络编辑器设置1.3Ubuntu和Windows网络信息设置Ubuntu网络信息配置方式&#xff1a;1.系统设置->网络->选项2.配置网络文件2源码准备2.…

Vuex 状态管理

文章目录Vuex概述安装单向数据流Vuex核心概念StatemapState 辅助函数扩展运算符GettermapGetters 辅助函数Mutation提交载荷提交载荷对象对象风格提交使用常量替代mutation事件类型Action异步分发Module命名空间Vuex 概述 Vuex 是一个状态管理库&#xff0c;用于管理 Vue.js …

CRM系统是什么?为什么使用它?

CRM系统是什么&#xff1f;为什么使用它&#xff1f;这篇来简单说下&#xff0c;CRM系统是什么&#xff1f;能帮助我们做什么&#xff1f;有什么好处&#xff1f; 01 CRM系统是什么&#xff1f; 我总结了7种关于CRM的概念&#xff0c;任意一个解释得其实都没什么问题&#xff…

【数据结构】核心数据结构之二叉堆的原理及实现

1.大顶堆和小顶堆原理 什么是堆 堆&#xff08;Heap&#xff09;是计算机科学中一类特殊的数据结构&#xff0c;通常是一个可以被看作一颗完全二叉树的数组对象。 完全二叉树 只有最下面两层节点的度可以小于2&#xff0c;并且最下层的叶节点集中在靠左连续的边界 只允许最后…

2023FL Studio最新中文版电子音乐、混音和母带制作DAW

水果具有独特的底层逻辑&#xff0c;其开创了编曲“块”的思维。用FL Studio编曲的流程是在把一个样式编辑好&#xff0c;然后将编辑好的样式当做音频块&#xff0c;在播放列表中像“搭积木”一样任意编排&#xff0c;形成一首歌&#xff0c;这种模式非常利于电子音乐编曲。 2…

Apinto V0.12 发布:新增流量镜像与 Mock 插件,路由特性更丰富!

Hello~ 各位开发者朋友们好呀&#xff0c; Eolink 旗下开源网关 Apinto 本周又更新啦&#xff01;这次的更新我们给大家带来了 2个好用的插件&#xff0c;且目前已经支持静态资源路由了&#xff01;希望新的功能能让大家的开发工作更加高效 &#xff5e; 1、新增流量镜像插件 …

学习streamlit-1

Streamlit A faster way to build and share data apps streamlit在几分钟内就可以将数据脚本转换为可共享的web应用程序&#xff0c;并且是纯python编程&#xff0c;无需前端经验。 快速开始 streamlit非常容易上手&#xff0c;运行demo只需2行代码&#xff1a; pip install…

0306spring--复习

一&#xff0c;spring是什么 Spring是一个轻量级的控制反转&#xff08;IOC&#xff09;和面向切面编程&#xff08;AOP&#xff09;的容器框架 理念&#xff1a;使现有的技术更加容易使用&#xff0c;本身是一个大杂烩&#xff0c;整合了现有的技术框架 优点&#xff1…

Windows系统利用Qemu仿真ARM64平台

Windows系统利用Qemu仿真ARM64平台0 写在最前1 Windows安装Qemu1.1 下载Qemu1.2 安装Qemu1.3 添加环境变量1.4测试安装是否成功2. Qemu安装Ubuntu-Server-Arm-642.1 安装前的准备2.2 安装Ubuntu server arm 64位镜像3 Windows配置Qemu网络和传输文件3.1 参考内容3.2 Windows安装…

正版Scrivener 3 论文/小说写作工具神器软件

一款非常优秀的写作软件&#xff0c;提供了各种写作辅助功能&#xff0c;如标注多个文档、概述介绍、全屏幕编辑、快照等&#xff0c;能够轻松、便捷的辅助作者从作品构思、搜集资料、组织结构、增删修改到排版输出的整个写作流程。 作为一个专业的写作软件&#xff0c;Scriven…