<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[REXYGEN Community Forum / Integrating I2C device using REXLANG]]></title>
	<link rel="self" href="https://www.rexygen.com/oldforum/extern.php?action=feed&amp;tid=26&amp;type=atom"/>
	<link href="http://www.rexygen.com/oldforum/viewtopic.php?id=26"/>
	<updated>2017-05-03T18:40:55Z</updated>
	<generator>FluxBB</generator>
	<id>http://www.rexygen.com/oldforum/viewtopic.php?id=26</id>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=1596#p1596"/>
		<content type="html"><![CDATA[<p>...an example with port expander MCP23017 (soxso2011, I hope you don&#039;t mind I used a part of your script)</p><p>8 inputs and 8 outputs</p><p><a href="https://www.rexygen.com/oldforum/img/members/6/REX_MCP23017.zip" rel="nofollow">REX_MCP23017.zip</a></p>]]></content>
		<author>
			<name><![CDATA[scoobsalamander]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=6</uri>
		</author>
		<updated>2017-05-03T18:40:55Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=1596#p1596</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=125#p125"/>
		<content type="html"><![CDATA[<p>Yep!!</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-29T11:52:45Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=125#p125</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=124#p124"/>
		<content type="html"><![CDATA[<p>I do not see any syntax error. However, the problem is probably the variable <strong>i2c_port_handle</strong>, which you should change to <strong>i2c_bus_handle</strong>, as you were instructed in the <a href="http://www.rexygen.com/oldforum/viewtopic.php?id=27" rel="nofollow">other topic</a>. Check the definitions of variables at the beginning of your code. You&#039;ll probably find this definition of a variable:</p><div class="codebox"><pre><code>long i2c_bus_handle;</code></pre></div><p>So that&#039;s why you get an error when compiling and why you have to make this change.</p>]]></content>
		<author>
			<name><![CDATA[josar]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=15</uri>
		</author>
		<updated>2015-11-28T19:47:47Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=124#p124</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=123#p123"/>
		<content type="html"><![CDATA[<p>//Sending data via I2C<br />&#160; i2c_ret_fun = I2C(i2c_port_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; adc_value = (i2c_bufRx[0]&lt;&lt;8) + i2c_bufRx[1];</p><p>Is there any syntax error in these lines??</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-28T11:40:50Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=123#p123</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=122#p122"/>
		<content type="html"><![CDATA[<p>Yeah...It worked...!!!</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-28T11:38:25Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=122#p122</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=120#p120"/>
		<content type="html"><![CDATA[<p>I faced the same problem !. Dont bother with the IOCON.BANK attribute in the c program. Your address for configuring Port A &amp; Port B are correct.(0x06 &amp; 0x07) This is the part of the program what you must edit to read Bank 0 of PCA 9555 as Output and Bank 1 as input.</p><p>//the main procedure is executed once in each sampling period<br />long main(void)<br />{<br />&#160; &#160; //Controlling outputs<br />&#160; &#160; i2c_bufTx[0] = 0x06; //CHANGE 0x06 TO 0x02 (REFER PCA 9555 DATASHEET)<br />&#160; &#160; i2c_bufTx[1] = digital_out &amp; 0xFF; //masking the data to control the outputs<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; <br />&#160; &#160; //Reading inputs<br />&#160; &#160; i2c_bufTx[0] = 0x07; //CHANGE 0x07 TO 0x01 (REFER PCA 9555 DATASHEET)<br />&#160; &#160; i2c_write_count = 1;<br />&#160; &#160; i2c_read_count = 1;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; digital_in = i2c_bufRx[0]; //publishing the received data<br />&#160; &#160; return 0;<br />}</p><p>This worked for me successfully.</p>]]></content>
		<author>
			<name><![CDATA[deepak]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=22</uri>
		</author>
		<updated>2015-11-27T16:16:58Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=120#p120</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=118#p118"/>
		<content type="html"><![CDATA[<p>This is the file I edited for interfacing PCA9555. I have changed the register addresses accordingly in the below program but still unable to access pins. In the c code example for MCP23017, It says By default, IOCON.BANK=0. How to edit this parameter because in PCA9555 both banks are of 8 bit addressing. Please help</p><p>/************************************************************<br />*<br />* REXLANG - Using the MCP23017 I/O expander via I2C<br />*<br />*************************************************************/<br />#define I2CDEV_FNAME 67 // I2C device is defined by the fname parameter of the REXLANG block (e.g. set it to /dev/i2c-1 on the Raspberry Pi minicomputer)<br />//assigning inputs to variables, these variables are READ-ONLY<br />long input(3) digital_out; //the signal controlling the outputs is connected to input u3 of the REXLANG block<br />long output(10) digital_in; //the state of the input pins is published via output y10 of the REXLANG block<br />//declaration of variables<br />long i2c_bufTx[3]; //buffer for transmitting data<br />long i2c_bufRx[3]; //buffer for receiving data<br />long i2c_bus_handle;<br />long i2c_chip_address;<br />long i2c_write_count;<br />long i2c_read_count;<br />long i2c_ret_fun;<br />//the init procedure is executed once when the REXLANG function block initializes<br />long init(void)<br />{<br />&#160; &#160; i2c_bus_handle = Open(I2CDEV_FNAME); // open I2C bus<br />&#160; &#160; i2c_chip_address = 0x20; // 7-bit address of the I2C device<br />&#160; &#160; // !!!!!!!!!!!!!<br />&#160; &#160; // , therefore see Table 1-6 in the datasheet for register mapping<br />&#160; &#160; //<br />&#160; &#160; // Table 1-5, which confusingly appears sooner in the datasheet, displays register addresses <br />&#160; &#160; // for IOCON.BANK=1, which are significantly different <br />&#160; &#160; // !!!!!!!!!!!!!<br />&#160; &#160; <br />&#160; &#160; //Setting PORTA to output<br />&#160; &#160; i2c_bufTx[0] = 0x06; //register no. (IODIRA) <br />&#160; &#160; i2c_bufTx[1] = 0x00; //IODIRA data, bitmask, 0=output, 1=input<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; //Setting PORTB to input<br />&#160; &#160; i2c_bufTx[0] = 0x07; //register no. (IODIRB) <br />&#160; &#160; i2c_bufTx[1] = 0xFF; //IODIRB data, bitmask, 0=output, 1=input<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; //Enabling pull-up resistors on PORTB<br />&#160; &#160; i2c_bufTx[0] = 0x0D; //register no. (GPPUB) <br />&#160; &#160; i2c_bufTx[1] = 0xFF; //GPPUB data, bitmask, 0=no pull-up, 1=pull-up enabled<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; return 0;<br />}<br />//the main procedure is executed once in each sampling period<br />long main(void)<br />{<br />&#160; &#160; //Controlling outputs<br />&#160; &#160; i2c_bufTx[0] = 0x06; //register no. (GPIOA)&#160; &#160;<br />&#160; &#160; i2c_bufTx[1] = digital_out &amp; 0xFF; //masking the data to control the outputs<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; <br />&#160; &#160; //Reading inputs<br />&#160; &#160; i2c_bufTx[0] = 0x07; //register no. (GPIOB)&#160; &#160;<br />&#160; &#160; i2c_write_count = 1;<br />&#160; &#160; i2c_read_count = 1;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; digital_in = i2c_bufRx[0]; //publishing the received data<br />&#160; &#160; return 0;<br />}<br />//the exit procedure is executed once when the task is correctly terminated<br />// (system shutdown, downloading new control algorithm, etc.)<br />long exit(void)<br />{<br />&#160; if(i2c_bus_handle&gt;=0) Close(i2c_bus_handle); // close I2C bus<br />&#160; return 0;<br />}</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-27T07:26:10Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=118#p118</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=117#p117"/>
		<content type="html"><![CDATA[<p>I am trying to interface PCA9555 I2C i/O port expander, this the following code for i/o extender mpc23017, could you please tell me what to edit for PCA9555.I am unable to access any pins.</p><br /><p>/************************************************************<br />*<br />* REXLANG - Using the MCP23017 I/O expander via I2C<br />*<br />*************************************************************/<br />#define I2CDEV_FNAME 67 // I2C device is defined by the fname parameter of the REXLANG block (e.g. set it to /dev/i2c-1 on the Raspberry Pi minicomputer)<br />//assigning inputs to variables, these variables are READ-ONLY<br />long input(3) digital_out; //the signal controlling the outputs is connected to input u3 of the REXLANG block<br />long output(10) digital_in; //the state of the input pins is published via output y10 of the REXLANG block<br />//declaration of variables<br />long i2c_bufTx[3]; //buffer for transmitting data<br />long i2c_bufRx[3]; //buffer for receiving data<br />long i2c_bus_handle;<br />long i2c_chip_address;<br />long i2c_write_count;<br />long i2c_read_count;<br />long i2c_ret_fun;<br />//the init procedure is executed once when the REXLANG function block initializes<br />long init(void)<br />{<br />&#160; &#160; i2c_bus_handle = Open(I2CDEV_FNAME); // open I2C bus<br />&#160; &#160; i2c_chip_address = 0x20; // 7-bit address of the I2C device<br />&#160; &#160; // !!!!!!!!!!!!!<br />&#160; &#160; // By default, IOCON.BANK=0, therefore see Table 1-6 in the datasheet for register mapping<br />&#160; &#160; //<br />&#160; &#160; // Table 1-5, which confusingly appears sooner in the datasheet, displays register addresses <br />&#160; &#160; // for IOCON.BANK=1, which are significantly different <br />&#160; &#160; // !!!!!!!!!!!!!<br />&#160; &#160; <br />&#160; &#160; //Setting PORTA to output<br />&#160; &#160; i2c_bufTx[0] = 0x00; //register no. (IODIRA) <br />&#160; &#160; i2c_bufTx[1] = 0x00; //IODIRA data, bitmask, 0=output, 1=input<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; //Setting PORTB to input<br />&#160; &#160; i2c_bufTx[0] = 0x01; //register no. (IODIRB) <br />&#160; &#160; i2c_bufTx[1] = 0xFF; //IODIRB data, bitmask, 0=output, 1=input<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; //Enabling pull-up resistors on PORTB<br />&#160; &#160; i2c_bufTx[0] = 0x0D; //register no. (GPPUB) <br />&#160; &#160; i2c_bufTx[1] = 0xFF; //GPPUB data, bitmask, 0=no pull-up, 1=pull-up enabled<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; return 0;<br />}<br />//the main procedure is executed once in each sampling period<br />long main(void)<br />{<br />&#160; &#160; //Controlling outputs<br />&#160; &#160; i2c_bufTx[0] = 0x12; //register no. (GPIOA)&#160; &#160;<br />&#160; &#160; i2c_bufTx[1] = digital_out &amp; 0xFF; //masking the data to control the outputs<br />&#160; &#160; i2c_write_count = 2;<br />&#160; &#160; i2c_read_count = 0;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; <br />&#160; &#160; //Reading inputs<br />&#160; &#160; i2c_bufTx[0] = 0x13; //register no. (GPIOB)&#160; &#160;<br />&#160; &#160; i2c_write_count = 1;<br />&#160; &#160; i2c_read_count = 1;<br />&#160; &#160; i2c_ret_fun = I2C(i2c_bus_handle, i2c_chip_address, i2c_bufTx, i2c_write_count, i2c_bufRx, i2c_read_count);<br />&#160; &#160; digital_in = i2c_bufRx[0]; //publishing the received data<br />&#160; &#160; return 0;<br />}<br />//the exit procedure is executed once when the task is correctly terminated<br />// (system shutdown, downloading new control algorithm, etc.)<br />long exit(void)<br />{<br />&#160; if(i2c_bus_handle&gt;=0) Close(i2c_bus_handle); // close I2C bus<br />&#160; return 0;<br />}</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-27T02:22:48Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=117#p117</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=116#p116"/>
		<content type="html"><![CDATA[<p>Without your source files (*.mdl and *.c) there is very little I can do. Zip your files and upload it here.</p>]]></content>
		<author>
			<name><![CDATA[jaroslav_sobota]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=3</uri>
		</author>
		<updated>2015-11-26T17:11:52Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=116#p116</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=114#p114"/>
		<content type="html"><![CDATA[<p>Error message while compiling: validation error:109,[rex i/o driver error]in pin pca955_gpio3:value<br />validation error:307[file open error] in pin pca9555_task.REXLANG:srcname</p><p>Please help!</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-26T14:04:17Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=114#p114</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=109#p109"/>
		<content type="html"><![CDATA[<p>Examples for integrating I2C devices are included in our GitHub repository, links in the <a href="https://www.rexcontrols.com/download#GitHubExamples" rel="nofollow">Downloads section</a>. After downloading, go into the &quot;Integrating_external_devices/I2C&quot; directory. You should be able to modify the examples for your GPIO expander.</p>]]></content>
		<author>
			<name><![CDATA[jaroslav_sobota]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=3</uri>
		</author>
		<updated>2015-11-26T00:00:42Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=109#p109</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Integrating I2C device using REXLANG]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=107#p107"/>
		<content type="html"><![CDATA[<p>How Rexlang block is used for I2C integration, I have made the connections and able to access it via command line sudo i2cdetect -y 1, but unable to integrate the same using Rexlang or any other block. The PCA9555 GPIO expander is used in my case.</p>]]></content>
		<author>
			<name><![CDATA[soxso2011]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=21</uri>
		</author>
		<updated>2015-11-25T19:09:23Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=107#p107</id>
	</entry>
</feed>
