FTDI Community

General Category => Discussion - Software => Topic started by: allenhuffman on April 23, 2020, 05:46:21 PM

Title: FT4222 and PC as an I2C slave example?
Post by: allenhuffman on April 23, 2020, 05:46:21 PM
We use FTDI I2C Master in a PC host program, but today I am trying to get a PC program to act as a slave so our embedded device can send some status information.

I am using a custom C# wrapper I wrote for the FT4222 I2C things. We use it successfully in an application running as a Master.

We are using the previous 1.4.2 release of the DLL package (I just noticed the 1.4.3 release today, which fixes a bug we'd encountered).

My code loop is very simple, but I get nothing back from it. I have used an analyzer and seen that there is I2C traffic with the correct address, but nothing makes it to my program. I expect I am missing something simple. My loop looks like this:

Code: [Select]
I2C i2c = new I2C(); // my wrapper

i2c.OpenByName("FT4222 A");

i2c.SlaveInit();
i2c.SlaveSetAddress((byte)0x40); // let's hard-code 40, which is the default.

Console.WriteLine("Slave address: 0x{0:x2} ({0})", i2c.SlaveGetAddress());

do
{
if (i2c.SlaveGetRxStatus() == 0) continue;

messageBuffer = i2c.SlaveRead(4);

for (int idx = 0; idx < 4; idx++)
{
Console.Write("{0:x2} ", messageBuffer[idx]);
}
Console.WriteLine();

} while (true);

GetRxStatus() always returns 0, but I do see my embedded device is writing out an I2C sequence to address 0x40 with four bytes after it. They are not being ACKed, so I don't think I have things set up properly for Slave.

Based on the examples in the PDF manual, and the i2c_slave.cpp sample code, it seems pretty straight forward.

Am I missing a step?

Thanks to whoever has the eyes to spot my mistake.
Title: Re: FT4222 and PC as an I2C slave example?
Post by: FTDI Community on April 27, 2020, 04:35:56 PM
Hello,

Is the device configured to be a different interface (I2C master?) before you try and initialise it as a I2C slave?
Do all of the function calls return with an FT_OK return code?


Best Regards,
FTDI Community
Title: Re: FT4222 and PC as an I2C slave example?
Post by: allenhuffman on April 30, 2020, 04:35:47 PM
This problem went away after two days of messing with it. Even using the default address of 0x40 was not working. Then it started. "SWT" (Strange Windows Thing?). An I have a fairly clean fresh install of Windows 10 from about a month ago, and I reboot my system every morning at the start of the day. Dunno!