<?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 K22 I2C and NACK in Kinetis Design Studio</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/K22-I2C-and-NACK/m-p/785693#M9796</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;I am using the K22FN256LH12 microcontroller with KDSv 3.2 and Processor Expert, and I am trying to get it to work with this AM2315 temperature sensor. I am currently using the I2C_LDD to communicate through I2C to other peripherals as well as this one. This sensor keeps giving me issues though. The first image below is of the sensor working correctly on an arduino, and the second is mine. I do not understand why I keep getting a NACK, any suggestions?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/61248i7A0125000F0C7620/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/61320i41B3D73AC16C3BE0/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is my code, I had to bit bang the first "184" since it needs a unique delayed stop...&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;#define AM2315_I2CADDR 0x5C //&amp;lt;&amp;lt;1&lt;BR /&gt;#define AM2315_READREG 0x03&lt;/P&gt;&lt;P&gt;byte err;&lt;BR /&gt; byte addr; // = AM2315_I2CADDR;&lt;BR /&gt; byte i = 0;&lt;/P&gt;&lt;P&gt;//first thing is to turn on the 5V&lt;BR /&gt; V5_ENABLE;&lt;BR /&gt;&lt;BR /&gt; //now bit-bang the wakeup since the I2C h/w cannot do this&lt;BR /&gt; //set mux to change I2C to GPIO (MUX=1)&lt;BR /&gt; PORTB_PCR1 &amp;amp;= ~(1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR1 |= (1 &amp;lt;&amp;lt; 8);&lt;BR /&gt; PORTB_PCR0 &amp;amp;= ~(1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR0 |= (1 &amp;lt;&amp;lt; 8);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//set data direction register for output&lt;BR /&gt; //must be done in following order or glitch will result on output&lt;BR /&gt; GPIOB_PDOR |= 0x3; //set BUS IDLE&lt;BR /&gt; GPIOB_PDDR |= 0x3;&lt;/P&gt;&lt;P&gt;WAIT1_Waitms(1);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); //set SDA 0&lt;BR /&gt; WAIT1_Waitus(10);&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 0); //SCL is 0&lt;BR /&gt; WAIT1_Waitus(1);&lt;BR /&gt;//&lt;BR /&gt;// //send out address&lt;BR /&gt; addr = AM2315_I2CADDR&amp;lt;&amp;lt;1;&lt;BR /&gt; for (i = 0; i &amp;lt; 8; i++) {&lt;BR /&gt; if (addr &amp;amp; 0x80) {&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 1); //set SDA 1&lt;BR /&gt; } else {&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); //set SDA 0&lt;BR /&gt; }&lt;BR /&gt; addr = addr &amp;lt;&amp;lt; 1; //get next bit&lt;BR /&gt; WAIT1_Waitus(1); //and clock it out&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 0); //SCL is 1&lt;BR /&gt; WAIT1_Waitus(5);&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 0); //SCL is 0&lt;BR /&gt; WAIT1_Waitus(5);&lt;BR /&gt; }&lt;BR /&gt; //send ACK&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 1); //set SDA 1&lt;BR /&gt; WAIT1_Waitus(1);&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 0); //SCL is 1&lt;BR /&gt; WAIT1_Waitus(10);&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 0); //SCL is 0&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); //set SDA 0&lt;/P&gt;&lt;P&gt;//wait a millisecond (required by sensor and not to exceed 3ms)&lt;BR /&gt; WAIT1_Waitus(70);&lt;/P&gt;&lt;P&gt;//send STOP&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 0); //set SCL high&lt;BR /&gt; WAIT1_Waitus(2);&lt;BR /&gt;// GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 1); //set SDA high&lt;BR /&gt;// }// end of bit bang&lt;/P&gt;&lt;P&gt;//set GPIO pin mux back to I2C (MUX= 0x02)&lt;BR /&gt; PORTB_PCR0 |= (1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR0 &amp;amp;= ~(1 &amp;lt;&amp;lt; 8);&lt;BR /&gt; PORTB_PCR1 |= (1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR1 &amp;amp;= ~(1 &amp;lt;&amp;lt; 8);&lt;BR /&gt;&lt;BR /&gt;MyI2CPtr = I2C_Sensors_Init(NULL);&lt;BR /&gt; //at this point , can use regular I2C&lt;BR /&gt; //I2C_TxCompleted = false;&lt;BR /&gt; tx_buf[0] = 0xB8;&lt;BR /&gt; tx_buf[1] = 0x3U; //start at register 0&lt;BR /&gt; tx_buf[2] = 0; //request four&lt;BR /&gt; tx_buf[2] = 0x4U; //request four&lt;BR /&gt;&lt;BR /&gt; uint8_t InpData[10];&lt;BR /&gt; I2C_TxCompleted = FALSE;&lt;BR /&gt; I2C_Sensors_SelectSlaveDevice(MyI2CPtr, LDD_I2C_ADDRTYPE_7BITS, 0x5C);&lt;BR /&gt; err = I2C_Sensors_MasterSendBlock(MyI2CPtr, tx_buf, 4, LDD_I2C_SEND_STOP);&lt;BR /&gt; while (!I2C_TxCompleted) { /* Wait until OutData are transmitted */&lt;BR /&gt; I2C_Sensors_Main(MyI2CPtr);&lt;BR /&gt; }&lt;BR /&gt; I2C_TxCompleted = FALSE;&lt;BR /&gt; WAIT1_Waitms(2); //wait atleast 1.5ms for sensor to start reply&lt;BR /&gt; /* Read Sensor */&lt;BR /&gt; err = I2C_Sensors_MasterReceiveBlock(MyI2CPtr, InpData, 8U, LDD_I2C_SEND_STOP);&lt;BR /&gt; while (!I2C_TxCompleted) { /* Wait until OutData are transmitted */&lt;BR /&gt; I2C_Sensors_Main(MyI2CPtr);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;Any ideas would be much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Jun 2018 02:07:17 GMT</pubDate>
    <dc:creator>burgeh</dc:creator>
    <dc:date>2018-06-15T02:07:17Z</dc:date>
    <item>
      <title>K22 I2C and NACK</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/K22-I2C-and-NACK/m-p/785693#M9796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;I am using the K22FN256LH12 microcontroller with KDSv 3.2 and Processor Expert, and I am trying to get it to work with this AM2315 temperature sensor. I am currently using the I2C_LDD to communicate through I2C to other peripherals as well as this one. This sensor keeps giving me issues though. The first image below is of the sensor working correctly on an arduino, and the second is mine. I do not understand why I keep getting a NACK, any suggestions?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/61248i7A0125000F0C7620/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/61320i41B3D73AC16C3BE0/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is my code, I had to bit bang the first "184" since it needs a unique delayed stop...&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;#define AM2315_I2CADDR 0x5C //&amp;lt;&amp;lt;1&lt;BR /&gt;#define AM2315_READREG 0x03&lt;/P&gt;&lt;P&gt;byte err;&lt;BR /&gt; byte addr; // = AM2315_I2CADDR;&lt;BR /&gt; byte i = 0;&lt;/P&gt;&lt;P&gt;//first thing is to turn on the 5V&lt;BR /&gt; V5_ENABLE;&lt;BR /&gt;&lt;BR /&gt; //now bit-bang the wakeup since the I2C h/w cannot do this&lt;BR /&gt; //set mux to change I2C to GPIO (MUX=1)&lt;BR /&gt; PORTB_PCR1 &amp;amp;= ~(1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR1 |= (1 &amp;lt;&amp;lt; 8);&lt;BR /&gt; PORTB_PCR0 &amp;amp;= ~(1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR0 |= (1 &amp;lt;&amp;lt; 8);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//set data direction register for output&lt;BR /&gt; //must be done in following order or glitch will result on output&lt;BR /&gt; GPIOB_PDOR |= 0x3; //set BUS IDLE&lt;BR /&gt; GPIOB_PDDR |= 0x3;&lt;/P&gt;&lt;P&gt;WAIT1_Waitms(1);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); //set SDA 0&lt;BR /&gt; WAIT1_Waitus(10);&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 0); //SCL is 0&lt;BR /&gt; WAIT1_Waitus(1);&lt;BR /&gt;//&lt;BR /&gt;// //send out address&lt;BR /&gt; addr = AM2315_I2CADDR&amp;lt;&amp;lt;1;&lt;BR /&gt; for (i = 0; i &amp;lt; 8; i++) {&lt;BR /&gt; if (addr &amp;amp; 0x80) {&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 1); //set SDA 1&lt;BR /&gt; } else {&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); //set SDA 0&lt;BR /&gt; }&lt;BR /&gt; addr = addr &amp;lt;&amp;lt; 1; //get next bit&lt;BR /&gt; WAIT1_Waitus(1); //and clock it out&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 0); //SCL is 1&lt;BR /&gt; WAIT1_Waitus(5);&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 0); //SCL is 0&lt;BR /&gt; WAIT1_Waitus(5);&lt;BR /&gt; }&lt;BR /&gt; //send ACK&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 1); //set SDA 1&lt;BR /&gt; WAIT1_Waitus(1);&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 0); //SCL is 1&lt;BR /&gt; WAIT1_Waitus(10);&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 0); //SCL is 0&lt;BR /&gt; GPIOB_PDOR &amp;amp;= ~(1 &amp;lt;&amp;lt; 1); //set SDA 0&lt;/P&gt;&lt;P&gt;//wait a millisecond (required by sensor and not to exceed 3ms)&lt;BR /&gt; WAIT1_Waitus(70);&lt;/P&gt;&lt;P&gt;//send STOP&lt;BR /&gt; GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 0); //set SCL high&lt;BR /&gt; WAIT1_Waitus(2);&lt;BR /&gt;// GPIOB_PDOR |= (1 &amp;lt;&amp;lt; 1); //set SDA high&lt;BR /&gt;// }// end of bit bang&lt;/P&gt;&lt;P&gt;//set GPIO pin mux back to I2C (MUX= 0x02)&lt;BR /&gt; PORTB_PCR0 |= (1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR0 &amp;amp;= ~(1 &amp;lt;&amp;lt; 8);&lt;BR /&gt; PORTB_PCR1 |= (1 &amp;lt;&amp;lt; 9);&lt;BR /&gt; PORTB_PCR1 &amp;amp;= ~(1 &amp;lt;&amp;lt; 8);&lt;BR /&gt;&lt;BR /&gt;MyI2CPtr = I2C_Sensors_Init(NULL);&lt;BR /&gt; //at this point , can use regular I2C&lt;BR /&gt; //I2C_TxCompleted = false;&lt;BR /&gt; tx_buf[0] = 0xB8;&lt;BR /&gt; tx_buf[1] = 0x3U; //start at register 0&lt;BR /&gt; tx_buf[2] = 0; //request four&lt;BR /&gt; tx_buf[2] = 0x4U; //request four&lt;BR /&gt;&lt;BR /&gt; uint8_t InpData[10];&lt;BR /&gt; I2C_TxCompleted = FALSE;&lt;BR /&gt; I2C_Sensors_SelectSlaveDevice(MyI2CPtr, LDD_I2C_ADDRTYPE_7BITS, 0x5C);&lt;BR /&gt; err = I2C_Sensors_MasterSendBlock(MyI2CPtr, tx_buf, 4, LDD_I2C_SEND_STOP);&lt;BR /&gt; while (!I2C_TxCompleted) { /* Wait until OutData are transmitted */&lt;BR /&gt; I2C_Sensors_Main(MyI2CPtr);&lt;BR /&gt; }&lt;BR /&gt; I2C_TxCompleted = FALSE;&lt;BR /&gt; WAIT1_Waitms(2); //wait atleast 1.5ms for sensor to start reply&lt;BR /&gt; /* Read Sensor */&lt;BR /&gt; err = I2C_Sensors_MasterReceiveBlock(MyI2CPtr, InpData, 8U, LDD_I2C_SEND_STOP);&lt;BR /&gt; while (!I2C_TxCompleted) { /* Wait until OutData are transmitted */&lt;BR /&gt; I2C_Sensors_Main(MyI2CPtr);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;Any ideas would be much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2018 02:07:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/K22-I2C-and-NACK/m-p/785693#M9796</guid>
      <dc:creator>burgeh</dc:creator>
      <dc:date>2018-06-15T02:07:17Z</dc:date>
    </item>
  </channel>
</rss>

