1
Breakout boards / Re: FTDI FT2232H - Problem reading two bytes from I2C device
When I tried this I got:
MSB (read first) = 0x27 (sensible value)
LSB (read second) = 0xFF - always the same regardless of the value in the register.
Open Source Hardware
This section allows you to view all Show Posts made by this member. Note that you can only see Show Posts made in areas you currently have access to.
//////////////////
///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