wangku001wei

ADI年度贺岁片——利用Arduino控制AD5933的初步尝试

wangku001wei 在 2014-1-14 建立的討論區
最後回覆由wudonghang於2017-3-26提供

AD5933 是ADI公司出品的 1 MSPS、12位阻抗转换器和网络分析仪,可用于电化学分析、生物电阻抗分析、阻抗频谱分析,复阻抗测量、生物医学和汽车传感器、材料性质分析等,使用IIC通信方式。

本想做一个完整的基于Arduino的AD5933阻抗测量系统,目前由于时间关系,先探索下其IIC通信方式,尝试实现控制AD5933进行温度采集并通过串口发送

软件代码主要包括以下个部分
1 发送温度采集命令
2 读取状态寄存器并判断温度采集是否完成
3 读取温度高位字节
4 读取温度低位字节
5 温度格式转换
6 串口发送温度数据

由于我的Arduino开发环境没有配置,不支持中文注释,所以采用了英文注释

代码如下,编译通过

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

char temphigh = 0;
char templow = 0;
char statusnow = 0;
float temperature = 0;
void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop()
{

  delay(500);

  // 1. begin measure temperature
  Wire.beginTransmission(13); // transmit to device #13 (0x0D) 
  Wire.write(byte(0x80));     // sends instruction byte
  Wire.write(byte(0x90));     // Measure temperature
  Wire.endTransmission();     // stop transmitting

  // 2. read status
  do
  {
    Wire.beginTransmission(13); // transmit to device #13 (0x0D)   // 0x0D                     
    Wire.write(byte(0xB0));     // sends instruction byte  -> read
    Wire.write(byte(0x8F));     // status register address
    Wire.endTransmission();     // stop transmitting
    Wire.requestFrom(13, 1, true);    // request 1 bytes from slave device #13
    while(Wire.available())    // slave may send less than requested
      statusnow = Wire.read(); // receive a byte as character
  }
  while((statusnow | byte(0xFE)) != byte(0xFF));

  // 3. read temperature high address
  Wire.beginTransmission(13); // transmit to device #13 (0x0D)   // 0x0D                          
  Wire.write(byte(0xB0));     // sends instruction byte  -> read
  Wire.write(byte(0x92));     // temperature register high address
  Wire.endTransmission();     // stop transmitting
  Wire.requestFrom(13, 1, true);    // request 1 bytes from slave device #13
  while(Wire.available())    // slave may send less than requested
  {
    temphigh = Wire.read(); // receive a byte as character
  }
  // 4. read temperature low address
  Wire.beginTransmission(13); // transmit to device #13 (0x0D)   // 0x0D
  Wire.write(byte(0xB0));     // sends instruction byte  -> read
  Wire.write(byte(0x93));     // temperature register low address 1
  Wire.endTransmission();     // stop transmitting
  Wire.requestFrom(13, 1, true);    // request 1 bytes from slave device #13
  while(Wire.available())    // slave may send less than requested
  {
    templow  = Wire.read(); // receive a byte as character
  }

  // 5. trans temperature;
  temperature = (temphigh<< 8) | templow;
  if(temphigh & 0x20 == 0x20)
    temperature = temperature - 16384;
  temperature = temperature /32 ;

  // 6. send temperature by uart
  Serial.print("The Temperature is: ");
  Serial.println(temperature,2);

  delay(500);
}

結果