极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7907|回复: 2

求助 arduino 读取 AD5933 寄存器出错,一直为0x70

[复制链接]
发表于 2014-7-31 23:21:06 | 显示全部楼层 |阅读模式
最近用Arduino操作AD5933出现了问题,读取状态寄存器的时候 老是读取0x70,有没有知道是什么原因啊。

贴一下我的代码

// AD5933 control
//
#include <Wire.h>

void writeAD5933(byte add, byte data)
{
  Wire.beginTransmission(13);  // this chip address is 0001101  13
  Wire.write(add);      
  Wire.write(data);      
  Wire.endTransmission();      // stop transmitting
}


byte readAD5933(byte add)
{
  byte date = 0;
  Wire.beginTransmission(13);  // 00011011
  Wire.write(byte(0xB0));      // Address pointer
  Wire.write(add);             //
  Wire.endTransmission();      // stop transmitting
  Wire.requestFrom(13, 1,true);
  if(Wire.available())   
  {
    date = Wire.read();  // receive high byte (overwrites previous reading)
  }  
  return date;
}

void setup()
{
  Wire.begin();
  Serial.begin(9600);  
}

int temp = 0;
byte templow = 0;
byte temphigh = 1;
byte statusReg = 0;
float temper = 0.0;

void loop()
{
  // writer error.
  // step 1: write temperature test control code to register
  
  delay(1000);
  delay(1000);  
  writeAD9777(byte(0x80), byte(0x90));

   templow = 0x00;
   while(!(templow & 0x07))
   {
      templow = readAD5933(byte(0x8F));
      Serial.println(templow,BIN);   // print the reading
      delay(1000);
    }
    Serial.println(templow,BIN);   // print the reading
    Serial.println("success!");    //

  delay(1000);
}

读写寄存器的函数应该是没有问题的,因为我通过读写别的寄存器 ,如起始频率寄存器,频率论扫数寄存器等,先写入数据,再读取数据,发现能够读取之前写入的数据。
回复

使用道具 举报

发表于 2014-8-1 22:10:14 | 显示全部楼层
为何不按标准的wire格式写呢,变量比较混乱。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-2 11:31:03 | 显示全部楼层
topdog 发表于 2014-8-1 22:10
为何不按标准的wire格式写呢,变量比较混乱。


求指导 什么是标准的wire格式啊?
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-24 00:31 , Processed in 0.043377 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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