参考官方文档:AN_135_MPSSE_Basics.pdf, AN_113_FTDI_Hi_Speed_USB_To_I2C_Example.pdf
有疑问的部分,色标已经标出。具体的执行时序流程,参考上一篇。
// Set initial states of the MPSSE interface
// - low byte, both pin directions and output values
// Pin name Signal Direction Config Initial State Config
// ADBUS0 TCK/SK output 1 high 1 -------------------->SCL(BIT0)
// ADBUS1 TDI/DO output 1 low 1 ---------------------->output SDA(BIT1)
// ADBUS2 TDO/DI input 0 0 ----------------------->input SDA
// ADBUS3 TMS/CS output 0 high 0
// ADBUS4 GPIOL0 output 1 low 0
// ADBUS5 GPIOL1 output 0 low 0
// ADBUS6 GPIOL2 output 0 high 0
// ADBUS7 GPIOL3 output 0 high 0
//---------------------I2C--------------------------------------------------------------------------------------------------
void FT2232I2cByteWrOneTime(unsigned char DeviceAddr,unsigned char RegAddr,unsigned char RegVal)
{
DWORD dwCount;
FT_STATUS ftStatus = FT_OK;
//-------------I2cStart-------------------------
for(dwCount=0; dwCount < 4; dwCount++) // Repeat commands to ensure the minimum period of the stop setup time ie 600ns is achieved
{
Set initial states of the MPSSE interface
OutputBuffer[dwNumBytesToSend++] = 0x80; Configure data bits low-byte of MPSSE port, Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = 0x03; Initial state config above, Set SDA, SCL high, WP disabled by SK, DO at bit „1‟, GPIOL0 at bit „0‟
OutputBuffer[dwNumBytesToSend++] = 0x13; Direction config above, Set SK,DO,GPIOL0 pins as output with bit „1‟, other pins as input with bit „0‟
}
for(dwCount=0; dwCount < 20; dwCount++)
{
OutputBuffer[dwNumBytesToSend++] = 0x80; //Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = 0x01; //Set SDA low, SCL high, WP disabled by SK at bit 1, DO, GPIOL0 at bit 0
OutputBuffer[dwNumBytesToSend++] = 0x13; //Set SK,DO,GPIOL0 pins as output with bit 1, other pins as input with bit 0
}
for(dwCount=0; dwCount < 20; dwCount++)
{
OutputBuffer[dwNumBytesToSend++] = 0x80; //Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = 0x00;
OutputBuffer[dwNumBytesToSend++] = 0x13; //Set SK,DO,GPIOL0 pins as output with bit 1, other pins as input with bit 0
}
//Sleep(10); //Delay for a while
//-------------I2cSendByteAndNotCheckACK_DeviceAddr-------------------------
OutputBuffer[dwNumBytesToSend++] = MSB_FALLING_EDGE_CLOCK_BYTE_OUT; //Clock data byte out on -ve Clock Edge MSB first
OutputBuffer[dwNumBytesToSend++] = '\x00';
OutputBuffer[dwNumBytesToSend++] = '\x00'; //Data length of 0x0000 means 1 byte data to clock out(8 bit)
OutputBuffer[dwNumBytesToSend++] = DeviceAddr;
//Get slave's ack
for(dwCount=0; dwCount<4; dwCount++) // Repeat commands to ensure the minimum period of the stop setup time ie 800ns is achieved
{
OutputBuffer[dwNumBytesToSend++] = 0x80; //Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = 0x02;
OutputBuffer[dwNumBytesToSend++] = 0x13; //Set SK,DO,GPIOL0 pins as output with bit 1, other pins as input with bit 0
}
for(dwCount=0; dwCount<10; dwCount++) // Repeat commands to ensure the minimum period of the stop setup time ie 800ns is achieved
{
OutputBuffer[dwNumBytesToSend++] = 0x80; //Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = 0x03;
OutputBuffer[dwNumBytesToSend++] = 0x13; //Set SK,DO,GPIOL0 pins as output with bit 1, other pins as input with bit 0
}
for(dwCount=0; dwCount<40; dwCount++) // Repeat commands to ensure the minimum period of the stop setup time ie 800ns is achieved
{
OutputBuffer[dwNumBytesToSend++] = 0x80; //Command to set directions of lower 8 pins and force value on bits set as output
OutputBuffer[dwNumBytesToSend++] = 0x02;
OutputBuffer[dwNumBytesToSend++] = 0x13; //Set SK,DO,GPIOL0 pins as output with bit 1, other pins as input with bit 0
}
//Sleep(10); //Delay for a while
//-------------I2cSendByteAndNotCheckACK_RegAddr-------------------------
OutputBuffer[dwNumBytesToSend++] = MSB_FALLING_EDGE_CLOCK_BYTE_OUT; //Clock data byte out on -ve Clock Edge MSB first
OutputBuffer[dwNumBytesToSend