已回答假定已回答

AD5426 DAC SPI通讯问题

朱二卫 在 2017-5-5 詢問的問題
最後回覆由EmmaChen於2017-5-10提供

AD5426 DAC芯片通讯问题。

REF_4V = 4.096V

上电后,Vzero=-4.09V

无法通过SPI通讯来控制DAC输出 Vzero一直为-4.09V,之前偶尔可以控制Vzero用 DAC复位至0V的指令。

 

STM32中程序:

void SPI2ADChipConfig(void)

{

  GPIO_InitTypeDef   GPIO_InitStructure;

  SPI_InitTypeDef    SPI_InitStructure;

 

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);  //SPI2时钟使能

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //GPIOB和AFIO时钟使能

  /* Configure SPI2 pins: NSS */

  GPIO_InitStructure.GPIO_Pin = SPI2_NSS_PB12;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

 

  /* Configure SPI2 pins: SCK, MISO and MOSI */

  GPIO_InitStructure.GPIO_Pin = SPI2_CLK_PB13 | SPI2_MISO_PB14 | SPI2_MOSI_PB15;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

    

  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //双向全双工

  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;         //主模式

  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;             //发送数据帧

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;             //空闲时时钟处于高电平态  SPI_CPOL_High   SPI_CPOL_Low

  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;             //在第 个时钟沿开始传

  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;             //NSS由软件管理  SPI_NSS_Soft SPI_NSS_Hard

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;// SPI_BaudRatePrescaler_8; // 波特率....和ADC采样频率相关

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;                 //发送数据从MSB位开始

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(SPI2, &SPI_InitStructure);

 

  SPI_SSOutputCmd(SPI2, DISABLE);

  SPI_SSOutputCmd(SPI2, ENABLE);

  /* Enable SPIy */

  SPI_Cmd(SPI2, DISABLE);

  SPI_Cmd(SPI2, ENABLE);

 

//-----
SendCmdtmp = 0x1100;  //C3~C0:0001 加载并更新 DB7~DB0:1000 0000 模拟输出0V
/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx data */
SPI_I2S_SendData(SPI2, SendCmdtmp);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2); //执行到次,RecvDataTmp = 0x0000,Vzero=-4.09V
/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx dummy data */
SPI_I2S_SendData(SPI2, 0);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2);  //执行到次,RecvDataTmp = 0x0880,Vzero=-4.09V
//-----

  SendCmdtmp = 0x2000;  //C3~C0:0010 启动回读 DB7~DB0:0000 0000 数据位应该没用

/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx data */
SPI_I2S_SendData(SPI2, SendCmdtmp);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2); //执行到次,RecvDataTmp = 0x0000,Vzero=-4.09V
/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx dummy data */
SPI_I2S_SendData(SPI2, 0);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2);  //执行到次,RecvDataTmp = 0x1000,Vzero=-4.09V
//-----

  SendCmdtmp = 0xB100;  //C3~C0:1011 复位DAC输出至零电平 DB7~DB0:1000 0000 数据位应该没用

/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx data */
SPI_I2S_SendData(SPI2, SendCmdtmp);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2); //执行到次,RecvDataTmp = 0x0000,Vzero=-4.09V
/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx dummy data */
SPI_I2S_SendData(SPI2, 0);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2);  //执行到次,RecvDataTmp = 0x5880,Vzero=-4.09V
//-----

  SendCmdtmp = 0x2000;  //C3~C0:0010 启动回读 DB7~DB0:0000 0000 数据位应该没用

/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx data */
SPI_I2S_SendData(SPI2, SendCmdtmp);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2);  //执行到次,RecvDataTmp = 0x0000,Vzero=-4.09V
/* Wait for SPIy Tx buffer empty */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx dummy data */
SPI_I2S_SendData(SPI2, 0);
/* Wait for SPIz data reception */
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
/* Read SPIz received data */
RecvDataTmp = SPI_I2S_ReceiveData(SPI2); //执行到次,RecvDataTmp = 0x1000,Vzero=-4.09V

}

}

 

--------------------

问题分析:

-之前也是这样发了好多条指令,有的就可以操作DAC输出0V。之后修改了指令顺序就又不行了,半天也没恢复到之前的。

-看样子回读数据 是0x1000,对应C3~C0是 0001 更新,DB7~DB0:0000 0000 输出是-Vref,感觉SPI通讯是对的,但是为什么控制不了 输出呢? 是R30和R36不能焊接0欧姆呢? 还是C83 1pF电容必须焊接呢? 还是SPI配置错误?还是菊花链模式不能使用(也禁止过菊花链模式,一样 不能确定是否写入了数据)?

已经在网上买了SPI转USB调试工具。

好无助啊,感觉可能是自己水平不行,用ADI的芯片 只有linux的驱动程序,没有STM32的驱动程序,弄起来好累啊,调试了1个礼拜也搞不清楚原因。

結果