<?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: LPC1125 as I2C slave</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546711#M50587</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/27788"&gt;@Alice_Yang&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;many thanks for your reply.&lt;/P&gt;&lt;P&gt;The function I invoked is part of "your" library (have a look to the &lt;EM&gt;i2c_112x.c&lt;/EM&gt;) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Initializes the LPC_I2C peripheral with specified parameter */
void Chip_I2C_Init(I2C_ID_T id)
{
enableClk(id);

/* Bring I2C out of reset */
Chip_SYSCON_PeriphReset(RESET_I2C0);

/* Set I2C operation to default */
LPC_I2Cx(id)-&amp;gt;CONCLR = (I2C_CON_AA | I2C_CON_SI | I2C_CON_STA | I2C_CON_I2EN);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Should then exist a different &lt;EM&gt;Init&lt;/EM&gt; function for the I2C configured as &lt;EM&gt;Slave&lt;/EM&gt;?&lt;UL&gt;&lt;LI&gt;I added also the &lt;EM&gt;CONSET&lt;/EM&gt; line as:&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Set I2C operation to default */
LPC_I2Cx(id)-&amp;gt;CONCLR = (I2C_CON_AA | I2C_CON_SI | I2C_CON_STA | I2C_CON_I2EN);
LPC_I2Cx(id)-&amp;gt;CONSET = (I2C_CON_AA | I2C_CON_I2EN);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;... But I still not receiving (ISR not triggered).&lt;/P&gt;&lt;P&gt;And yes I'm using an external I2C logger as well.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there an order to execute the &lt;EM&gt;Init &lt;/EM&gt;function (&lt;EM&gt;Init_I2C_Slave&lt;/EM&gt;)?&lt;/LI&gt;&lt;LI&gt;Is there something else I forgot to check?&lt;UL&gt;&lt;LI&gt;Any suggestions?&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Many thanks!&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;superaga&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 08:15:51 GMT</pubDate>
    <dc:creator>superaga</dc:creator>
    <dc:date>2022-11-01T08:15:51Z</dc:date>
    <item>
      <title>LPC1125 as I2C slave</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546389#M50568</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I already checked for this issue and I didn't find any post.&lt;/P&gt;&lt;P&gt;I'm trying to make the LPC1125 work as slave on I2C using the interrupt mode, but I can't. When the program runs it doesn't hit the ISR when I try to connect to.&lt;/P&gt;&lt;P&gt;Based on the provided example &lt;EM&gt;periph_i2c&lt;/EM&gt; I wrote my init (using the provided &lt;EM&gt;lpc_chip_112x&lt;/EM&gt;) as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void Init_I2C_Slave(void){

/* Set the I2C inputs as standard mode*/
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO0_4, IOCON_FUNC1);
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO0_5, IOCON_FUNC1);

/* Init I2C module */
Chip_I2C_Init(I2C0);

/* Set the clock rate for the I2C peripheral */
Chip_I2C_SetClockRate(I2C0, I2C_DEFAULT_SPEED);

/* Set the I2C mode to interrupt*/
Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandler);

/* Configure the I2C parameters */
dev_xfer.slaveAddr = (I2C_SLAVE_ADDR &amp;lt;&amp;lt; 1);
dev_xfer.rxBuff = &amp;amp;g_comm.rxBuff;
dev_xfer.rxSz = sizeof(g_comm.rxBuff);
dev_xfer.txBuff = &amp;amp;g_comm.txBuff;
dev_xfer.txSz = sizeof(g_comm.txBuff);
Chip_I2C_SlaveSetup(I2C0, I2C_SLAVE_0, &amp;amp;g_comm, I2C_Events, 0);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where my events function has been defined as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;static void I2C_Events(I2C_ID_T id, I2C_EVENT_T event){

	switch(event){
	case I2C_EVENT_DONE:
		printf("I2C done event\r\n");
		printf("%i\r\n", g_comm.rxBuff);
		// update size
		printf("\r\n");
		break;

	case I2C_EVENT_SLAVE_RX:
		printf("I2C receive event\r\n");
		printf("%i\r\n", g_comm.rxBuff);
		printf("\r\n");
		break;

	case I2C_EVENT_SLAVE_TX:
		printf("I2C transmit event\r\n");
		printf("%i\r\n", g_comm.txBuff);
		printf("\r\n");
		break;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And my exchange data structure globally defined (to share data across the program) as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Global communication structure */
typedef struct {
	uint8_t	rxBuff;
	uint8_t txBuff;
}g_comm_t;
g_comm_t g_comm;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally my IRQ handler defined as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/**
 * @brief	I2C Interrupt Handler
 * @return	None
 */
void I2C_IRQHandler(void)
{
	Chip_I2C_SlaveStateHandler(I2C0);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course in my &lt;EM&gt;main&lt;/EM&gt; I call the init and I enable the NVIC as well:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Init the I2C module as slave */
Init_I2C_Slave();

/* Enable the I2C NVIC interrupt */
NVIC_EnableIRQ(I2C0_IRQn);&lt;/LI-CODE&gt;&lt;P&gt;My questions are:&lt;/P&gt;&lt;P&gt;Are the functions of my &lt;EM&gt;Init_I2C_Slave&lt;/EM&gt; routine executed in the right order?&lt;/P&gt;&lt;P&gt;In the &lt;A href="https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwjDmrLh3or7AhWU8LsIHTFsDG4QFnoECCYQAQ&amp;amp;url=https%3A%2F%2Fwww.nxp.com%2Fdocs%2Fen%2Fdata-sheet%2FLPC112X.pdf&amp;amp;usg=AOvVaw3IAdwCIhVuQn_kWEGdcdGs" target="_blank" rel="noopener"&gt;device user manual&lt;/A&gt; (rev1.0) at &lt;EM&gt;Slave Receiver mode&lt;/EM&gt; (page 101) it is written that to initialize the I2C module as slave receiver I have to write the &lt;EM&gt;Slave Address&lt;/EM&gt; register and write the &lt;EM&gt;I2C Control Set&lt;/EM&gt; register as follow:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic_01.png" style="width: 531px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/198647i976425379E6A7B3A/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic_01.png" alt="pic_01.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But if you take a look to the &lt;EM&gt;Chip_I2C_Init&lt;/EM&gt; it is implemented as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{
	enableClk(id);

	/* Bring I2C out of reset */
	Chip_SYSCON_PeriphReset(RESET_I2C0);

	/* Set I2C operation to default */
	LPC_I2Cx(id)-&amp;gt;CONCLR = (I2C_CON_AA | I2C_CON_SI | I2C_CON_STA | I2C_CON_I2EN);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see above the flags: SI, STA are set too.&lt;/P&gt;&lt;P&gt;Should then exist a different &lt;EM&gt;Init&lt;/EM&gt; function for the I2C configured as &lt;EM&gt;Slave&lt;/EM&gt;?&lt;/P&gt;&lt;P&gt;One more: the function &lt;EM&gt;Chip_I2C_SetMasterEventHandler &lt;/EM&gt;needs to be used in the I2C Slave mode as well? Because the name it is a bit misleading and I couldn't find any good explanation other than:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Set the master event handler */
int Chip_I2C_SetMasterEventHandler(I2C_ID_T id, I2C_EVENTHANDLER_T event){
...
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In its own definition.&lt;/P&gt;&lt;P&gt;I assume "yes" since this part exists in the provided example... But I don't understand what it does.&lt;/P&gt;&lt;P&gt;Could you please help me to fix this?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 15:36:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546389#M50568</guid>
      <dc:creator>superaga</dc:creator>
      <dc:date>2022-10-31T15:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1125 as I2C slave</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546668#M50581</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/180438"&gt;@superaga&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-c"&gt;&lt;CODE&gt;/* Set I2C operation to default */
	LPC_I2Cx(id)-&amp;gt;CONCLR = (I2C_CON_AA | I2C_CON_SI | I2C_CON_STA | I2C_CON_I2EN);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Pay attention, this is CON&lt;FONT color="#FF0000"&gt;CLR&lt;FONT color="#000000"&gt; register, not CONSET.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;This code function is clear&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;SI and STA to 0 .&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;2) "&amp;nbsp;the function&amp;nbsp;&lt;EM&gt;Chip_I2C_SetMasterEventHandler&amp;nbsp;&lt;/EM&gt;needs to be used in the I2C Slave mode as well?&amp;nbsp;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;-&amp;gt;&amp;gt; Yes.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Recommend you use logic analyzer measure I2C signal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Alice&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 06:42:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546668#M50581</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2022-11-01T06:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1125 as I2C slave</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546711#M50587</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/27788"&gt;@Alice_Yang&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;many thanks for your reply.&lt;/P&gt;&lt;P&gt;The function I invoked is part of "your" library (have a look to the &lt;EM&gt;i2c_112x.c&lt;/EM&gt;) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Initializes the LPC_I2C peripheral with specified parameter */
void Chip_I2C_Init(I2C_ID_T id)
{
enableClk(id);

/* Bring I2C out of reset */
Chip_SYSCON_PeriphReset(RESET_I2C0);

/* Set I2C operation to default */
LPC_I2Cx(id)-&amp;gt;CONCLR = (I2C_CON_AA | I2C_CON_SI | I2C_CON_STA | I2C_CON_I2EN);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Should then exist a different &lt;EM&gt;Init&lt;/EM&gt; function for the I2C configured as &lt;EM&gt;Slave&lt;/EM&gt;?&lt;UL&gt;&lt;LI&gt;I added also the &lt;EM&gt;CONSET&lt;/EM&gt; line as:&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Set I2C operation to default */
LPC_I2Cx(id)-&amp;gt;CONCLR = (I2C_CON_AA | I2C_CON_SI | I2C_CON_STA | I2C_CON_I2EN);
LPC_I2Cx(id)-&amp;gt;CONSET = (I2C_CON_AA | I2C_CON_I2EN);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;... But I still not receiving (ISR not triggered).&lt;/P&gt;&lt;P&gt;And yes I'm using an external I2C logger as well.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there an order to execute the &lt;EM&gt;Init &lt;/EM&gt;function (&lt;EM&gt;Init_I2C_Slave&lt;/EM&gt;)?&lt;/LI&gt;&lt;LI&gt;Is there something else I forgot to check?&lt;UL&gt;&lt;LI&gt;Any suggestions?&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Many thanks!&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;superaga&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 08:15:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546711#M50587</guid>
      <dc:creator>superaga</dc:creator>
      <dc:date>2022-11-01T08:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: LPC1125 as I2C slave</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546945#M50592</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I've been able to fix the issue.&lt;/P&gt;&lt;P&gt;I made a mistake in my &lt;EM&gt;Init_I2C_Slave&lt;/EM&gt; function, I wrongly passed my data structure (&lt;EM&gt;g_comm&lt;/EM&gt;) instead of the correct one.&lt;/P&gt;&lt;P&gt;In fact the &lt;EM&gt;Chip_I2C_SlaveSetup&lt;/EM&gt; function (declared as below) needs its &lt;EM&gt;I2C_XFER_T&lt;/EM&gt; data structure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void Chip_I2C_SlaveSetup(
    I2C_ID_T id,
    I2C_SLAVE_ID sid,
    I2C_XFER_T *xfer,
    I2C_EVENTHANDLER_T event,
    uint8_t addrMask);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The correct code results then:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void Init_I2C_Slave(void){
...
...
	/* Configure the I2C parameters */
	dev_xfer.slaveAddr = (I2C_SLAVE_ADDR &amp;lt;&amp;lt; 1);
	dev_xfer.rxBuff = &amp;amp;g_comm.rxBuff;
	dev_xfer.rxSz = sizeof(g_comm.rxBuff);
	dev_xfer.txBuff = &amp;amp;g_comm.txBuff;
	dev_xfer.txSz = sizeof(g_comm.txBuff);
	Chip_I2C_SlaveSetup(I2C0, I2C_SLAVE_0, &amp;amp;dev_xfer, I2C_Events, 0);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can then answer also to the other questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Should then exist a different &lt;EM&gt;Init&lt;/EM&gt; function for the I2C configured as &lt;EM&gt;Slave&lt;/EM&gt;?&lt;UL&gt;&lt;LI&gt;No, the existing function works properly.&lt;/LI&gt;&lt;LI&gt;There is no need to further add the following line (inside the &lt;EM&gt;Chip_I2C_Init&lt;/EM&gt; function):&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;LPC_I2Cx(id)-&amp;gt;CONSET = (I2C_CON_AA | I2C_CON_I2EN);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there an order to execute the &lt;EM&gt;Init &lt;/EM&gt;function (&lt;EM&gt;Init_I2C_Slave&lt;/EM&gt;)?&lt;UL&gt;&lt;LI&gt;The used order (in my &lt;EM&gt;Init_I2C_Slave&lt;/EM&gt; routine) worked properly.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 15:56:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC1125-as-I2C-slave/m-p/1546945#M50592</guid>
      <dc:creator>superaga</dc:creator>
      <dc:date>2022-11-01T15:56:03Z</dc:date>
    </item>
  </channel>
</rss>

