• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: 其他
  • 标签: DAC8552  DAC8554  STM32  

资源简介

基于STM32的DAC8552的驱动程序,DAC8554和这个一样,已经调试了

资源截图

代码片段和文件信息


/**
  ******************************************************************************
  * @file    bsp_dac8552.c
  * @author  张超凡
  * @version V1.0
  * @date    
  * @brief   DAC8552驱动程序
*
  */
 /*******************************调试信息*************************************************
*  模拟了三个spi通信。一红有6个通道,编号从 0-5 。
*  为保证输出的精度,有两种办法:1、用最小二乘法拟合直线。2、用分段线性插值。
*  
*  
*  增加了延时
*
*
*
*******************************************************************************/




#include “stm32f4xx.h“
#include “bsp_dac8552.h“
#include “stm32f4xx_conf.h“
#include “delay.h“


static void DAC8552_0_SPI_Write( unsigned int code);
static void DAC8552_1_SPI_Write( unsigned int code);
static void DAC8552_2_SPI_Write( unsigned int code);
static void DAC8552_delay(void);
void DAC8552_Init()
{
unsigned char i = 0;
GPIO_InitTypeDef  GPIO_InitStructure;

  
DAC8552_RCC_GPIOClockCmd(); //使能端口引脚端口时钟



GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出  
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;


GPIO_InitStructure.GPIO_Pin = DAC8552_0_SYNC_Pin ;  // 端口配置
GPIO_Init(DAC8552_0_SYNC_Port &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = DAC8552_0_SCLK_Pin;
GPIO_Init(DAC8552_0_SCLK_Port &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = DAC8552_0_DIN_Pin;
GPIO_Init(DAC8552_0_DIN_Port &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = DAC8552_1_SYNC_Pin ;  // 端口配置
GPIO_Init(DAC8552_1_SYNC_Port &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = DAC8552_1_SCLK_Pin;
GPIO_Init(DAC8552_1_SCLK_Port &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = DAC8552_1_DIN_Pin;
GPIO_Init(DAC8552_1_DIN_Port &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = DAC8552_2_SYNC_Pin ;  // 端口配置
GPIO_Init(DAC8552_2_SYNC_Port &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = DAC8552_2_SCLK_Pin;
GPIO_Init(DAC8552_2_SCLK_Port &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = DAC8552_2_DIN_Pin;
GPIO_Init(DAC8552_2_DIN_Port &GPIO_InitStructure);

for(i = 0;i <5;i ++)
{
DAC8552_SetVoltage(i0);

}

}


static void DAC8552_delay(void)
{
int x = 10;
  while(--x);
}

void DAC8552_SetVoltage( unsigned char channelunsigned int code)  //通道一共6个(0-5),一个芯片有两个通道   data是一个24位的数据STM32中int型是32位的数据
{
  unsigned int data = 0;
unsigned char chip;
  if( code > 65535 | channel > 5)
return ;

chip =  channel >> 1;
(channel%2 == 0) ? (data = 0x100000 | code) : (data = 0x240000 | code)     ; //通道有 chip0 : 0 1  chip1 : 2 3 chip2 : 4 5 偶数通道0 奇数通道一
switch( chip)
{
case 0 :
{
DAC8552_0_SPI_Write(data);
break;
}
case 1 :
{
DAC8552_1_SPI_Write(data);
break;
}
case 2 :
{
DAC8552_2_SPI_Write(data);
break;
}
}

}


static void DAC8552_1_SPI_Write( unsigned int code)
{
char i=0;
  unsigned int data = code;
DAC8552_1_SYNC = 1;
DAC8

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-05-24 15:40  dac8552\
     文件        4436  2017-05-24 15:40  dac8552\bsp_dac8552.c
     文件        1694  2017-05-24 15:40  dac8552\bsp_dac8552.h

评论

共有 条评论