<?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>LPCXpresso IDE中的主题 Re: I2C on LPC1343</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544799#M8902</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by groufosse on Mon Nov 05 15:26:45 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Rob65&lt;/STRONG&gt;&lt;BR /&gt;Done!&lt;BR /&gt;The attachment contains the updated driver as an exported Code Red project.&lt;BR /&gt;Note that I did this on an LPC1114 module, you need to change the references to the LPC11xx.h header file for an lpc13xx.&lt;BR /&gt;&lt;BR /&gt;I changed the state machine in the interrupt:&lt;BR /&gt;&lt;BR /&gt;[LIST]&lt;BR /&gt;[*]Added some comment to clarify the different states&lt;BR /&gt;[*]removed the assignments to I2CMasterState (these were not used).&lt;BR /&gt;[*]Changed I2CMasterState to give the result of the transaction&lt;BR /&gt;[*]fixed a bug (on a read there was actually one byte more read than requested).&lt;BR /&gt;[*]Added consequent handling for sending a STOP condition removing the need to send a STOP condition from I2CEngine()&lt;BR /&gt;[/LIST]&lt;BR /&gt;I also added a timeout to I2CStop() and the I2CEngine now returns a transaction result.&lt;BR /&gt;&lt;BR /&gt;The i2ctest.c is almost the same, all I did was a small change to use a 24LC08 EEPROM as a device and I added a check on the EEPROM read.&lt;BR /&gt;The 24LC08 will return a NACK on the slave address as long as it is writing the data to EEPROM. When this happens the I2CEngine will return the I2CSTATE_SLA_NACK value and the test program will loop until an actual read has taken place.&lt;BR /&gt;&lt;BR /&gt;There is also a screendump from the logic analyzer available showing all transactions but that image is too large for this forum. The image is available at: &lt;A href="http://"&gt;http://myvoice.nl/software/#XpressoDrivers&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;If there still is anything wrong with this driver feel free to shoot me (ehh... drop me an email) and I'll try to fix it.&lt;BR /&gt;&lt;BR /&gt;Some notes:&lt;BR /&gt;&lt;BR /&gt;[LIST]&lt;BR /&gt;[*]no real documentation added&lt;BR /&gt;[*]no extensive testing on fault conditions, the states 0x30, 0x38 and 0x48 in the state machine have not been tested&lt;BR /&gt;[*]I did not check all existing comments, there may still be some faulty comments&lt;BR /&gt;[*]the I2C clock is set to 400 kHz on the lpc1114, besides editing the i2c.h file there is no means to change the clock frequency.&lt;BR /&gt;[/LIST]&lt;BR /&gt; Regards,&lt;BR /&gt;&lt;BR /&gt;Rob&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Rob,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm new to using I2C, and taking a stab at using your sample. I've got it added into my IAR project. The code gets to the line where " I2CEngine();" is called, after all the I2CMasterBuffer variables are set. It never comes back from that call.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestion as to what I might look for to figure this out? Due to the nature of the call, the debugger can't step through it either.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my case, I've changed the references to include "LPC17xx.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Gary&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 21:58:31 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T21:58:31Z</dc:date>
    <item>
      <title>I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544733#M8836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JohnBurton on Thu Jul 15 10:07:06 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to use the I2C on an LPC1343 LPCXpresso board to read and write an EEPROM chip.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've taken the example code from the I2C sample and adapted it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've set the A0,1,2 pins on the chip to 0,and connected the SDA and SDC lines to the board with pullup resistors too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code I'm trying to use looks like this - but it never reads anything back. Most worryingly if I remove the chip entirely just keeping the pins with the pullups then it does exactly the same.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there anything else I have to do to make this work? I'm presuming I2CInit will set up the hardware settings required for this? Or am I missign something else I need to do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any suggestions&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;border:1px solid black;background-color:#cacaca;background-color:#cacaca;border:1px solid black;"&gt; &lt;PRE&gt;

#define EEPROM_ADDR 0xA0

int main(void)
{
int f;
I2CInit(I2CMASTER);

// Write the byte 0xFD into location zero in the EEPROM
I2CWriteLength = 4;
I2CReadLength&amp;nbsp; = 0;
I2CMasterBuffer[0] = EEPROM_ADDR;
I2CMasterBuffer[1] = 0x00;// 2 byte address zero
I2CMasterBuffer[2] = 0x00;
I2CMasterBuffer[3] = 0xFD;
I2CEngine();

// And read it back, should appear at IC2MasterBuffer[3 + 2] ...?
I2CWriteLength = 3;
I2CReadLength&amp;nbsp; = 1;
I2CMasterBuffer[0] = EEPROM_ADDR;
I2CMasterBuffer[1] = 0x00;// 2 byte address zero
I2CMasterBuffer[2] = 0x00;
I2CMasterBuffer[3] = EEPROM_ADDR | RD_BIT;
I2CEngine();

return 0 ;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544733#M8836</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544734#M8837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Jul 15 10:18:04 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you scope SCL / SDA and what&amp;nbsp; EEPROM ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544734#M8837</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544735#M8838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Thu Jul 15 10:45:07 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a quick look at the sample code shows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; /* Write SLA(W), address, SLA(R), and read one byte back. */
&amp;nbsp; I2CWriteLength = 2;
&amp;nbsp; I2CReadLength = 4;
&amp;nbsp; I2CMasterBuffer[0] = PCF8594_ADDR;
&amp;nbsp; I2CMasterBuffer[1] = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* address */
&amp;nbsp; I2CMasterBuffer[2] = PCF8594_ADDR | RD_BIT;
&amp;nbsp; I2CEngine();
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;It looks like the I2CReadLength needs to be 3 more than the number of bytes to be read. Seems like the I2CReadLength name is a bit misleading.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544735#M8838</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544736#M8839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JohnBurton on Thu Jul 15 11:13:11 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for looking.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem turned out to be this paragraph in the example i2ctest.c&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; (3) If it's a I2C Write/Read with repeated start, specify the &lt;BR /&gt;&amp;nbsp; I2CWriteLength, fill the content of bytes to be written in &lt;BR /&gt;&amp;nbsp; I2CMasterBuffer, specify the I2CReadLength, after the repeated &lt;BR /&gt;&amp;nbsp; start and the device address with RD bit set, the content of the &lt;BR /&gt;&amp;nbsp; reading will be filled in I2CMasterBuffer index at &lt;BR /&gt;&amp;nbsp; I2CMasterBuffer[I2CWriteLength+2]. &lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does not fill in the I2CMasterBuffer at that location it fills in the result in I2CSlaveBuffer at the start. It appears that this comment is simply wrong. Perhaps the sample can be updated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544736#M8839</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544737#M8840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Thu Jul 15 14:10:08 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Ouch!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: JohnBurton&lt;/STRONG&gt;&lt;BR /&gt;It appears that this comment is simply wrong. Perhaps the sample can be updated.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used to work at NXP and wrote these kind of sample programs (not for the LPCXpresso). Seeing these kind of errors just hurts :eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good thing you found this bug - I'll be needing the I2C driver in a week or so myself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe some of the Xpresso users could join in creating a set of (tested) standard drivers. I have already noticed that other sample programs also have errors; the SPI sample gives a wrong frequency for the CPI clock - here also comment and code do not match ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544737#M8840</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544738#M8841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JohnBurton on Sun Jul 18 03:49:53 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I agree that some better tested documented library code would be a very good thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And samples are very good, but a library would be better :)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544738#M8841</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544739#M8842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by ktownsend on Sun Jul 18 15:09:25 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Rob65&lt;/STRONG&gt;&lt;BR /&gt;It looks like the I2CReadLength needs to be 3 more than the number of bytes to be read. Seems like the I2CReadLength name is a bit misleading.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That definately had me scratching my head a bit as well when I was putting together some I2C drivers a while back. You indeed need to use one byte more than WriteLength would have you believe. For example (for an I2C eeprom):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt; 
&amp;nbsp; // Clear buffers
&amp;nbsp; for ( i = 0; i &amp;lt; I2C_BUFSIZE; i++ )
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; I2CMasterBuffer&lt;I&gt; = 0x00;
&amp;nbsp;&amp;nbsp;&amp;nbsp; I2CSlaveBuffer&lt;I&gt; = 0x00;
&amp;nbsp; }
&amp;nbsp; // Write address bits to enable random read
&amp;nbsp; I2CWriteLength = 3;
&amp;nbsp; I2CReadLength = bufferLength;
&amp;nbsp; I2CMasterBuffer[0] = MCP24AA_ADDR;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // I2C device address
&amp;nbsp; I2CMasterBuffer[1] = ((address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Address (high byte)
&amp;nbsp; I2CMasterBuffer[2] = (address &amp;amp; 0xFF);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Address (low byte)
&amp;nbsp; // Append address w/read bit
&amp;nbsp; I2CMasterBuffer[3] = MCP24AA_ADDR | MCP24AA_READBIT;&amp;nbsp; 
&amp;nbsp; // Transmit command
&amp;nbsp; i2cEngine();
 
&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's not really complicated once you know the magic formula, but I can imagine a lot of people really wondering why their code isn't working if they didn't look carefully at the provided examples to notice that. That said ... the examples still saved me a lot of time compared to starting with just the user manual in hand, so I don't want to complain TOO loudly either. &lt;SPAN class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;&lt;LI-EMOJI id="lia_face-with-open-mouth" title=":face_with_open_mouth:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544739#M8842</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544740#M8843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JohnBurton on Sun Jul 18 15:21:24 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, ReadLength needs to be the actual number of bytes you want to read.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;WriteLength is the number of bytes to send including the address. But if you want to read any bytes then you have to send the address again with the R/W bit set but don't include this in the write length.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The interface to this functionality isn't great, it would be much better to have separate I2C_Read and I2C_Write commands that take pointers to read and write buffers and their ACTUAL sizes. Shouldn't be too hard to wrap or rewrite to do this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544740#M8843</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544741#M8844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Mon Jul 19 04:01:30 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;and a user manual that is complete and correct would also be useful ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In both the lpc11xx and the 13xx user manuals there is no proper reference to the I2C_PCLK clock. In the clocking and power control chapter (10.7 for the 11xx, 12.7 for the lpc13xx) there is a PCLK_I2C clock mentioned. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Later on there are mixed references to PCLK_I2C and I2C_PCLK used in the register description for the duty cycle registers and a table lists different duty cycle values for different PCLK_I2C values but besides these references to this clock there is no description of what its value is or how to set this value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the lpc11xx sample 0x180 is used for the duty cycle registers and this results in a ~62.11 kHz I2C clock - what has the guy programming this been thinking ???&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like the PCLK is about 48 MHz. With the 48 MHz I did some calculations:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[LIST=1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]400 kHz should use I2CSCLH+I2CSCLL of 120&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the actual frequency is 384 kHz (2.6 us clockcycle instead of 2.5 us)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]100 kHz should use I2SCLH+I2SCLL of 480&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the actual frequency is 99 kHz (10.1 us cycle instead of 10 us)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]the 0x180 values (totals up to 768) should result in 62.5 kHz&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;actual cycle is 16.1 us instead of the calculated 16 us&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/LIST]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Fun isn't it? There is actual always a 0.1 us different in the calculated and the real clock cycle values :eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For 100 kHz I2CSCLH + I2CSCLL should be 475 (I used 237 for SCLH and 238 for SCLL) and 400 kHz needs a total of 115 (58 + 57) - this is tested on an lpc11xx Xpresso module from EA using a logic analyzer with a 200 MHz sampling rate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dear NXP, please enlighten us about the I2C_PCLK and how to calculate the SCLH/SCLL values. Where does this 0.1 us difference between the suggested calculation in the user manual an (my) real world come from?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544741#M8844</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544742#M8845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Mon Jul 19 08:40:16 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I am just now digging through the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This indeed is (just) sample code and not suited for real life apps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Comments do not always match with the code - E.g: the init function says it returns FALSE if the interrupt handler was not installed while in fact always a TRUE is returned and there is no check to see if the interrupt routine is installed (this is done at link time) ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are a number of while(1) loops, I don't think this is good coding.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; while( 1 )
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( I2CMasterState == I2C_STARTED )
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retVal = TRUE;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( timeout &amp;gt;= MAX_TIMEOUT )
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retVal = FALSE;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; timeout++;
&amp;nbsp; }
&amp;nbsp; return( retVal );&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;I think that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt; while((I2CMasterState != I2C_STARTED) &amp;amp;&amp;amp; (timeout &amp;lt; MAX_TIMEOUT))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; timeout++;
&amp;nbsp; return (timeout &amp;gt;= MAX_TIMEOUT);&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;is more readable&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and what about the I2CEngine function. This contains:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; while ( 1 )
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( I2CMasterState == DATA_NACK )
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2CStop();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;I got the creeps from reading this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Why do we wait forever and only stop on a DATA_NACK state ???&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the end I figured out that the DATA_NACK state is an internal state used by the interrupt state machine and the DATA_NACK is misused for the perfectly legal (and acknowledged by the slave) ending of the transaction.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The interrupt routine already sent out the STOP condition so there is no need to do this again ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And the state machine does not even check for an ACK or NACK after sending a byte ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But then, this code is usable as an example to write my own driver but I would not call this a good example.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looking at John's original code, this I2C driver will not suffice for an EEPROM like the 24LC08 - after writing the data, you need to do something called "Acknowledge polling": The 24LC08 keeps retuning a NACK on the slave address+R/W=0 as long as it is writing to memory so before reading valid data we need to make sure we received an ACK on the slave address.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope to change the code and test it today. I will post my code when finished.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544742#M8845</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544743#M8846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Mon Jul 19 13:27:56 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Done!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The attachment contains the updated driver as an exported Code Red project.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Note that I did this on an LPC1114 module, you need to change the references to the LPC11xx.h header file for an lpc13xx.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed the state machine in the interrupt:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[LIST]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]Added some comment to clarify the different states&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]removed the assignments to I2CMasterState (these were not used).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]Changed I2CMasterState to give the result of the transaction&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]fixed a bug (on a read there was actually one byte more read than requested).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]Added consequent handling for sending a STOP condition removing the need to send a STOP condition from I2CEngine()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/LIST]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I also added a timeout to I2CStop() and the I2CEngine now returns a transaction result.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The i2ctest.c is almost the same, all I did was a small change to use a 24LC08 EEPROM as a device and I added a check on the EEPROM read.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The 24LC08 will return a NACK on the slave address as long as it is writing the data to EEPROM. When this happens the I2CEngine will return the I2CSTATE_SLA_NACK value and the test program will loop until an actual read has taken place.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is also a screendump from the logic analyzer available showing all transactions but that image is too large for this forum. The image is available at: &lt;/SPAN&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2F" rel="nofollow" target="_blank"&gt;http://myvoice.nl/software/#XpressoDrivers&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If there still is anything wrong with this driver feel free to shoot me (ehh... drop me an email) and I'll try to fix it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Some notes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[LIST]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]no real documentation added&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]no extensive testing on fault conditions, the states 0x30, 0x38 and 0x48 in the state machine have not been tested&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]I did not check all existing comments, there may still be some faulty comments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[*]the I2C clock is set to 400 kHz on the lpc1114, besides editing the i2c.h file there is no means to change the clock frequency.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/LIST]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544743#M8846</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544744#M8847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by waterforces on Tue Jul 20 01:56:05 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I like function like :writeI2C(...) and readI2C(...), why use I2CEngine()? It makes me confused that perparing I2CMasterBuffer!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544744#M8847</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544745#M8848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Rob65 on Tue Jul 20 03:31:52 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: waterforces&lt;/STRONG&gt;&lt;BR /&gt;I like function like :writeI2C(...) and readI2C(...), why use I2CEngine()? It makes me confused that perparing I2CMasterBuffer!&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can understand this, yesterday's goal was just to get the example working, stable and a bit more readable. I am just now splitting the example into a separate (application) project and a static library for the i2c driver. Now I do see that I2CMasterBuffer and I2CSlaveBuffer are very confusing; these should be I2CWriteBuffer and I2CReadBuffer or even better have them as pointers to a buffer that is defined in the application (I need an 18 byte buffer for my EEPROM).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having separate writeI2C() and readI2C() function may seem logical but in order to do a read you always have to do a write first, followed by a restart and then a read.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What the write needs to do depends on the actual device. My small EEPROM needs just 1 byte as memory address, the larger EEPROM needs 2 bytes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And this write, restart, read is handled as one transaction by the interrupt routine. Therefore from a I2C perspective the I2CEngine() does make some sense.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What if I change the interface to the I2CEngine() a bit:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;uint32_t I2CEngine( uint32_t BytesToWrite, uint8_t &amp;amp;WriteBuffer, uint32_t BytesToRead, uint8_t *ReadBuffer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This as least makes a bit more sense than the fixed Master/Slave buffers we now have.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At the same time I'll also add a run-time configurable I2C clock.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544745#M8848</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544746#M8849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Lithium on Thu Oct 07 07:15:51 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;This topic is not that old,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am also trying to get the I2C working, i am using an lpc1343 board.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have found this topic and changed the example code to this code. I can understand about 90% of the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to read and write to an DS1307 real time clock ic.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;On page 12 you can see how the data needs to be send: &lt;/SPAN&gt;&lt;A href="http://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://datasheets.maxim-ic.com/en/ds/DS1307.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to send 3 times a byte, table 2 has only 2 bytes, one for the address and one for the data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What about the 3th one?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To send data i need this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
&amp;nbsp; I2CWriteLength = 3;
&amp;nbsp; I2CReadLength = 0;
&amp;nbsp; I2CMasterBuffer[0] = MC24LC08_ADDR;
&amp;nbsp; I2CMasterBuffer[1] = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* address */
&amp;nbsp; I2CMasterBuffer[2] = 0x55;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Data0 */
&amp;nbsp; I2CEngine();
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;Is that correct? Buffer 0 for the address of the DS1307, buffer1 for the internal address and buffer2 for the data?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Where does the I2CEngine() put the data in that has been read?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope you can help me with those questions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The address of the DS1307 is: 1101000 followed by the direction bit (R/W), which for a write is 0 So that will be: 11010000 to write and 11010001 to read?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If i want this to put it into a hex value it will be D0 to write and D1 to read?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544746#M8849</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544747#M8850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Oct 07 14:42:59 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I've used DS1307Z with several AT90CAN's and can confirm that your reading and writing address is OK:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;[B][COLOR=#9d0000]#define DS_R 0xD1 //read = DS1307 ADDRESS +1 [/COLOR][/B]&lt;BR /&gt;[B][COLOR=#9d0000]#define DS_W 0xD0 //write= DS1307 ADDRESS +0[/COLOR][/B]&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Although I didn't test this sample, it seems to work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Writing data:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I2CMasterBuffer must be filled with DS_W, address, data &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I2CWriteLength = 3;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I2CReadLength = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Reading data:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I2CMasterBuffer must be filled with DS_R, address&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I2CWriteLength = 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I2CReadLength = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After starting I2CEngine(), everything should be done in I2C_IRQHandler().&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Read data are stored in I2CSlaveBuffer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Note: DS1307 min supply voltage is 4.5V, so I would suggest to use DS1338-33 (3.3V). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;HTH,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Zero&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544747#M8850</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544748#M8851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Mike45 on Thu Nov 04 07:39:47 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;good thread, i am going to try some i2c stuff today.&amp;nbsp; What values should be used for a pullup?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:57:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544748#M8851</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544749#M8852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Nov 04 07:49:19 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using 10k :) without problems. But everything between 1k and 10k should work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How to calculate the correct value you can read in Chapter 17.2 of&amp;nbsp; 'I2C-BUS SPECIFICATION'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[FONT=GillSans,Bold][SIZE=4] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/SIZE][/FONT]&lt;/SPAN&gt;&lt;A href="http://"&gt;http://www.nxp.com/acrobat_download2/literature/9398/39340011.pdf&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Although the result of this calculation is about 1kOhm, a lot of circuits use a lower termination (=higher resistor). In practice EEPROMs with 400kHz and short I2C lines don't need high termination.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you use higher speed and longer I2C lines (like I2C-Temperature sensor) it's a good idea to use higher termination (=lower resistance).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:58:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544749#M8852</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544750#M8853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Mike45 on Thu Nov 04 09:09:34 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;I'm using 10k :) without problems. But everything between 1k and 10k should work.&lt;BR /&gt; &lt;BR /&gt;How to calculate the correct value you can read in Chapter 17.2 of&amp;nbsp; 'I2C-BUS SPECIFICATION'&lt;BR /&gt;[FONT=GillSans,Bold][SIZE=4] &lt;BR /&gt;[/SIZE][/FONT]&lt;A href="http://"&gt;http://www.nxp.com/acrobat_download2/literature/9398/39340011.pdf&lt;/A&gt;&lt;BR /&gt; &lt;BR /&gt;Although the result of this calculation is about 1kOhm, a lot of circuits use a lower termination (=higher resistor). In practice EEPROMs with 400kHz and short I2C lines don't need high termination.&lt;BR /&gt;If you use higher speed and longer I2C lines (like I2C-Temperature sensor) it's a good idea to use higher termination (=lower resistance).&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ty ty:D&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:58:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544750#M8853</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544751#M8854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by ktownsend on Sat Dec 18 12:51:51 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Rob65:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just wanted to say thanks for taking the time to post an update.&amp;nbsp; I was using the original i2c code and noticed the reads from EEPROM were randomly nutty.&amp;nbsp; Digging into it, it turned out to be the generic i2c code.&amp;nbsp; I'd been meaning to replace it since day one, but it was always lower on the todo list since it 'seemed' to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kevin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:58:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544751#M8854</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: I2C on LPC1343</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544752#M8855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by zzz on Fri Jan 07 00:46:08 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Rob for updating the example. However I am having difficulty connecting to the PCF8574 I2C I/O Expander IC. Has anyone had any luck connecting to this device?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I modified the code for 100khz speeds. &lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#define I2SCLH_SCLH237&amp;nbsp; /* I2C SCL Duty Cycle High Reg */
#define I2SCLL_SCLL238&amp;nbsp; /* I2C SCL Duty Cycle Low Reg */&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;I set the correct address, commented out the read portion since i just have 8 LEDs connected to the I/O pins. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I debug it never leaves I2CEngine() function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; while (I2CMasterState &amp;lt; 0x100);
&amp;nbsp; return ( I2CMasterState );&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:58:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/I2C-on-LPC1343/m-p/544752#M8855</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:58:02Z</dc:date>
    </item>
  </channel>
</rss>

