#include "DAC7512.h"
static void SPI_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC7512_SPI_GPIO_APBxClock_FUN ( DAC7512_SPI_GPIO_CLK, ENABLE );
DAC7512_SPI_APBxClock_FUN ( DAC7512_SPI_CLK, ENABLE );
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);
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);
// DAC7512_SPI_CS_HIGH;
}
static void SPI_Mode_Config(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2 ;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge ;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low ;
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();
}
static 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 SPI_Write_Enable(uint16_t data)
{
//片选使能
DAC7512_SPI_CS_LOW;
SPI_DAC7512_Send_Byte(data);
//DAC7512_SPI_CS_HIGH ;
}
这样写不知道为什么没有输出,三个信号线都有信号啊
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
很急,大神可以帮忙看看吗
一周热门 更多>