<?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: I2C slave mode on KL02Z with processor expert and Kinetis I2C2_LDD in Processor Expert Software</title>
    <link>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459748#M3717</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello George,&lt;/P&gt;&lt;P&gt;You must use (call) the &lt;EM&gt;I2C2_SlaveReceiveBlock()&lt;/EM&gt; before the data are being received, i.e. this method sets pointer to your buffer for storing data. See the following example the is available on the Typical Usage page of the I2C_LDD component help.&lt;/P&gt;&lt;P&gt;Please note, that the data are received in the buffer when the &lt;EM&gt;I2C3_OnSlaveBlockReceived()&lt;/EM&gt; event is invoked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;volatile bool DataReceivedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;volatile bool DataTransmittedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;uint8_t OutData[4] = {0x00U, 0x01U, 0x02U, 0x03U}; /* Initialization of output data buffer */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;uint8_t InpData[4];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LDD_TError Error;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LDD_TDeviceData *MyI2CPtr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void main(void)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; . . .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; MyI2CPtr = I2C2_Init(NULL); /* Initialization of I2C2 component */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; Error = I2C2_SlaveSendBlock(MyI2CPtr, OutData, 4U); /* Send OutData (4bytes) to I2C BUS */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; while (!DataTransmittedFlg) { /* Wait until OutData are transmitted */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; DataTransmittedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; Error = I2C2_SlaveReceiveBlock(MyI2CPtr, InpData, 4U); /* Receive InpData (16bytes) from I2C BUS */&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; while (!DataReceivedFlg) { /* Wait until InpData are received */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; DataReceivedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; for(;;) {}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Content of Event.c:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="code"&gt;extern volatile bool DataTransmittedFlg;
void I2C3_OnSlaveBlockSent(LDD_TUserData *UserDataPtr)
{
&amp;nbsp; DataTransmittedFlg = TRUE; /* Set DataTransmittedFlg flag */
}

extern volatile bool DataReceivedFlg;
void I2C3_OnSlaveBlockReceived(LDD_TUserData *UserDataPtr)
{
&amp;nbsp; DataReceivedFlg = TRUE; /* Set DataReceivedFlg flag */
}&lt;/PRE&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Marek Neuzil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Apr 2016 06:44:04 GMT</pubDate>
    <dc:creator>marek_neuzil</dc:creator>
    <dc:date>2016-04-29T06:44:04Z</dc:date>
    <item>
      <title>I2C slave mode on KL02Z with processor expert and Kinetis I2C2_LDD</title>
      <link>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459747#M3716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using an MKL02Z32VFM4 micro-controller for my project, programming it through the KDS (3.2.0) and PE (3.0.2.b151214). I am using the Kinetis I2C2_LDD component for I2C communications, set to slave mode, running at 93.623kHz at address 0x2A. However, I am not entirely sure how to use the component when it comes to implementing my code. When a master tries writing data to the slave, it enters the I2C2_OnSlaveRxRequest() function in Events.c. I then try receiving the data with:&lt;/P&gt;&lt;P&gt;res = I2C2_SlaveReceiveBlock(&amp;amp;deviceData, &amp;amp;data, 1U);&lt;/P&gt;&lt;P&gt;if (res != ERR_OK) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ERR_FAILED;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;but every time I2C2_SlaveReceiveBlock() returns 0x08, which is ERR_BUSY /*!&amp;lt; Device is busy. */&lt;/P&gt;&lt;P&gt;Do I need to generate an acknowledgement of the master addressing the slave before attempting to read the data? And if so, how would I go about doing this? I feel as though I am missing some steps here, can anyone point me in the right direction?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;George&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2016 13:14:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459747#M3716</guid>
      <dc:creator>georgeaddison</dc:creator>
      <dc:date>2016-04-19T13:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: I2C slave mode on KL02Z with processor expert and Kinetis I2C2_LDD</title>
      <link>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459748#M3717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello George,&lt;/P&gt;&lt;P&gt;You must use (call) the &lt;EM&gt;I2C2_SlaveReceiveBlock()&lt;/EM&gt; before the data are being received, i.e. this method sets pointer to your buffer for storing data. See the following example the is available on the Typical Usage page of the I2C_LDD component help.&lt;/P&gt;&lt;P&gt;Please note, that the data are received in the buffer when the &lt;EM&gt;I2C3_OnSlaveBlockReceived()&lt;/EM&gt; event is invoked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;volatile bool DataReceivedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;volatile bool DataTransmittedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;uint8_t OutData[4] = {0x00U, 0x01U, 0x02U, 0x03U}; /* Initialization of output data buffer */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;uint8_t InpData[4];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LDD_TError Error;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LDD_TDeviceData *MyI2CPtr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void main(void)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; . . .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; MyI2CPtr = I2C2_Init(NULL); /* Initialization of I2C2 component */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; Error = I2C2_SlaveSendBlock(MyI2CPtr, OutData, 4U); /* Send OutData (4bytes) to I2C BUS */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; while (!DataTransmittedFlg) { /* Wait until OutData are transmitted */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; DataTransmittedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; Error = I2C2_SlaveReceiveBlock(MyI2CPtr, InpData, 4U); /* Receive InpData (16bytes) from I2C BUS */&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; while (!DataReceivedFlg) { /* Wait until InpData are received */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; DataReceivedFlg = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; for(;;) {}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Content of Event.c:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="code"&gt;extern volatile bool DataTransmittedFlg;
void I2C3_OnSlaveBlockSent(LDD_TUserData *UserDataPtr)
{
&amp;nbsp; DataTransmittedFlg = TRUE; /* Set DataTransmittedFlg flag */
}

extern volatile bool DataReceivedFlg;
void I2C3_OnSlaveBlockReceived(LDD_TUserData *UserDataPtr)
{
&amp;nbsp; DataReceivedFlg = TRUE; /* Set DataReceivedFlg flag */
}&lt;/PRE&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Marek Neuzil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2016 06:44:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459748#M3717</guid>
      <dc:creator>marek_neuzil</dc:creator>
      <dc:date>2016-04-29T06:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: I2C slave mode on KL02Z with processor expert and Kinetis I2C2_LDD</title>
      <link>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459749#M3718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marek,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is great, thank you very much for showing me this. I confess I was unaware of the component help feature, this will certainly make my life a lot easier!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example given in the component help does indeed work as expected, however my only confusion now is, this example seems to rely on the slave knowing exactly when to receive the data? If the master is requesting to read or write data to the slave at arbitrary times, I would like to be able to be able to respond to an interrupt when the slave is addressed. When the master writes the slaves address, followed by the write bit, the &lt;STRONG&gt;I2C2_OnSlaveRxRequest()&lt;/STRONG&gt; is called. I assumed I could then use this to trigger the beginning of the slave's receipt of the data, but as mentioned in the description of this event:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;After the return from the event call the first data byte receiving starts&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So presumably I cannot receive data until that function has returned. I tried setting a flag here to tell another function when to start receiving data, but then that flag must be constantly polled, which rather defeats the purpose of interrupts.&lt;/P&gt;&lt;P&gt;So my question boils down to, how do I know when to call &lt;STRONG&gt;I2C2_SlaveReceiveBlock()&lt;/STRONG&gt; if the master is addressing the slave at an unknown time intervals?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect this is due to my lack of programming knowledge, so sorry if this is a silly question. Thanks again for your help,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;George&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 May 2016 16:37:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459749#M3718</guid>
      <dc:creator>georgeaddison</dc:creator>
      <dc:date>2016-05-01T16:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: I2C slave mode on KL02Z with processor expert and Kinetis I2C2_LDD</title>
      <link>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459750#M3719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello George,&lt;/P&gt;&lt;P&gt;In your case you can directly use the event &lt;EM&gt;I2C2_SlaveReceiveBlock() &lt;/EM&gt;to process the received data (you needn't wait for a flag in a loop). E.g. you can use this event to copy these received data into another buffer for processing, you can wakeup a task (in case of a RTOS is used) or do another action based on received data.&lt;/P&gt;&lt;P&gt;Therefore, in you application, you can prepare a buffer for receiving data by using the &lt;EM&gt;I2C2_SlaveReceiveBlock() &lt;/EM&gt;method of the I2C component (in a main function/task). This method just prepare buffer for the data and the application can run (it is not a blocking method). When the I2C interrupt occurs the enabled events (&lt;EM&gt;I2C2_OnSlaveRxRequest, &lt;EM&gt;I2C2_SlaveReceiveBlock&lt;/EM&gt;) &lt;/EM&gt;are subsequently called and you can use these events to trigger or process an action.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Marek Neuzil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Jun 2016 07:27:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Processor-Expert-Software/I2C-slave-mode-on-KL02Z-with-processor-expert-and-Kinetis-I2C2/m-p/459750#M3719</guid>
      <dc:creator>marek_neuzil</dc:creator>
      <dc:date>2016-06-27T07:27:57Z</dc:date>
    </item>
  </channel>
</rss>

