野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 23873|回复: 1

AD7888读数一直为0

[复制链接]
发表于 2021-8-7 11:00:59 | 显示全部楼层 |阅读模式
10火花
有没有大佬用STM32驱动过AD7888,读数一直为0
unsigned int ReadFromAD7888ViaSPI(unsigned char RegValue)
{
        unsigned int ReceiveData = 0;
        unsigned char ControlValue = 0;
        unsigned int i = 0;
        unsigned int iTemp =0;
        ControlValue = RegValue;

        //Write Control register and Read result data

     GPIO_ResetBits(CS_GPIO_PORT, CS_GPIO_PIN);    //CS=0
     GPIO_ResetBits(SCLK_GPIO_PORT, SCLK_GPIO_PIN);        //SCLK=0

        for(i=0; i<16; i++)
        {
                ReceiveData <<= 1;        //Rotate data

                //write register code
                if(i < 8)
                {
                        if(0x80 == (ControlValue & 0x80)) //1000 0000   
                        {
                               
                                 GPIO_SetBits(DIN_GPIO_PORT, DIN_GPIO_PIN);// DIN=1
                        }
                        else
                        {
                                 GPIO_ResetBits(DIN_GPIO_PORT, DIN_GPIO_PIN);//DIN=0
                        }
                        ControlValue <<= 1;        //Rotate data
                }
                  Delay(1);       
                 GPIO_SetBits(SCLK_GPIO_PORT, SCLK_GPIO_PIN);           //SCLK=1
                //read data code
                iTemp = GPIO_ReadInputDataBit(DOUT_GPIO_PORT, DOUT_GPIO_PIN);                                                                                        //Read SDI of AD7888
                        if(0x00000020 == (iTemp & 0x00000020))                           //DOUT=1
                        {
                                ReceiveData |= 1;       
                        }
                        Delay(1);
                        GPIO_ResetBits(SCLK_GPIO_PORT, SCLK_GPIO_PIN);           //SCLK=0

        }
         GPIO_SetBits(CS_GPIO_PORT, CS_GPIO_PIN);        //CS=1
        return ReceiveData;
}

回复

使用道具 举报

发表于 2021-8-7 13:53:52 | 显示全部楼层
建议先用示波器或者逻辑分析仪看一下模拟的时序对不对。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-6-2 13:41 , Processed in 0.036749 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表