I2C Timing Issues

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
Posts: 9
Joined: Tue Jan 31, 2017 8:45 am

I2C Timing Issues

Postby ChrisDev » Fri Apr 21, 2017 10:56 am

Hello everybody,

I'm currently having some issues using an I2C communication or rather using the i2c library.
It seems to have no effect if, the kbits per second parameter is changed.
-- i2c_lib - snippet

Code: Select all

/** Implements I2C on the i2c_master_if interface using two ports.
 *  \param  i      An array of server interface connections for clients to
 *                 connect to
 *  \param  n      The number of clients connected
 *  \param  p_scl  The SCL port of the I2C bus
 *  \param  p_sda  The SDA port of the I2C bus
 *  \param  kbits_per_second The speed of the I2C bus
[[distributable]] void i2c_master(server interface i2c_master_if i[n],
                                  size_t n,
                                  port p_scl, port p_sda,
                                  unsigned kbits_per_second);

main.xc - snippet

Code: Select all

    on tile[1]:i2c_master(i2c,1,SCL,SDA,100);
    on tile[1]:adc(i2c,0);

By using these configuration for the i2c the result is like this:
SCL in blue, SDA in yellow. On the right hand side the timing is measured with two coursers.

Rising or lowering this parameter doesn't really effect the timing. Also the SCL's shape seems to be a bit suspicious.

Is this a known problem ? I haven't modified the i2c_lib in any kind.

I was digging a bit more regarding this problem and found out that the variable 'bit_time' which is calculated in the i2c_master task always has the value 100. No matter if kbits_per_second is about 100, 400 or even 1000.
But when I was trying to debug the calculation the xtimecomposer showed in the variable tab the following error... "_Si2c_master_0.init.1.state_ptr <mi_cmd_var_create: unable to create variable object>"

XCore Expert
Posts: 606
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Fri Apr 21, 2017 12:48 pm


1) A bit of dialog of your error posted here:



2) Forget the bit rate calculator and spoon feed the proper values manually - does that work to alter the SCL / SDA speeds ?

So change line 109 to a static value and test again. XS1_TIMER_MHZ should be 100.

From the scope capture, SCL is around 860khz ? If yes, that is beyond spec for most parts.

3) On the waveforms, what is the value of the I2C pull-ups for your project ? Recommend the values be 2.2k - 2.7k to 3v3. XMOS is not 5 volt tolerant on the port pins. We have found the pull-up resistors values are really not so critical but use 2k2 or higher and review the length of your I2C traces / wiring and suggest to keep them as short as possible.

Post back if this does not get resolved.

Return to “Development Tools and Programming”

Who is online

Users browsing this forum: No registered users and 20 guests