Post Go back to editing

AD7998 can only read channel 1

Category: Hardware
Product Number: AD7998BRUZ-0

I am trying to Access the AD7998 using the FT260 USB to I2C module. I am trying to access one channel at a time. I am able to read channel 1 just fine, but can't read the rest of the channels. 

I tried using Mode 2 and sending repeated starts, but kept getting channel 1 on every Chanel. So I switched to trying each channel one by one. 

My SPI port first sends three bytes after the device address 0x21  

I send 0x02,0x00,0x10 as seen below

WriteByteBuf[0] = 0x02; //Register pointer to Configuration Register
WriteByteBuf[1] = 0x00; // Config Reg High byte--If 1 Convert CH8,C7,CH6,CH5
WriteByteBuf[2] = 0x10; // Config Reg Low byte--Convert CH4,CH3,CH2,CH1, Filer on

numBytesToWrite = 3;
Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

I then send one byte 0x80 setting the pointer to the result register for channel 1

WriteByteBuf[0] = 0x80; //Register pointer to Conversion Result register, T

numBytesToWrite = 1;
Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

I then read the two bytes and I get good results for Channel 1

numBytesToRead = 2;
Status = FT260_I2CMaster_Read(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToRead, ref readLength, 5000);

I then try the same for channel two

WriteByteBuf[0] = 0x02; //Register pointer to Configuration Register
WriteByteBuf[1] = 0x00; // Config Reg High byte--Convert CH8,C7,CH6,CH5
WriteByteBuf[2] = 0x20; // Config Reg Low byte--Convert CH4,CH3,CH2,CH1, Filer on

numBytesToWrite = 3;
Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

WriteByteBuf[0] = 0x90; //Register pointer to Conversion Result register, Turn on Mode 2 for all channels

numBytesToWrite = 1;
Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

numBytesToRead = 2;
Status = FT260_I2CMaster_Read(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToRead, ref readLength, 5000);

I get bad results 0x1000 or 4096 decimal as a result

Then read Cannel 3 

WriteByteBuf[0] = 0x02; //Register pointer to Configuration Register
WriteByteBuf[1] = 0x00; // Config Reg High byte--If 1 > Convert DC,DC,DC,DC,CH8,C7,CH6,CH5
WriteByteBuf[2] = 0x40; // Config Reg Low byte--If 1 > Convert CH4,CH3,CH2,CH1, Filer on, Alert, Busy/Alert, A/B Polarity

numBytesToWrite = 3;
Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

WriteByteBuf[0] = 0xA0; //Register pointer to Conversion Result register, Only convert one channel at a time.

numBytesToWrite = 1;
Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

numBytesToRead = 2;
Status = FT260_I2CMaster_Read(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToRead, ref readLength, 5000);

I get 0x2000 or 8192 decimal for Channel 3

And so on for the the other channels.

Is there any other registers needed I need to write to or commands to make the other channels work properly. 

My I2C signals looks good but it seems the result register is not correct or the ADC is not converting properly 

  • I tried the sequential read again with a repeated start set on the FT260 for the 0x70 write and again for the 16 byte read. I then send a stop command. Channel 1 is fine, but the other 7 channels are garbage. 

    I add some red arrows to some SDA bits I am not sure what that is. Its at the end of each byte. Maybe part of the ACK. 

    Starting from the top with channel 1 down to channel 8 below is what I am getting. several channels are grounded along with channel 1. 

    Would be nice to get this resolved. I have tried everything I can think of for the past two days. 

  • Stupid me! I did not mask out the top bits which are the Channel ID bits. 

    Rooky Mistake.Confounded

    Plus I did not see that the voltage dividers for each channel are different on the schematic. Need better glasses. Slight smile

    All seems to be working now with the repeat start on the FT260

    I included my C# working code in case anyone else needs to use the FT260 USB to I2C with the AD7998

    I need to play around with the highlighted areas to make sure if I need the extra stop command. The AD7998 can lock up the bus if it does not receive a stop.

    private void button6_Click(object sender, EventArgs e)
    {

    byte[] Reading = new byte[100];

    // ################################# AD7998 Setup and Read ADC Voltages#########################################

    byte[] VoltageAddressReg = new byte[10];
    byte[] CurrentAddressReg = new byte[10];
    byte[] WriteByteBuf = new byte[10];
    UInt32 numBytesToWrite = 0;
    UInt32 numBytesToRead = 0;
    UInt32 readLength = 0;
    UInt32 writeLength = 0;

    int size = Marshal.SizeOf(VoltageAddressReg[0]) * VoltageAddressReg.Length;
    IntPtr pnt = Marshal.AllocHGlobal(size);

    WriteByteBuf[0] = 0x02; //Register pointer to Configuration Register
    WriteByteBuf[1] = 0x0F; // Config Reg High byte--Convert CH8,C7,CH6,CH5
    WriteByteBuf[2] = 0xF8; // Config Reg Low byte--Convert CH4,CH3,CH2,CH1, Filer on

    numBytesToWrite = 3;
    Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
    Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START_AND_STOP, pnt, numBytesToWrite, ref writeLength);

    if ((Status != FT260_STATUS.FT260_OK) || (writeLength != numBytesToWrite))
    {
    SetControls_Error("Error", "Please check hardware and re-start application (AD7998W1)");
    return;
    }

    WriteByteBuf[0] = 0x70; //Register pointer to Conversion Result register, Turn on Mode 2 for all channels

    numBytesToWrite = 1;
    Marshal.Copy(WriteByteBuf, 0, pnt, WriteByteBuf.Length);
    Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_REPEATED_START, pnt, numBytesToWrite, ref writeLength);

    if ((Status != FT260_STATUS.FT260_OK) || (writeLength != numBytesToWrite))
    {
    SetControls_Error("Error", "Please check hardware and re-start application (AD7998W2)");
    return;
    }


    numBytesToRead = 16;
    Status = FT260_I2CMaster_Read(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_START, pnt, numBytesToRead, ref readLength, 5000);

    numBytesToWrite = 1;
    Status = FT260_I2CMaster_Write(ft260handle, 0x21, FT260_I2C_FLAG.FT260_I2C_STOP, pnt, numBytesToWrite, ref writeLength);

    if (Status == FT260_STATUS.FT260_OTHER_ERROR)
    {
    SetControls_Error("Error", "Please check hardware and re-start application (AD7998R1)");
    return;
    }

    if (Status == FT260_STATUS.FT260_I2C_READ_FAIL)
    {
    SetControls_Error_AllowReInit("Stopped", "Capture stopped: Click Initialise and the Start to begin again (AD7998R2)");
    return;
    }

    if ((Status != FT260_STATUS.FT260_OK) || (readLength != numBytesToRead))
    {
    SetControls_Error("Error", "Please check hardware and re-start application (AD7998R3)");
    return;
    }

    Marshal.Copy(pnt, Reading, 0, (int)numBytesToRead);
    ushort CH1 = (ushort)(((Reading[0] & 0x0F) * 256) + Reading[1]);
    ushort CH2 = (ushort)(((Reading[2] & 0x0F) * 256) + Reading[3]);
    ushort CH3 = (ushort)(((Reading[4] & 0x0F) * 256) + Reading[5]);
    ushort CH4 = (ushort)(((Reading[6] & 0x0F) * 256) + Reading[7]);
    ushort CH5 = (ushort)(((Reading[8] & 0x0F) * 256) + Reading[9]);
    ushort CH6 = (ushort)(((Reading[10] & 0x0F) * 256) + Reading[11]);
    ushort CH7 = (ushort)(((Reading[12] & 0x0F) * 256) + Reading[13]);
    ushort CH8 = (ushort)(((Reading[14] & 0x0F) * 256) + Reading[15]);


    labelCH1.Text = CH1.ToString();
    labelCH2.Text = CH2.ToString();
    labelCH3.Text = CH3.ToString();
    labelCH4.Text = CH4.ToString();
    labelCH5.Text = CH5.ToString();
    labelCH6.Text = CH6.ToString();
    labelCH7.Text = CH7.ToString();
    labelCH8.Text = CH8.ToString();
    }

  • Hi  ,

    Glad you have resolved your issue. Feel free to post another thread if you need further assistance. I will be closing this thread now.

    Regards,

    JC