FT2232 I2C 8位设备地址 8位寄存器地址 8位数据 读写示例

参考官方文档: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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值