打印
[STM32F1]

上电输出不确定电压

[复制链接]
714|24
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dengdc|  楼主 | 2019-1-23 13:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32 SPI驱动DAC8830 上电输出不确定电压
沙发
598330983| | 2019-1-23 13:41 | 只看该作者
那个单片机无关了,你没有弄好DAC芯片。

使用特权

评论回复
板凳
shimx| | 2019-1-23 13:42 | 只看该作者
楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因

使用特权

评论回复
地板
dengdc|  楼主 | 2019-1-23 13:45 | 只看该作者

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就会输出一个不确定的电压

使用特权

评论回复
5
jiaxw| | 2019-1-23 13:49 | 只看该作者
SPI配置应该没有问题吧

使用特权

评论回复
6
dengdc|  楼主 | 2019-1-23 13:53 | 只看该作者
嗯,因为上电后我在主函数用SPI1和DAC通信时,得到的模拟电压是正确的,只是上电时输出的不为0的电压问题一直困扰我。

使用特权

评论回复
7
spark周| | 2019-1-23 13:55 | 只看该作者
怀疑是由于PA4(CS信号)上电为低电平,DAC一直处在激活状态,可能从MOSI接口接收了信号造成了输出电压不为0

使用特权

评论回复
8
liliang9554| | 2019-1-23 14:00 | 只看该作者
这应该是上电复位的问题, 看 DAC8830 手册的描述:

POWER-ON RESET
Both devices have a power-on reset function to ensure the output is at a known state upon power-up. In the DAC8830 and DAC8831, at power-up, the DAC latch and Input Registers contain all 0s until new data are loaded from the input serial shift register. Therefore, after power-up, the output from pin V OUT of the DAC8830 is 0 V. The output from pin V OUT of the DAC8831 is 0 V in unipolar mode and – V REF in bipolar mode.
However, the serial register of the DAC8830 and DAC8831 is not cleared on power-up, so its contents are undefined. When loading data initially to the device, 16 bits or more should be loaded to prevent erroneous data appearing on the output. If more than 16 bits are loaded, the last 16 are kept; if less than 16 are loaded, bits will remain from the previous word. If the device must be interfaced with data shorter than 16 bits, the data should be padded with 0s at the LSBs.

使用特权

评论回复
9
dengdc|  楼主 | 2019-1-23 14:05 | 只看该作者
执行了这个函数之后,DAC就输出一个不确定的初始电压,很奇怪

使用特权

评论回复
10
午夜粪车| | 2019-1-23 14:07 | 只看该作者

时序介绍有一句话:The low-to-high transition of CS transfers the contents of the input shift register to the input register...In the DAC8830, the contents of the input register are transferred into the DAC latch immediately when the input
register is loaded, and the DAC output is updated at the same time.意思是说,CS的低到高变化,会把输入移位寄存器的值送到输入寄存器,而输入寄存器的更新会使DAC立即输出相应的电压。

使用特权

评论回复
11
dengdc|  楼主 | 2019-1-23 14:10 | 只看该作者

而POWER-ON RESET 这里有一句:However, the serial register of the DAC8830 and DAC8831 is not cleared on power-up, so its contents are undefined.姑且认为这里的serial register就是上述的输入移位寄存器。又联想到STM32上电后,PA4端口(CS)默认的是低电平,当我给他Set High时,DAC就会把输入移位寄存器里未知的内容送入输入寄存器,从而DAC输出一个未知的电压值。
  这样理解的话倒是说的通,但是有没有办法避免这个问题?

使用特权

评论回复
12
zhaoxqi| | 2019-1-23 14:14 | 只看该作者
是否有办法让STM上电默认输出高电平呀?

使用特权

评论回复
13
huangchui| | 2019-1-23 14:17 | 只看该作者

上电默认输出高电平, 最好加个上拉电阻来实现. 不过我关注的问题是:

However, the serial register of the DAC8830 and DAC8831 is not cleared on power-up, so its contents are undefined. When loading data initially to the device, 16 bits or more should be loaded to prevent erroneous data appearing on the output.

就是说, 上电的寄存器值不确定.

使用特权

评论回复
14
jiajs| | 2019-1-23 14:20 | 只看该作者
上电复位的问题???
怎么会是不确定电压?

使用特权

评论回复
15
heisexingqisi| | 2019-1-23 14:22 | 只看该作者
电路没有弄好吧

使用特权

评论回复
16
zhanghqi| | 2019-1-23 14:22 | 只看该作者
是不是缺少上拉电阻的原因?

使用特权

评论回复
17
huangchui| | 2019-1-23 14:26 | 只看该作者
上电默认输出高电平

使用特权

评论回复
18
dengdc|  楼主 | 2019-1-23 14:29 | 只看该作者
嗯,我再好好缕一缕吧,有了好消息及时通知大家,结贴喽

使用特权

评论回复
19
heisexingqisi| | 2019-1-23 15:07 | 只看该作者
直接IO驱动试试手册有时序的

使用特权

评论回复
20
磨砂| | 2019-2-17 13:38 | 只看该作者
硬件上是怎么接的啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

892

主题

13885

帖子

7

粉丝