FTDI FT2232H - Problem reading two bytes from I2C device

Hi All,

I am using visual c++ to communicate with three ICs using I2C, from a PC via usb using a FT2232H.

The devices I am connected via I2C are 2x AD5252 and 1x AD7993. The AD7993 contains 16 bit registers which I am having trouble reading from. I have successfully written and read from the 8bit registers on all three devices, but always get incorrect results when reading the 16bit registers.

Below is a copy of the code I use for reading the 8bit registers in the AD7993 AtoD converter. The code is written in Microsoft Visual C++ 2008 Express Edition and based on code from the I2CTEST example code found at http://www.ftdichip.com/Support/SoftwareExamples/CodeExamples/VC++/I2CTEST.rar

I would appreciate it if anyone could point me to how to modify the code for reading two bytes?

//////////////////
///READ SECTION
///////////////////
//Purge USB receive buffer first before read operation
ftStatus = FT_GetQueueStatus(ftHandle, &dwNumInputBuffer);	 // Get the number of bytes in the device receive buffer
if ((ftStatus == FT_OK) && (dwNumInputBuffer > 0))
		FT_Read(ftHandle, &InputBuffer, dwNumInputBuffer, &dwNumBytesRead);  //Read out all the data from receive buffer
//////////////////////////////////////////////////////////
// Set I2C start condition
//////////////////////////////////////////////////////////
HighSpeedSetI2CStart();
bSucceed = SendByteAndCheckACK(0x58); // Address of AD5252 with LSB=0 for write command
bSucceed = SendByteAndCheckACK(0x01); // Register RDAC1 for W1
HighSpeedSetI2CStart();
bSucceed = SendByteAndCheckACK(0x59); // Address of AD5252 with LSB=1 for read command
//////////////////////////////////////////////////////////
// Read the data from I2C device
//////////////////////////////////////////////////////////
//dwNumBytesToSend = 0;			//Clear output buffer
OutputBuffer[dwNumBytesToSend++] = '\x80'; 	//Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = '\x00'; 	//Set SCL low, WP disabled by SK, GPIOL0 at bit ¡®0¡¯
OutputBuffer[dwNumBytesToSend++] = '\x11';	//Set SK, GPIOL0 pins as output with bit ¡¯1¡¯, DO and other pins as input with bit ¡®0¡¯
OutputBuffer[dwNumBytesToSend++] = MSB_FALLING_EDGE_CLOCK_BYTE_IN; 	//Command to clock data byte in on ¨Cve Clock Edge MSB first
OutputBuffer[dwNumBytesToSend++] = '\x00';
OutputBuffer[dwNumBytesToSend++] = '\x00';	//Data length of 0x0000 means 1 byte data to clock in
//OutputBuffer[dwNumBytesToSend++] = '\x87';	//Send answer back immediate command

OutputBuffer[dwNumBytesToSend++] = MSB_RISING_EDGE_CLOCK_BIT_IN; 	//Command to scan in acknowledge bit , -ve clock Edge MSB first
OutputBuffer[dwNumBytesToSend++] = '\x0';	//Length of 0 means to scan in 1 bit
OutputBuffer[dwNumBytesToSend++] = '\x87';	//Send answer back immediate command
ftStatus = FT_Write(ftHandle, OutputBuffer, dwNumBytesToSend, &dwNumBytesSent);		//Send off the commands
dwNumBytesToSend = 0;			//Clear output buffer
ftStatus = FT_Read(ftHandle, InputBuffer, 2, &dwNumBytesRead);//Read one byte from device receive buffer, may need try more times

ByteDataRead = InputBuffer[0];		//return the data read from EEPROM
	
OutputBuffer[dwNumBytesToSend++] = '\x80'; 	//Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = '\x02'; 	//Set SDA high, SCL low, WP disabled by SK at bit '0', DO, GPIOL0 at bit '1'
OutputBuffer[dwNumBytesToSend++] = '\x13';	//Set SK,DO,GPIOL0 pins as output with bit ¡¯1¡¯, other pins as input with bit ¡®0¡¯
HighSpeedSetI2CStop();
ftStatus = FT_Write(ftHandle, OutputBuffer, dwNumBytesToSend, &dwNumBytesSent); //Send off the commands
dwNumBytesToSend = 0;			//Clear output buffer

Jonathan

Hey Jono and welcome to the netmf forum.

Do you really mean you’re programming in Visual C# Express 2010, which is where netmf coding occurs, or are you really using C++ on a Windows machine to talk to the FTDI chip? Fundamentally, I hate to say it, but I suspect you aren’t likely to get too many people here who will know about this, but I can’t make a sensible suggestion about where you might get more assistance except maybe FTDI have a forum?

I would have to assume you do it here:

OutputBuffer[dwNumBytesToSend++] = '\x00'; //Data length of 0x0000 means 1 byte data to clock in

But I can’t vouch for that. I looked at the FTDI samples a few months ago and gave up. It was easier to build a USB to I2C interface using a PIC and coding it myself…

@ Brett, yeah, the FTDI samples are in C++, the C# samples are out dated and “not supported” and written as if the programmer was drunk. Maybe it’s just me, but it is NOT easy to follow…

But I suspect that this thread should have been in “Off Topic”…

The OP has posted this question on at least one other site. The OP has
no interest in MF, and is just posting on multiple sites to solicit an answer
without consideration of forum context.

The question has been answered on another site.