0

I am currently working on a project that use the ftdi MPSSE (FT232H) with an I2C sensor.

I did manage to connect and read the value, I want to read them faster.

Currently I read that at nearly 10hz, and it is very slow. I know fore sure that I can read them faster because I used to work on other I2C sensor and I could read them till 3KHz.

I don't know where the problem is.

I try to use different "option" acknowledge, start bit, stop bit etc, but I can't find any solution.

The weird thing is : if I use an Arduino board I can read them much much faster (1khz).

But for purpose I am block with this ftdi chip.

Code is here.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

/* OS specific libraries */

#include<windows.h>


#include "ftd2xx.h"
#include "libMPSSE_i2c.h"
#define I2C_DEVICE_BUFFER_SIZE          256
static uint8 buffer[I2C_DEVICE_BUFFER_SIZE] = { 0 };


int main(int argc, char* argv[])
{
    uint32 adresse = 0x54;
    uint8  data[7];
    uint32 datatoread = 7;
    uint32 datatoread2 = 7;
    uint8  data2[7];
    uint32 numberofbytesread = 0;
    int i = 0;

    Init_libMPSSE();

    FT_STATUS status;
    FT_DEVICE_LIST_INFO_NODE channelInfo;
    FT_HANDLE handle;
    uint32 channelCount = 0;
    uint32 datashort = 0;
    //buffer[datatoread];

    status = I2C_GetNumChannels(&channelCount);
    if (status != FT_OK)
        printf("Error while checking the number of mpsse channel");
    else if (channelCount < 1)
        printf("erro no MPSE channels are available");

    printf("there are %u channel available \n\n", channelCount);

    // Print out details of each mpsse channel 

    for (uint8 i = 0; i < channelCount; i++) {
        status = I2C_GetChannelInfo(i, &channelInfo);
        if (status != FT_OK)
            printf("Error while checking the number of mpsse channel");

        printf("Channel number : %d\n", i);
        printf("description : %s\n", channelInfo.Description);
        printf("Serial number : %s\n", channelInfo.SerialNumber);
    }
    //ask the user to select a channel
    uint32 channel = 0;
    printf("\nenter a channel to use : ");
    scanf_s("%d", &channel);

    // open the I2C channel 

    status = I2C_OpenChannel(channel, &handle);
    if (status != FT_OK)
        printf("error while oppening the mpsse channel");

    //init the channel

    ChannelConfig I2C_ChannelConfig;
    I2C_ChannelConfig.ClockRate = I2C_CLOCK_FAST_MODE;
    I2C_ChannelConfig.LatencyTimer = 1; // 1mS latency timer
    I2C_ChannelConfig.Options = 0;
    //uint32 mode = I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT;
    
    
    status = I2C_InitChannel(handle, &I2C_ChannelConfig);
    if (status != FT_OK)
        printf("error while oppening the mpsse channel");

       while (1) {
        //i++;
        
        status = I2C_DeviceRead(handle, adresse, datatoread, data, &numberofbytesread, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_NACK_LAST_BYTE);
        //printf("\n%d",i);
        datashort = (data[3] << 8) + data[2];
        printf("\nForce is  : %u DaN", datashort);
        //Sleep(1);
        //getchar();
    }

    I2C_CloseChannel(handle);
    Cleanup_libMPSSE();
    //getchar();
    return 0;
}

Thanks.

4
  • 1
    Use your oscilloscope to watch the I²C communication, and then edit your question and add your findings. Commented Jun 22, 2022 at 14:21
  • 1
    printf() is useful for debugging, but does add latency when wanting to do something in a fast loop. Once you have the O'scope connected, consider removing the printfs Commented Jun 22, 2022 at 14:24
  • I'm using a FTDI converter as well, the model is UM232H. But I am not being able to get to the I2C sensor which in this case is an accelerometer. How did you manage to get data? Commented May 4, 2023 at 8:25
  • in wich environment do you work ? For your information, they released new libraries but there is currently a problem with them. So you should use the 0.6 and not the 0.3 Commented May 5, 2023 at 9:02

1 Answer 1

1

You are configuring your I2C_ChannelConfig.ClockRate to I2C_CLOCK_FAST_MODE (400kb/sec), but you can use I2C_CLOCK_FAST_MODE_PLUS (1000kb/sec) or I2C_CLOCK_HIGH_SPEED_MODE (3.4Mb/sec).

Sign up to request clarification or add additional context in comments.

3 Comments

Hi thank for you answer l already try it but it does not change the speed. I think the problem come from the reading part. Because when I change the argument option, it does change the result of the speed but for example when I set the option with just a START bit the result as return is 65535. It's pretty weird. I2C_DeviceRead(FT_HANDLE handle, uint32 deviceAddress, uint32 sizeToTransfer, uint8 *buffer, uint32 *sizeTransferred, uint32 options). I guess l'll have to check that with a scope
Maybe try adding I2C_TRANSFER_OPTIONS_FAST_TRANSFER to your options and see if it helps (I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_NACK_LAST_BYTE | I2C_TRANSFER_OPTIONS_FAST_TRANSFER).
it says "if I2C_TRANSFER_OPTION_FAST_TRANSFER is set then setting this bit would mean that the address field should be ignored. The address is either a part of the data or this is a special I2C frame that doesn't require an address*/" I do need my adress. I sent a message to the technical support of ftdi. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.