<?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: LPC8XX problem with I2C in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579793#M24263</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by dheide on Thu Oct 16 15:52:48 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, good point!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was just a test case since it did not work in the real programm (where the variables were volatile) but I'll correct that immediatly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jun 2016 00:01:19 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-16T00:01:19Z</dc:date>
    <item>
      <title>LPC8XX problem with I2C</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579791#M24261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by dheide on Mon Oct 13 14:09:05 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a problem using the I2C to communicate with a display. Below, I pasted the code which I destilled from the examples and the documentation. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I understand that the interrupt is enabled, but never called and the code hangs in the loop that waits for the interrupt. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm kind of stuck, so any help is appreciated!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers, dheide&lt;/SPAN&gt;&lt;BR /&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;

#define CLOCK_SETUP 1

#include "LPC8xx.h"

#define MASTER_STATE_MASK(0x7&amp;lt;&amp;lt;1)
#define STAT_MSTPEND&amp;nbsp; (1 &amp;lt;&amp;lt; 0)
#define STAT_MSTRX (0x1 &amp;lt;&amp;lt; 1)
#define STAT_MSTTX (0x2 &amp;lt;&amp;lt; 1)
#define I2C_SMODE_PRE_DIV(90-1)
#define CFG_MSTENA(1 &amp;lt;&amp;lt; 0)
#define STAT_MSTARBLOSS(1 &amp;lt;&amp;lt; 4)
#define STAT_MSTSSERR (1 &amp;lt;&amp;lt; 6)
#define TIM_MSTSCLLOW(d)((d) &amp;lt;&amp;lt; 0)
#define TIM_MSTSCLHIGH(d)((d) &amp;lt;&amp;lt; 4)

#define CTL_MSTCONTINUE(1 &amp;lt;&amp;lt; 0)
#define CTL_MSTSTART(1 &amp;lt;&amp;lt; 1)
#define CTL_MSTSTOP (1 &amp;lt;&amp;lt; 2)


uint32_t I2CInterruptCount = 0;
uint32_t I2CMstRXCount = 0;
uint32_t I2CMstTXCount = 0;
uint32_t msttxrdy = 0;
uint32_t mstrxrdy = 0;

LPC_I2C_TypeDef *I2Cx = (LPC_I2C_TypeDef*) LPC_I2C_BASE;

void I2C_IRQHandler(void)
{
uint32_t active = LPC_I2C-&amp;gt;INTSTAT;
uint32_t i2cmststate = LPC_I2C-&amp;gt;STAT &amp;amp; MASTER_STATE_MASK;

I2CInterruptCount++;&amp;nbsp; &amp;lt;&amp;lt;--- Never called!!!

if ( active &amp;amp; STAT_MSTPEND )
{
LPC_I2C-&amp;gt;INTENCLR = STAT_MSTPEND;

switch ( i2cmststate )
{
case STAT_MSTRX:
I2CMstRXCount++;
mstrxrdy = 1;
break;

case STAT_MSTTX:
I2CMstTXCount++;
msttxrdy = 1;
break;
}
}

}

int main(void)
{
uint32_t i, regVal;

SystemInit();
SystemCoreClockUpdate();

/* Initialize I2C pin connect */
/* connect the I2C SCL and SDA sigals to port pins(P0.10-P0.11)*/
regVal = LPC_SWM-&amp;gt;PINASSIGN7 &amp;amp; ~(0xFFUL&amp;lt;&amp;lt;24);
LPC_SWM-&amp;gt;PINASSIGN7 = regVal | (10 &amp;lt;&amp;lt; 24);/* P0.10 is I2C SDA, ASSIGN0(31:24) */
regVal = LPC_SWM-&amp;gt;PINASSIGN8 &amp;amp; ~(0xFF&amp;lt;&amp;lt;0);
LPC_SWM-&amp;gt;PINASSIGN8 = regVal | (11 &amp;lt;&amp;lt; 0);/* P0.11 is I2C SCL. ASSIGN0(7:0) */

/* Enable I2C clock */
LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (1&amp;lt;&amp;lt;5);
/* Toggle peripheral reset control to I2C, a "1" bring it out of reset. */
LPC_SYSCON-&amp;gt;PRESETCTRL &amp;amp;= ~(0x1&amp;lt;&amp;lt;6);
LPC_SYSCON-&amp;gt;PRESETCTRL |= (0x1&amp;lt;&amp;lt;6);

/* setup I2C */
uint32_t dutycycle = 0;
I2Cx-&amp;gt;DIV = I2C_SMODE_PRE_DIV;
I2Cx-&amp;gt;CFG &amp;amp;= ~(CFG_MSTENA);
msttxrdy = mstrxrdy = 0;

I2Cx-&amp;gt;MSTTIME = TIM_MSTSCLLOW(dutycycle) | TIM_MSTSCLHIGH(dutycycle);
I2Cx-&amp;gt;INTENSET |= ( STAT_MSTARBLOSS | STAT_MSTSSERR );

NVIC_EnableIRQ(I2C_IRQn);

I2Cx-&amp;gt;CFG |= CFG_MSTENA;

//
uint8_t addr = 0x3F &amp;lt;&amp;lt; 1;

uint32_t len = 2;
uint8_t tx[len];
tx[0] = 0xFF; tx[1] = 0xFF;

I2Cx-&amp;gt;MSTDAT = addr;
I2Cx-&amp;gt;MSTCTL = CTL_MSTSTART;

msttxrdy = 0;
I2Cx-&amp;gt;INTENSET = STAT_MSTPEND;

for ( i = 0; i &amp;lt; len; i++ )
{
while(!msttxrdy);&amp;nbsp;&amp;nbsp; &amp;lt;&amp;lt;--- Here, the program hangs.

msttxrdy = 0;
I2Cx-&amp;gt;MSTDAT = tx&lt;I&gt;;
I2Cx-&amp;gt;MSTCTL = CTL_MSTCONTINUE;
I2Cx-&amp;gt;INTENSET = STAT_MSTPEND;
}

while(1);
return 0;
}

&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:01:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579791#M24261</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: LPC8XX problem with I2C</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579792#M24262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by starblue on Tue Oct 14 00:26:57 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;For a start you should make I2CInterruptCount and the other variables volatile.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:01:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579792#M24262</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: LPC8XX problem with I2C</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579793#M24263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by dheide on Thu Oct 16 15:52:48 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, good point!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was just a test case since it did not work in the real programm (where the variables were volatile) but I'll correct that immediatly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:01:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/LPC8XX-problem-with-I2C/m-p/579793#M24263</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:01:19Z</dc:date>
    </item>
  </channel>
</rss>

