#include "DAC7512.h"
sta
tic void SPI_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC7512_SPI_GPIO_APBxClock_FUN (DAC7512_SPI_GPIO_CLK,ENABLE);
GPIO_InitStructure.GPIO_Pin = DAC7512_SPI_CS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(DAC7512_SPI_CS_PORT,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = DAC7512_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(DAC7512_SPI_SCK_PORT,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = DAC7512_SPI_MOSI_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(DAC7512_SPI_MOSI_PORT,&GPIO_InitStructure);
DAC7512_SPI_CS_HIGH;
}
static void SPI_Mode_Config(void)
{
SPI_InitTypeDef SPI_InitStructure;
DAC7512_SPI_APBxClock_FUN(DAC7512_SPI_CLK,ENABLE);
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge ;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High ;
SPI_InitStructure.SPI_CRCPolynomial = 0;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_Init(DAC7512_SPIx,&SPI_InitStructure);
SPI_Cmd(DAC7512_SPIx,ENABLE);
}
void SPI_DAC7512_Init(void)
{
SPI_GPIO_Config();
SPI_Mode_Config();
}
void SPI_DAC7512_Send_Byte(uint16_t data)
{
while(SPI_I2S_GetFlagStatus(DAC7512_SPIx,SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(DAC7512_SPIx,data);
}
void Delay(uint8_t s)
{
uint8_t i = 0;
for(i=0;i
{
__NOP();
}
}
#include "
STM32f10x.h"
#include "DAC7512.h"
uint16_t data1 = 0x00ff;
int main(void)
{
SPI_DAC7512_Init();
while(1)
{
DAC7512_SPI_CS_LOW;
SPI_DAC7512_Send_Byte(data1);
Delay(60);
DAC7512_SPI_CS_HIGH;
}
}
这是程序,时序用示波器测试是正常的,可芯片就是没有输出,求大神指导啊