Reputation: 13
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.
Upvotes: 0
Views: 514
Reputation: 552
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).
Upvotes: 1