I2C通信问题Teensy LC到C ++中的Pmodl A

问题描述

我正在尝试使用标题中提到的两块板来构建电化学阻抗谱电路,并且我要脱离别人的代码。问题在于,上载到Teensy LC的代码未通过初始化。我不太熟悉编码,因此我很难弄清楚下一步如何进行故障排除。如果有人可以让我知道可能是什么问题或下一步应该去哪里看,我将不胜感激。谢谢。

这是代码在while循环中卡住的地方。

    // Perform initial configuration. Fail if any one of these fail.
  if (!(AD5933::reset() &&
    AD5933::setRange(1) && 
    AD5933::setInternalClock(true) &&
    AD5933::setStartFrequency(START_FREQ) &&
    AD5933::setIncrementFrequency(incrementFrequency) &&
    AD5933::setNumberIncrements(NUM_INCR) &&
    AD5933::setPGAGain(PGA_GAIN_X5)))
  
  {
    Serial.println("Initialization Failed!");
    while (true);

这是.cpp文件中被卡住的函数

 * Reset the AD5933. This interrupts a sweep if one is running,but the start
 * frequency,number of increments,and frequency increment register contents
 * are not overwritten,but an initialize start frequency command is required
 * to restart a frequency sweep.
 *
 * @return Success or failure
 */
bool AD5933::reset() {
    // Get the current value of the control register
    byte val;
    if (!getByte(CTRL_REG2,&val))
    
        return false;

    // Set bit D4 for restart
    val |= CTRL_RESET;

    // Send byte back
    return sendByte(CTRL_REG2,val);
}

这是函数上方卡住的地方。

它将“ Made it to#1”返回到序列号

 * Request to read a byte from the AD5933.
 *
 * @param address Address of register requesting data from
 * @param value Pointer to a byte where the return value should be stored,or
 *        where the error code will be stored if fail.
 * @return Success or failure
 */
int AD5933::getByte(byte address,byte *value) {
    // Request to read a byte using the address pointer register
    Wire.beginTransmission(AD5933_ADDR);
    Wire.write(ADDR_PTR);
    Wire.write(address);

    // Ensure transmission worked
    if (byte res = Wire.endTransmission() != I2C_RESULT_SUCCESS) {
        *value = res;
        Serial.println("Made it to #1");
        return false;
    }

    // Read the byte from the written address
    Wire.requestFrom(AD5933_ADDR,1);
    if (Wire.available()) {
        *value = Wire.read();
        Serial.println("Made it to #2");
        return true;
    } else {
        *value = 0;
        return false;
    }
}

显示在Arduino IDE的监视器中,但不是错误

C:\Users\macsa\Documents\Arduino\libraries\AD5933\AD5933.cpp: In static member function 'static bool AD5933::sendByte(byte,byte)':
C:\Users\macsa\Documents\Arduino\libraries\AD5933\AD5933.cpp:68:14: warning: unused variable 'res' [-Wunused-variable]
     if (byte res = Wire.endTransmission() != I2C_RESULT_SUCCESS) {
              ^

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)