<?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のトピックi2c communication not working.</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-communication-not-working/m-p/641761#M25385</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, i am using LPC1768 MC embedded on local&amp;nbsp;development board. to fetch data from MCU 9250, i2c communication is needed. I haven't used any library for the purpose and all code is written in ARDUINO IDE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In Master sender mode, after sending start byte, and slave address, "I2STAT" should have one of definite state : 0x08 , 0x018, 0x28 &amp;nbsp;But in this case, "I2STATE" comes out to be have "0xF8", which is INVALID. Please check the code, and tell what is missing/wrong.( I am struct with this thing from the past 4 days.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define WAIT_SI while (!(LPC_I2C1-&amp;gt;I2CONSET &amp;amp; (1&amp;lt;&amp;lt;3)))&lt;BR /&gt;#define CLEAR_SI LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 3&lt;/P&gt;&lt;P&gt;void i2c_enable(){&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET |= 1&amp;lt;&amp;lt; 6; //ENABLE I2C1 (CONSET REGISTER)&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void i2c_start(){&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET |= 1&amp;lt;&amp;lt; 5; &lt;BR /&gt;WAIT_SI; // WAIT UNTIL DONE &lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void i2c_stop(){&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET |= 1&amp;lt;&amp;lt;4; // stop i2c&lt;BR /&gt;CLEAR_SI; //clear SI&lt;BR /&gt;// while (LPC_I2C1-&amp;gt;I2CONSET &amp;amp; (1&amp;lt;&amp;lt;4)); // wait until H/W stops i2c&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char i2c_address(unsigned char add)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2DAT = add;&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 5;&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 3;&lt;BR /&gt;WAIT_SI;&lt;BR /&gt;return (LPC_I2C1-&amp;gt;I2STAT);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void i2c_write(char data)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2DAT = data;&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 3;&lt;BR /&gt;CLEAR_SI;&lt;BR /&gt;WAIT_SI;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char i2c_read(char ack)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;if(ack)&lt;BR /&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET = 1&amp;lt;&amp;lt;2;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 2;&lt;BR /&gt;} &lt;BR /&gt;CLEAR_SI;&lt;BR /&gt;// WAIT_SI;&lt;BR /&gt;return (LPC_I2C1-&amp;gt; I2DAT);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void sysInit() {&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR0 |= 0x33; //P0.5 P0.4 P0.1 P0.0 ext pins 29,30,10,9&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR0 |= 1&amp;lt;&amp;lt;00;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR0 |= 1&amp;lt;&amp;lt;01;&lt;BR /&gt;LPC_SC-&amp;gt;PCONP |= 1 &amp;lt;&amp;lt; 19; //re-enable POWER to I2C_1 if required&lt;BR /&gt;LPC_SC-&amp;gt;PCLKSEL1 |= 1&amp;lt;&amp;lt;6; //pclk = cclk&lt;BR /&gt;LPC_PINCON-&amp;gt;PINSEL0 |= 0x03&amp;lt;&amp;lt;00; //Pin P0.00 allocated to alternate function 3&lt;BR /&gt;LPC_PINCON-&amp;gt;PINSEL0 |= 0x03&amp;lt;&amp;lt;01; //Pin P0.01 allocated to alternate function 3&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR |= 1&amp;lt;&amp;lt;00; //Bit P0.10 an output&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR |= 1&amp;lt;&amp;lt;01; //Bit P0.11 an output&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE0 &amp;amp;= ~(3&amp;lt;&amp;lt;00); //P0.10 has pull up/down resistor&lt;BR /&gt;//LPC_PINCON-&amp;gt;PINMODE0 |= (2&amp;lt;&amp;lt;20); //omit to use internal pull up&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE0 &amp;amp;= ~(3&amp;lt;&amp;lt;02); //P0.11 has pull up/down resistor&lt;BR /&gt;//LPC_PINCON-&amp;gt;PINMODE0 |= (2&amp;lt;&amp;lt;22); //omit to use internal pull up&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE_OD0 |= 1&amp;lt;&amp;lt;00; //Bit P0.10 is open drain&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE_OD0 |= 1&amp;lt;&amp;lt;01; //Bit P0.11 is open drain&lt;BR /&gt;LPC_I2C1-&amp;gt;I2SCLH = 60; //100kHz from 12MHz&lt;BR /&gt;LPC_I2C1-&amp;gt;I2SCLL = 60; //100kHz from 12MHz&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void setup() {&lt;/P&gt;&lt;P&gt;sysInit();&lt;BR /&gt;Serial.begin(9600);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void loop() {&lt;BR /&gt;unsigned char st;&lt;BR /&gt;i2c_enable();&lt;BR /&gt;i2c_start();&lt;BR /&gt;st=i2c_address(0xD0);&lt;BR /&gt;Serial.print(st,HEX); &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; //state value comes out to be 0xF8&lt;/STRONG&gt;&lt;BR /&gt;if (st == 0x18) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;{&lt;BR /&gt;//do nothing;&lt;BR /&gt;}&lt;BR /&gt;if (st == 0x20) &amp;nbsp; &amp;nbsp;// 0x20 signifies: slave address is send, ackno does not recieve.&lt;BR /&gt;{&lt;BR /&gt;Serial.println("success");&lt;BR /&gt;i2c_stop();&lt;BR /&gt;while(1);&lt;BR /&gt;}&lt;BR /&gt;//Serial.print("no sucess");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Code is tested over EXPLORE M3(locally made board) without any slave device connected. Slave Address used is random. In described &amp;nbsp;condition 'I2STATE' should have 0x20.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Dec 2016 15:07:51 GMT</pubDate>
    <dc:creator>rishavsharma</dc:creator>
    <dc:date>2016-12-26T15:07:51Z</dc:date>
    <item>
      <title>i2c communication not working.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-communication-not-working/m-p/641761#M25385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, i am using LPC1768 MC embedded on local&amp;nbsp;development board. to fetch data from MCU 9250, i2c communication is needed. I haven't used any library for the purpose and all code is written in ARDUINO IDE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In Master sender mode, after sending start byte, and slave address, "I2STAT" should have one of definite state : 0x08 , 0x018, 0x28 &amp;nbsp;But in this case, "I2STATE" comes out to be have "0xF8", which is INVALID. Please check the code, and tell what is missing/wrong.( I am struct with this thing from the past 4 days.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define WAIT_SI while (!(LPC_I2C1-&amp;gt;I2CONSET &amp;amp; (1&amp;lt;&amp;lt;3)))&lt;BR /&gt;#define CLEAR_SI LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 3&lt;/P&gt;&lt;P&gt;void i2c_enable(){&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET |= 1&amp;lt;&amp;lt; 6; //ENABLE I2C1 (CONSET REGISTER)&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void i2c_start(){&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET |= 1&amp;lt;&amp;lt; 5; &lt;BR /&gt;WAIT_SI; // WAIT UNTIL DONE &lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void i2c_stop(){&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET |= 1&amp;lt;&amp;lt;4; // stop i2c&lt;BR /&gt;CLEAR_SI; //clear SI&lt;BR /&gt;// while (LPC_I2C1-&amp;gt;I2CONSET &amp;amp; (1&amp;lt;&amp;lt;4)); // wait until H/W stops i2c&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char i2c_address(unsigned char add)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2DAT = add;&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 5;&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 3;&lt;BR /&gt;WAIT_SI;&lt;BR /&gt;return (LPC_I2C1-&amp;gt;I2STAT);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void i2c_write(char data)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2DAT = data;&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 3;&lt;BR /&gt;CLEAR_SI;&lt;BR /&gt;WAIT_SI;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char i2c_read(char ack)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;if(ack)&lt;BR /&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONSET = 1&amp;lt;&amp;lt;2;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;LPC_I2C1-&amp;gt;I2CONCLR = 1&amp;lt;&amp;lt; 2;&lt;BR /&gt;} &lt;BR /&gt;CLEAR_SI;&lt;BR /&gt;// WAIT_SI;&lt;BR /&gt;return (LPC_I2C1-&amp;gt; I2DAT);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void sysInit() {&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR0 |= 0x33; //P0.5 P0.4 P0.1 P0.0 ext pins 29,30,10,9&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR0 |= 1&amp;lt;&amp;lt;00;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR0 |= 1&amp;lt;&amp;lt;01;&lt;BR /&gt;LPC_SC-&amp;gt;PCONP |= 1 &amp;lt;&amp;lt; 19; //re-enable POWER to I2C_1 if required&lt;BR /&gt;LPC_SC-&amp;gt;PCLKSEL1 |= 1&amp;lt;&amp;lt;6; //pclk = cclk&lt;BR /&gt;LPC_PINCON-&amp;gt;PINSEL0 |= 0x03&amp;lt;&amp;lt;00; //Pin P0.00 allocated to alternate function 3&lt;BR /&gt;LPC_PINCON-&amp;gt;PINSEL0 |= 0x03&amp;lt;&amp;lt;01; //Pin P0.01 allocated to alternate function 3&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR |= 1&amp;lt;&amp;lt;00; //Bit P0.10 an output&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIODIR |= 1&amp;lt;&amp;lt;01; //Bit P0.11 an output&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE0 &amp;amp;= ~(3&amp;lt;&amp;lt;00); //P0.10 has pull up/down resistor&lt;BR /&gt;//LPC_PINCON-&amp;gt;PINMODE0 |= (2&amp;lt;&amp;lt;20); //omit to use internal pull up&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE0 &amp;amp;= ~(3&amp;lt;&amp;lt;02); //P0.11 has pull up/down resistor&lt;BR /&gt;//LPC_PINCON-&amp;gt;PINMODE0 |= (2&amp;lt;&amp;lt;22); //omit to use internal pull up&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE_OD0 |= 1&amp;lt;&amp;lt;00; //Bit P0.10 is open drain&lt;BR /&gt;LPC_PINCON-&amp;gt;PINMODE_OD0 |= 1&amp;lt;&amp;lt;01; //Bit P0.11 is open drain&lt;BR /&gt;LPC_I2C1-&amp;gt;I2SCLH = 60; //100kHz from 12MHz&lt;BR /&gt;LPC_I2C1-&amp;gt;I2SCLL = 60; //100kHz from 12MHz&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void setup() {&lt;/P&gt;&lt;P&gt;sysInit();&lt;BR /&gt;Serial.begin(9600);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void loop() {&lt;BR /&gt;unsigned char st;&lt;BR /&gt;i2c_enable();&lt;BR /&gt;i2c_start();&lt;BR /&gt;st=i2c_address(0xD0);&lt;BR /&gt;Serial.print(st,HEX); &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; //state value comes out to be 0xF8&lt;/STRONG&gt;&lt;BR /&gt;if (st == 0x18) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;{&lt;BR /&gt;//do nothing;&lt;BR /&gt;}&lt;BR /&gt;if (st == 0x20) &amp;nbsp; &amp;nbsp;// 0x20 signifies: slave address is send, ackno does not recieve.&lt;BR /&gt;{&lt;BR /&gt;Serial.println("success");&lt;BR /&gt;i2c_stop();&lt;BR /&gt;while(1);&lt;BR /&gt;}&lt;BR /&gt;//Serial.print("no sucess");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Code is tested over EXPLORE M3(locally made board) without any slave device connected. Slave Address used is random. In described &amp;nbsp;condition 'I2STATE' should have 0x20.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Dec 2016 15:07:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/i2c-communication-not-working/m-p/641761#M25385</guid>
      <dc:creator>rishavsharma</dc:creator>
      <dc:date>2016-12-26T15:07:51Z</dc:date>
    </item>
  </channel>
</rss>

