資源簡介
基于STM32的DAC7562模塊驅動代碼,使用軟件spi協議通信,可實現控制電壓輸出

代碼片段和文件信息
#include?“stm32f10x.h“
#include?“bsp_spi.h“
#include?“bsp_SysTick.h“
?/******************************************************************************
??*?@file????bsp_spi.c
??*?@author??Tanch
??*?@version?V1.0.0
??*?@date????03/15/2019
??*?@brief???software?spi
??******************************************************************************/
??
/******************************************************************************
??*?@name:??SPI_DelayUS
??*?@param:?delay_time:0~65535?delay?time
??*?@note:??SPI_DelayUS
??*?@retval:none
??******************************************************************************/
void?SPI_DelayUS(uint16_t?delay_time)
{
unsigned?long?j;
while(delay_time--)
{
j=12;
while(j--);
}
}
/******************************************************************************
??*?@name:??SPI_DelayMS
??*?@param:?delay_time:0~65535?delay?time
??*?@note:??SPI_DelayMS
??*?@retval:none
??******************************************************************************/
void?SPI_DelayMS(uint16_t?delay_time)
{
while(delay_time--)
SPI_DelayUS(1030);
}
/******************************************************************************
??*?@name:??IIC_GPIO_Init
??*?@param:?none
??*?@note:??IIC_GPIO_Init
??*?@retval:none
??******************************************************************************/
void?SPI_GPIO_Config(void)
{
GPIO_InitTypeDef?GPIO_InitStructure;
????RCC_APB2PeriphClockCmd(SPI_ADS_CLK_CLK|SPI_ADS_MOSI_CLK?ENABLE);
RCC_APB2PeriphClockCmd(SPI_ADS_CS1_CLK|SPI_ADS_CS2_CLK|SPI_ADS_CS3_CLK|SPI_ADS_CS4_CLK?ENABLE);
//?CLK
????GPIO_InitStructure.GPIO_Pin?=?SPI_ADS_CLK_PIN;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
GPIO_Init(SPI_ADS_CLK_PORT?&GPIO_InitStructure);
//?MOSI
????GPIO_InitStructure.GPIO_Pin?=??SPI_ADS_MOSI_PIN;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
GPIO_Init(SPI_ADS_MOSI_PORT?&GPIO_InitStructure);
????//?CS1
????GPIO_InitStructure.GPIO_Pin?=?SPI_ADS_CS1_PIN;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
GPIO_Init(SPI_ADS_CS1_PORT?&GPIO_InitStructure);
????//?CS2
????GPIO_InitStructure.GPIO_Pin?=?SPI_ADS_CS2_PIN;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
GPIO_Init(SPI_ADS_CS2_PORT?&GPIO_InitStructure);
????//?CS3
????GPIO_InitStructure.GPIO_Pin?=?SPI_ADS_CS3_PIN;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
GPIO_Init(SPI_ADS_CS3_PORT?&GPIO_InitStructure);
????//?CS4
????GPIO_InitStructure.GPIO_Pin?=?SPI_ADS_CS4_PIN;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
GPIO_Init(SPI_ADS_CS4_PORT?&GPIO_InitStructure);
SPI_ADS_CS1(1);
SPI_ADS_CS2(1);
SPI_ADS_CS3(1);
SPI_ADS_CS4(1);?
}
/******************************************************************************
??*?@name:??SPI_ADS_SendByte
??*?@param:?byte:?send?data
??*?@note:??SPI_ADS_SendByte
??*?@retval:none
??********************************************************
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????3825??2019-03-15?12:18??dac7562驅動代碼\bsp_spi.c
?????文件????????1603??2019-03-15?12:12??dac7562驅動代碼\bsp_spi.h
?????文件????????2144??2019-03-15?12:22??dac7562驅動代碼\dac7562.c
?????文件????????1185??2019-03-15?12:10??dac7562驅動代碼\dac7562.h
?????目錄???????????0??2019-03-15?12:21??dac7562驅動代碼\
- 上一篇:銀行管理系統詳細設計文檔
- 下一篇:基于STM32F103的24m02芯片驅動代碼
評論
共有 條評論