<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: I2C interface problems (iMX6-SABRESDB)... in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264818#M27350</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;More...&lt;/P&gt;&lt;P&gt;Just noticed that if I change the above code so that I am accessing the eCompass (SLAVE_ADDR=0x0e, bus=/dev/i2c-2)&lt;/P&gt;&lt;P&gt;i'm able to access that device.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Oct 2013 19:18:22 GMT</pubDate>
    <dc:creator>EdSutter</dc:creator>
    <dc:date>2013-10-04T19:18:22Z</dc:date>
    <item>
      <title>I2C interface problems (iMX6-SABRESDB)...</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264817#M27349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't have much experience with linux/i2c (plenty of i2c, just not much on linux).&lt;/P&gt;&lt;P&gt;Anyway, in preparation for a few I2C devices on our custom hardware I wanted to play with the generic&lt;/P&gt;&lt;P&gt;linux i2c driver just to get used to it.&amp;nbsp; I picked the accelerometer (MMA8451Q, device addr: 0x1C, bus 0).&lt;/P&gt;&lt;P&gt;The device seems simple enough to use, but I keep getting a Input/Output error when I try to write&lt;/P&gt;&lt;P&gt;to it.&amp;nbsp; Here's the entire snippet of code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#include &amp;lt;errno.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#include &amp;lt;fcntl.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#include &amp;lt;linux/i2c-dev.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#define SLAVE_ADDR&amp;nbsp; 0x1c&amp;nbsp;&amp;nbsp;&amp;nbsp; /* SA0 is low, so addr=1c */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;int&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;main(int argc, char *argv[])&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i, j, dev;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char buf[8];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((dev = open("/dev/i2c-0", O_RDWR)) &amp;lt; 0) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror("open failed");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ioctl(dev, I2C_SLAVE, SLAVE_ADDR) &amp;lt; 0) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror("ioctl failed");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(dev);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; buf[0] = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (write(dev,buf,1) != 1) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror("write failed");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(dev);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (read(dev,buf,1) != 1) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror("read failed");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(dev);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(dev);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;1;i++)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("buf[%d]: 0x%02x\n",i,buf[i]);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the the correct way to access a device on the I2C bus?&lt;/P&gt;&lt;P&gt;Any hints as to where the problem might be?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 18:46:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264817#M27349</guid>
      <dc:creator>EdSutter</dc:creator>
      <dc:date>2013-10-04T18:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: I2C interface problems (iMX6-SABRESDB)...</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264818#M27350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;More...&lt;/P&gt;&lt;P&gt;Just noticed that if I change the above code so that I am accessing the eCompass (SLAVE_ADDR=0x0e, bus=/dev/i2c-2)&lt;/P&gt;&lt;P&gt;i'm able to access that device.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 19:18:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264818#M27350</guid>
      <dc:creator>EdSutter</dc:creator>
      <dc:date>2013-10-04T19:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: I2C interface problems (iMX6-SABRESDB)...</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264819#M27351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Resolved...&lt;/P&gt;&lt;P&gt;I just noticed that L20 is removed from my board.. This puts the device in power-down mode, so all bets are off.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 19:33:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264819#M27351</guid>
      <dc:creator>EdSutter</dc:creator>
      <dc:date>2013-10-04T19:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: I2C interface problems (iMX6-SABRESDB)...</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264820#M27352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ed Sutter,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; In this code you are writing register at address 0 (buf) which is read only status register,so you can't do write operation on that.Try read operation on same register by calling read first instead of write.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sasidhar&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Oct 2013 10:20:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264820#M27352</guid>
      <dc:creator>Raybiztech</dc:creator>
      <dc:date>2013-10-05T10:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: I2C interface problems (iMX6-SABRESDB)...</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264821#M27353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sasidhar,&lt;/P&gt;&lt;P&gt;Yea good point (duh).&amp;nbsp; Bad example above.&lt;/P&gt;&lt;P&gt;Still can't access the device though because of the L20 issue.&lt;/P&gt;&lt;P&gt;No problem, I was able to access a different I2C device, and my primary goal at&lt;/P&gt;&lt;P&gt;this point is just get some experience with the Linux-I2C generic driver.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, just doing a read (without the illegal write above) didn't matter in my case.&lt;/P&gt;&lt;P&gt;The overriding issue is the absence of L20 on my board because we're using some&lt;/P&gt;&lt;P&gt;of the pins on that device in a different iomux mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Oct 2013 12:28:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/I2C-interface-problems-iMX6-SABRESDB/m-p/264821#M27353</guid>
      <dc:creator>EdSutter</dc:creator>
      <dc:date>2013-10-07T12:28:56Z</dc:date>
    </item>
  </channel>
</rss>

