簡體   English   中英

I2C 讀取頻率

[英]I2C Reading frequency

我目前正在開發一個使用帶有 I2C 傳感器的 ftdi MPSSE (FT232H) 的項目。

我確實設法連接並讀取了值,我想更快地讀取它們。

目前我以接近 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;
}

謝謝。

您正在將I2C_ChannelConfig.ClockRate配置為I2C_CLOCK_FAST_MODE (400kb/sec),但您可以使用I2C_CLOCK_FAST_MODE_PLUS (1000kb/sec) 或I2C_CLOCK_HIGH_SPEED_MODE (3.4Mb/sec)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM