#include "DAC7512.h"
static 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<s;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;
}
}
求大神帮忙看看这个程序,用示波器测试时序都没问题啊,就是没有输出 |