已回答假定已回答

AD9837 写控制字

ziziran 在 2016-5-20 詢問的問題
最後回覆由hpkamen於2016-6-5提供

使用STM32控制AD9837 ,使用SPI发送控制字,SPI的时序和发出的数据都看过,没有问题 。但是AD9837没响应。

STM32的代码如下:

 

void AD9837_SPI_Init( void)

{

    GPIO_InitTypeDef GPIO_InitStructure;

  SPI_InitTypeDef SPI2_InitStruct;

  

  

//SPI 端口时钟初始化  

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);  

//SPI 片选使能初始化   

     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);

 

    /* Confugure SCK and MOSI pins as Input Floating */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

  

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15|GPIO_Pin_14;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP ;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

  

    //FSYNC 初始化

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

    GPIO_Init(GPIOE, &GPIO_InitStructure);

  

    ADI_CS_HIGH_1;

    ADI_CS_HIGH_2;

  

//SPI2 时钟使能

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

  

    SPI_I2S_DeInit(SPI2);

  

    SPI2_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

    SPI2_InitStruct.SPI_Mode = SPI_Mode_Master; //主模式

    SPI2_InitStruct.SPI_DataSize = SPI_DataSize_16b;

    SPI2_InitStruct.SPI_CPOL = SPI_CPOL_High;

    SPI2_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;

    SPI2_InitStruct.SPI_NSS = SPI_NSS_Soft ;

    SPI2_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; //速录500K,1M也试过

    SPI2_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;

    SPI2_InitStruct.SPI_CRCPolynomial = 7;

  

    //初始化

    SPI_Init(SPI2, &SPI2_InitStruct);

    //使能

    SPI_Cmd(SPI2,ENABLE);

  

    AD9837_SetRegisterValue(AD9837_REG_CMD | AD9837_RESET);

}

/***************************************************************************//**

* @brief Writes data to SPI.

*

* @param data - Write data buffer:

*               - first byte is the chip select number;

*               - from the second byte onwards are located data bytes to write.

* @param bytesNumber - Number of bytes to write.

*

* @return Number of written bytes.

*******************************************************************************/

void SPI_Write(uint16 data)

{

    while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);

      

    SPI_I2S_SendData(SPI2, data);

}

 

 

AD9837.h和AD9837.C是使用ADI官网的例程文件。

附件

結果