<?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 Help communicating with I2C octal registers and switches in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Help-communicating-with-I2C-octal-registers-and-switches/m-p/552237#M14362</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by jtor on Fri Feb 06 12:54:25 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an LPC2368 with a Keil Dev Board.&amp;nbsp; I am needing assistance in reading a couple I2C devices.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been trying to communicate with a PCA9557 as well as a PCA9547D both made by NXP.&amp;nbsp; Listed below are links to the data sheets.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A href="https://community.nxp.com/www.nxp.com/documents/data_sheet/PCA9557.pdf" rel="nofollow noopener noreferrer noopener noreferrer" target="test_blank"&gt;www.nxp.com/documents/data_sheet/PCA9557.pdf&lt;/A&gt; - &lt;/SPAN&gt;&lt;STRONG&gt;pg. 9 of 30&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.nxp.com%2Fdocuments%2Fdata_sheet%2FPCA9547.pdf" rel="noopener noreferrer" target="_blank"&gt;http://www.nxp.com/documents/data_sheet/PCA9547.pdf&lt;/A&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;STRONG&gt;pg. 6 of 30&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When configuring and reading these registers, my status bits are returning okay, but my expected output buffers are not accurate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to know if my method of communicating with these specific devices is correct, which I do not think so..&amp;nbsp; To illustrate this, I am going to have to post some code.&lt;/SPAN&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;
//CONFIGURE REGISTER PORTION
uint8 configOctalRegister(void)
{
uint8 stat;
uint8 buff[2] = { 0x03, 0x7F }; // 0x03 = CONIG REGISTER, 0x7F = pins 1 - 6 are inputs and pin 7 is an output

stat = writeI2C( ADDR_1, 2, buff, 1 ); //octalRegister1

return stat;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
int writeI2C(uint8 addr, uint8 sz, uint8 *buff, uint8 bus)
{
&amp;nbsp; uint8 i;
&amp;nbsp; uint16 stat;

&amp;nbsp; /* shift address to bits 7-1; bit 0 is R/W */
&amp;nbsp; I2CMasterBuffer[0] = addr&amp;lt;&amp;lt;1;

&amp;nbsp; /* write "size" + 1 uint8 for address */
&amp;nbsp; I2CWrLength = sz + 1;
&amp;nbsp; I2CRdLength = 0;
&amp;nbsp; for (i = 0; i &amp;lt; sz; i++)
I2CMasterBuffer[i+1] = buff&lt;I&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; stat = I2CEngine(bus);
&amp;nbsp; return stat;
}&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will now show the process of how I read the input register.&amp;nbsp; My I2C master buffer is this, in order, [0] = ADDR ; [1] = 0x00 (input reg) ; [2] = READ ADDR&lt;/SPAN&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;
uint8 readExpanderPins( uint8 addr)
{
uint8 stat;
uint8 buff;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buff = 0x00; //read the input port register

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stat = write_readI2C( ADDR_1, 1, 0x00, &amp;amp;buff, 1 );&amp;nbsp; //passing the addr, readSize, offset, buffer, bus
if(!stat)
{
bit2status = ( buff &amp;amp; 0x04 ); //buff[2]; bit2
bit3tatus = ( buff &amp;amp; 0x08 ); //buff[3]; bit3
bit4status = ( buff &amp;amp; 0x01 ); //buff[4]; bit4
bit5status = ( buff &amp;amp; 0x20 ); //buff[5]; bit5
bit6status = ( buff &amp;amp; 0x40 ); //buff[6]; bit6
}
return stat;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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;
int write_readI2C(uint8 addr, uint8 sz, uint8 offset, uint8 *buff, uint8 bus)
{
&amp;nbsp; uint8 i;
&amp;nbsp; uint16 stat;

&amp;nbsp; /* shift address to bits 7-1; bit 0 is R/W */
&amp;nbsp; I2CMasterBuffer[0] = addr&amp;lt;&amp;lt;1;

&amp;nbsp; /* write 2 size: I2C address + offset to read */
&amp;nbsp; I2CWrLength = 2;
&amp;nbsp; I2CMasterBuffer[1] = offset;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; /* now load read command */
&amp;nbsp; I2CMasterBuffer[2] = addr&amp;lt;&amp;lt;1 | RD_BIT;
&amp;nbsp; I2CRdLength = sz;

&amp;nbsp; stat = I2CEngine(bus); 
&amp;nbsp; if (stat)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return stat;

&amp;nbsp; if (RdIndex == 0) //no data was read
return FAIL; //(I2C_ERR_MASK | RD_ERR);
&amp;nbsp; for ( i = 0; i &amp;lt; sz; i++ )
&amp;nbsp;&amp;nbsp;&amp;nbsp; buff&lt;I&gt; = I2CMasterBuffer[i+3];

&amp;nbsp; return stat; 
}
&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will not show the interrupt routine soloely based on I know it works for reading and writing to other I2C devices such as temperature sensor.&amp;nbsp; Plus this post is already long enough.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate any expert help on my problem.&amp;nbsp; If any more content is needed just let me know.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Nov 2020 13:39:07 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2020-11-02T13:39:07Z</dc:date>
    <item>
      <title>Help communicating with I2C octal registers and switches</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Help-communicating-with-I2C-octal-registers-and-switches/m-p/552237#M14362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by jtor on Fri Feb 06 12:54:25 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an LPC2368 with a Keil Dev Board.&amp;nbsp; I am needing assistance in reading a couple I2C devices.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been trying to communicate with a PCA9557 as well as a PCA9547D both made by NXP.&amp;nbsp; Listed below are links to the data sheets.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A href="https://community.nxp.com/www.nxp.com/documents/data_sheet/PCA9557.pdf" rel="nofollow noopener noreferrer noopener noreferrer" target="test_blank"&gt;www.nxp.com/documents/data_sheet/PCA9557.pdf&lt;/A&gt; - &lt;/SPAN&gt;&lt;STRONG&gt;pg. 9 of 30&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.nxp.com%2Fdocuments%2Fdata_sheet%2FPCA9547.pdf" rel="noopener noreferrer" target="_blank"&gt;http://www.nxp.com/documents/data_sheet/PCA9547.pdf&lt;/A&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;STRONG&gt;pg. 6 of 30&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When configuring and reading these registers, my status bits are returning okay, but my expected output buffers are not accurate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to know if my method of communicating with these specific devices is correct, which I do not think so..&amp;nbsp; To illustrate this, I am going to have to post some code.&lt;/SPAN&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;
//CONFIGURE REGISTER PORTION
uint8 configOctalRegister(void)
{
uint8 stat;
uint8 buff[2] = { 0x03, 0x7F }; // 0x03 = CONIG REGISTER, 0x7F = pins 1 - 6 are inputs and pin 7 is an output

stat = writeI2C( ADDR_1, 2, buff, 1 ); //octalRegister1

return stat;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
int writeI2C(uint8 addr, uint8 sz, uint8 *buff, uint8 bus)
{
&amp;nbsp; uint8 i;
&amp;nbsp; uint16 stat;

&amp;nbsp; /* shift address to bits 7-1; bit 0 is R/W */
&amp;nbsp; I2CMasterBuffer[0] = addr&amp;lt;&amp;lt;1;

&amp;nbsp; /* write "size" + 1 uint8 for address */
&amp;nbsp; I2CWrLength = sz + 1;
&amp;nbsp; I2CRdLength = 0;
&amp;nbsp; for (i = 0; i &amp;lt; sz; i++)
I2CMasterBuffer[i+1] = buff&lt;I&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; stat = I2CEngine(bus);
&amp;nbsp; return stat;
}&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will now show the process of how I read the input register.&amp;nbsp; My I2C master buffer is this, in order, [0] = ADDR ; [1] = 0x00 (input reg) ; [2] = READ ADDR&lt;/SPAN&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;
uint8 readExpanderPins( uint8 addr)
{
uint8 stat;
uint8 buff;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buff = 0x00; //read the input port register

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stat = write_readI2C( ADDR_1, 1, 0x00, &amp;amp;buff, 1 );&amp;nbsp; //passing the addr, readSize, offset, buffer, bus
if(!stat)
{
bit2status = ( buff &amp;amp; 0x04 ); //buff[2]; bit2
bit3tatus = ( buff &amp;amp; 0x08 ); //buff[3]; bit3
bit4status = ( buff &amp;amp; 0x01 ); //buff[4]; bit4
bit5status = ( buff &amp;amp; 0x20 ); //buff[5]; bit5
bit6status = ( buff &amp;amp; 0x40 ); //buff[6]; bit6
}
return stat;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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;
int write_readI2C(uint8 addr, uint8 sz, uint8 offset, uint8 *buff, uint8 bus)
{
&amp;nbsp; uint8 i;
&amp;nbsp; uint16 stat;

&amp;nbsp; /* shift address to bits 7-1; bit 0 is R/W */
&amp;nbsp; I2CMasterBuffer[0] = addr&amp;lt;&amp;lt;1;

&amp;nbsp; /* write 2 size: I2C address + offset to read */
&amp;nbsp; I2CWrLength = 2;
&amp;nbsp; I2CMasterBuffer[1] = offset;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; /* now load read command */
&amp;nbsp; I2CMasterBuffer[2] = addr&amp;lt;&amp;lt;1 | RD_BIT;
&amp;nbsp; I2CRdLength = sz;

&amp;nbsp; stat = I2CEngine(bus); 
&amp;nbsp; if (stat)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return stat;

&amp;nbsp; if (RdIndex == 0) //no data was read
return FAIL; //(I2C_ERR_MASK | RD_ERR);
&amp;nbsp; for ( i = 0; i &amp;lt; sz; i++ )
&amp;nbsp;&amp;nbsp;&amp;nbsp; buff&lt;I&gt; = I2CMasterBuffer[i+3];

&amp;nbsp; return stat; 
}
&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will not show the interrupt routine soloely based on I know it works for reading and writing to other I2C devices such as temperature sensor.&amp;nbsp; Plus this post is already long enough.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate any expert help on my problem.&amp;nbsp; If any more content is needed just let me know.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 13:39:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Help-communicating-with-I2C-octal-registers-and-switches/m-p/552237#M14362</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2020-11-02T13:39:07Z</dc:date>
    </item>
  </channel>
</rss>

