SPI配置函数如下:
void SPI1_DAC8830_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
/* PA5--SCK */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/* PA7--MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/* PA4--CS for DAC8830 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/* Deselect the DAC8830 */
SPI_DAC8830_CS_High();
/* Configure the SPI Mode */
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; //Send 16bit
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB ;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; // fCLK/4
/* DAC8830 is sampling SDI data at the rising edge */
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //Sampling at odd edge
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //SCK low at the beginnig of CS HIGH to LOW
SPI_Init(SPI1,&SPI_InitStructure);
/* Enable the SPI1 */
SPI_Cmd(SPI1,ENABLE);
}
DAC8830上电会自动复位输出0V。但是执行了上述这个函数之后,每次上电DAC8830就会输出一个不确定的电压,但是SPI配置应该没有问题,因为上电后我在主函数用SPI1和DAC通信时,得到的模拟电压是正确的,只是上电时输出的不为0的电压问题一直困扰我。怀疑是由于PA4(CS信号)上电为低电平,DAC一直处在激活状态,可能从MOSI接口接收了信号造成了输出电压不为0,但是无从验证。求大神帮解答,万分感谢。
|