I2C阅读频率

发布于 2025-02-09 14:07:45 字数 3007 浏览 1 评论 0原文

我目前正在研究一个将FTDI MPSSE(FT232H)与I2C传感器一起使用的项目。

我确实设法连接并阅读了值,我想更快地阅读它们。

目前,我读到近10Hz,而且非常慢。我知道我可以更快地阅读它们,因为我曾经在其他I2C传感器上工作,并且可以阅读它们直到3KHz。

我不知道问题在哪里。

我尝试使用不同的“选项”确认,开始,停止位等,但找不到任何解决方案。

奇怪的是:如果我使用Arduino板,我可以更快地阅读它们(1KHz)。

但是出于目的,我使用了这个FTDI芯片。

代码在这里。

#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;
}

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2025-02-16 14:07:45

您正在配置i2c_channelconfig.clockrate i2c_clock_fast_mode(400kb/sec),但是您可以使用模式(3.4MB/sec)

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文