I2C port questions

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

I2C port questions

Post by landon »

I was reviewing some of the I2C XMOS code in the example: module_i2c.1v1 and noticed this code:

Code: Select all

  // turn the data to input
   i2c.sda :> Temp;
   gt :> time;
   time += (I2C_BIT_TIME / 2);
   gt when timerafter(time) :> void;
   i2c.scl <: 1;

// sample first ACK.
   i2c.sda :> ack[0];
   gt :> time;
   time += (I2C_BIT_TIME / 2);
   gt when timerafter(time) :> void;
   i2c.scl <: 0;
Is it necessary to do that i2c.sda :> Temp; call to turn the port into an input? I haven't ready anywhere in the XMOS XC port docs that to switch directions you needed to do one of these dummy inputs.

Is this how an XMOS I2C master "releases" the I2C bus so the slave can drive it?

Landon


User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

In my experience, yes you do. It tripped me up for a long time, because one of the parts of hardware I use waits until the port becomes an input. So when I read the value, I got nothing, and then the hardware put out the data (when i wasn't listening). I had to put 2 consecutive read statements.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

Thanks for the confirmation. I was having trouble with this as well when I wrote some bit banging I2C today...it wasn't making sense so I started digging around and found that code above.

Once I put i a dummy read, it appeared to release the line.

Thanks again for the info,

Landon
daleonpz
Member++
Posts: 26
Joined: Thu Nov 04, 2010 1:18 pm

Post by daleonpz »

Im new with XS1-L1, and i would like to know how to communicate the module with an ADC using I2C. :oops:
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

I haven't done an I2C ADC interface with XMOS, only SPI. I'd suggest a couple things - look through all the example code available on xmos and xcore - there are definitely some I2C examples for other devices that could help you get started. Secondly, you might want to start a separate thread on the topic.