<?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>LPC MicrocontrollersのトピックRe: LPC open I2C driver - I2C master state machine</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-open-I2C-driver-I2C-master-state-machine/m-p/579294#M20007</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gnxp on Fri Sep 26 03:05:00 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;For completion, I'll update this issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;From Table 399. Master Transmitter mode and table Table 400. Master Receiver mode, it is clear that AA bit is&amp;nbsp; a don't care in most of situations. Section 19.10 is&amp;nbsp; a bit misleading. The good news is the driver works really well(at least the master handler which I am concerned about right now). I have managed to read/write data to 24LC64 EEPROM on lpc xpresso board. 32 bytes is the maximum size for a block write. To increase throughput by using ACK polling feature I just added a couple of lines to the driver as shown below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/* NAK Handling */
case 0x20:/* SLA+W sent NAK received */
/* After a STOP condition, write cycle begins in a EEPROM chip and it&amp;nbsp; won't ACK during the cycle. We use this to do a ACK polling. This means keep sending START and control byte till you get ACK. Take care to adjust with timeouts as you don't want to be stuck here in case of a dodgy chip&amp;nbsp; or if chip is full */
xfer-&amp;gt;status = I2C_STATUS_BUSY; /* Hold on */
if (xfer-&amp;gt;txSz) cclr &amp;amp;= ~I2C_CON_STA;
break;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 20:20:29 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T20:20:29Z</dc:date>
    <item>
      <title>LPC open I2C driver - I2C master state machine</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-open-I2C-driver-I2C-master-state-machine/m-p/579293#M20006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gnxp on Tue Sep 23 04:41:43 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Environment - lpc xpresso 1769 board with 24LC64 EEPROM on I2C, lpc open 2.10 library &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Going through I2C driver and the documentation, I find a discrepancy. The below code is directly from lpc driver with two commented lines which I added for the following explained reason.&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;
/* Master transfer state change handler handler */
int handleMasterXferState(LPC_I2C_T *pI2C, I2C_XFER_T&amp;nbsp; *xfer)
{
uint32_t cclr = I2C_CON_FLAGS;

switch (getCurState(pI2C)) {
case 0x08:/* Start condition on bus */
case 0x10:/* Repeated start condition */
pI2C-&amp;gt;DAT = (xfer-&amp;gt;slaveAddr &amp;lt;&amp;lt; 1) | (xfer-&amp;gt;txSz == 0);
//cclr &amp;amp;= ~I2C_CON_AA; /* Set AA bit??? */
break;

/* Tx handling */
case 0x18:/* SLA+W sent and ACK received */
case 0x28:/* DATA sent and ACK received */
if (!xfer-&amp;gt;txSz) {
cclr &amp;amp;= ~(xfer-&amp;gt;rxSz ? I2C_CON_STA : I2C_CON_STO);
}
else {
pI2C-&amp;gt;DAT = *xfer-&amp;gt;txBuff++;
xfer-&amp;gt;txSz--;
//cclr &amp;amp;= ~I2C_CON_AA; /* Set AA bit??? */
}
break;

/* Rx handling */
case 0x58:/* Data Received and NACK sent */
cclr &amp;amp;= ~I2C_CON_STO;

case 0x50:/* Data Received and ACK sent */
*xfer-&amp;gt;rxBuff++ = pI2C-&amp;gt;DAT;
xfer-&amp;gt;rxSz--;

case 0x40:/* SLA+R sent and ACK received */
if (xfer-&amp;gt;rxSz &amp;gt; 1) {
cclr &amp;amp;= ~I2C_CON_AA;
}
break;

/* NAK Handling */
case 0x20:/* SLA+W sent NAK received */
case 0x30:/* DATA sent NAK received */
case 0x48:/* SLA+R sent NAK received */
xfer-&amp;gt;status = I2C_STATUS_NAK;
cclr &amp;amp;= ~I2C_CON_STO;
break;

case 0x38:/* Arbitration lost */
xfer-&amp;gt;status = I2C_STATUS_ARBLOST;
break;

/* Bus Error */
case 0x00:
xfer-&amp;gt;status = I2C_STATUS_BUSERR;
cclr &amp;amp;= ~I2C_CON_STO;
}

/* Set clear control flags */
pI2C-&amp;gt;CONSET = cclr ^ I2C_CON_FLAGS;
pI2C-&amp;gt;CONCLR = cclr;

/* If stopped return 0 */
if (!(cclr &amp;amp; I2C_CON_STO) || (xfer-&amp;gt;status == I2C_STATUS_ARBLOST)) {
if (xfer-&amp;gt;status == I2C_STATUS_BUSY) {
xfer-&amp;gt;status = I2C_STATUS_DONE;
}
return 0;
}
return 1;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On rev 3.1 of lpc 1769 user manual(UM10360) pg.476, software handling of I2C states is explained. When 1769 is master and&amp;nbsp; I2STA reads 0x08,0x10,0x18 or 0x28, AA should be set as explained in pg. 476 and 477. I don't see that in above code. A slave would have to ACK data unless it is physically not able to accept it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I missing understanding anything in code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:20:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-open-I2C-driver-I2C-master-state-machine/m-p/579293#M20006</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: LPC open I2C driver - I2C master state machine</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-open-I2C-driver-I2C-master-state-machine/m-p/579294#M20007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by gnxp on Fri Sep 26 03:05:00 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;For completion, I'll update this issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;From Table 399. Master Transmitter mode and table Table 400. Master Receiver mode, it is clear that AA bit is&amp;nbsp; a don't care in most of situations. Section 19.10 is&amp;nbsp; a bit misleading. The good news is the driver works really well(at least the master handler which I am concerned about right now). I have managed to read/write data to 24LC64 EEPROM on lpc xpresso board. 32 bytes is the maximum size for a block write. To increase throughput by using ACK polling feature I just added a couple of lines to the driver as shown below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/* NAK Handling */
case 0x20:/* SLA+W sent NAK received */
/* After a STOP condition, write cycle begins in a EEPROM chip and it&amp;nbsp; won't ACK during the cycle. We use this to do a ACK polling. This means keep sending START and control byte till you get ACK. Take care to adjust with timeouts as you don't want to be stuck here in case of a dodgy chip&amp;nbsp; or if chip is full */
xfer-&amp;gt;status = I2C_STATUS_BUSY; /* Hold on */
if (xfer-&amp;gt;txSz) cclr &amp;amp;= ~I2C_CON_STA;
break;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:20:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-open-I2C-driver-I2C-master-state-machine/m-p/579294#M20007</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:20:29Z</dc:date>
    </item>
  </channel>
</rss>

