因为以前没有用过DAC108S085这个芯片,这样配置完以后,在DA的输出端检测 不到电压,各位有用过这个芯片的没有,帮忙 看一下!谢谢!( 附上DA手册)
#include "spi.h"
void SPI_DAC_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //SPI1_SCK
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //SPI1_MOSI
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //SPI1_NSS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
SPI_DAC_CS_HIGH();//拉高PA4脚
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // 两线全双工模式
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //时钟下降沿采样
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/* Enable SPI1 */
SPI_Cmd(SPI1, ENABLE);
}
void SPI_DAC_SendByte(u16 byte)
{
u16 i =0;
SPI_DAC_CS_LOW();
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); //发送缓存空时向下执行
/* Send byte through the SPI1 peripheral */
SPI_I2S_SendData(SPI1, byte);
for(i = 500; i>0; i--);
SPI_DAC_CS_HIGH();
}
#include "stm32f10x.h"
#include "spi.h"
#define DAC_A_FULL 0x0FFC
#define DAC_B_three_quarters 0x1C00
#define DAC_C_half 0x2800
#define DAC_D_one_quarter 0x3400
#define DAC_E_FULL 0x4FFC
#define DAC_F_half 0x5800
#define DAC_UPDATE 0xA03F //更新6个通道的电压值
int main(void)
{
SPI_DAC_Init();
SPI_DAC_SendByte(DAC_A_FULL);
SPI_DAC_SendByte(DAC_B_three_quarters);
SPI_DAC_SendByte(DAC_C_half);
SPI_DAC_SendByte(DAC_D_one_quarter);
SPI_DAC_SendByte(DAC_E_FULL);
SPI_DAC_SendByte(DAC_F_half);
SPI_DAC_SendByte(DAC_UPDATE);
while(1) ;
}
|