<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: I2C Slave code implemented</title>
		<link>http://forums.leaflabs.com/topic.php?id=2630</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:06:05 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=2630" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13104</link>
			<pubDate>Mon, 03 Sep 2012 13:23:02 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">13104@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Got it, thanks. I will review and test tomorrow (Tuesday) and get back to you. Let's move discussion of the patch over to the pull request page:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/pull/54/&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/pull/54/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13102</link>
			<pubDate>Mon, 03 Sep 2012 11:52:54 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13102@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;OK so I put it up on my github&#60;/p&#62;
&#60;p&#62;I have requested a pull from you.&#60;/p&#62;
&#60;p&#62;Commit msg&#60;br /&#62;
&#60;a href=&#34;https://github.com/ginge/libmaple/commit/da01c80f24dc9c43ff951ea9fd283abb4628ceb7&#34; rel=&#34;nofollow&#34;&#62;https://github.com/ginge/libmaple/commit/da01c80f24dc9c43ff951ea9fd283abb4628ceb7&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13095</link>
			<pubDate>Mon, 03 Sep 2012 03:05:44 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13095@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;It would be nice to get it into the tree.&#60;/p&#62;
&#60;p&#62;I will follow the submission guidelines and also write something that resembles documentation for the feature.&#60;/p&#62;
&#60;p&#62;ginge
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13084</link>
			<pubDate>Sun, 02 Sep 2012 20:12:37 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">13084@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;thanks for the updates and bugfixes, as well as for the advice on what makes sense regarding the API names and code structure.&#60;/p&#62;
&#60;p&#62;are you posting this patch as a proof of concept, or would you like us to apply it to the official leaflabs tree? if you're looking for this to get into our tree, we need a sign-off line along with the patch. see the libmaple contributing doc:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/libmaple/contributing.html#submitting-via-email&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/contributing.html#submitting-via-email&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13083</link>
			<pubDate>Sun, 02 Sep 2012 14:36:32 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13083@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Another patch!&#60;/p&#62;
&#60;p&#62;Fixed a corner case where the tx callback was called before the rx callback on a repeated start.&#60;/p&#62;
&#60;p&#62;Added new I2C state in the i2c_state enum&#60;br /&#62;
I2C_STATE_SL_RX             = 4, /**&#38;lt; Slave receiving */&#60;/p&#62;
&#60;p&#62;when transmitting it is I2C_STATE_BUSY&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/9mk2bssk&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/9mk2bssk&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;ginge
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13054</link>
			<pubDate>Sat, 01 Sep 2012 08:18:50 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13054@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;new diff.&#60;/p&#62;
&#60;p&#62;fixed tabs to spaces&#60;br /&#62;
fixed 2 small syntactical bugs&#60;br /&#62;
added i2c_slave_init()&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/cjza1CnD&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/cjza1CnD&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13053</link>
			<pubDate>Sat, 01 Sep 2012 07:48:27 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13053@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;please ignore the fact the pasted snipped has a bug ;)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13050</link>
			<pubDate>Sat, 01 Sep 2012 07:36:14 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13050@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So I implemented an i2c_slave_enable function. It calls i2c_master_disable and then re-enables it passing the flags.&#60;/p&#62;
&#60;p&#62;i2c_slave_enable(i2c_dev *dev, uint32 flags) {&#60;br /&#62;
	i2c_master_disable(i2c_dev *dev);&#60;br /&#62;
	i2c_master_enable(dev-&#38;gt;config_flags &#38;amp; flags);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;I don't like it. it seems wrong.&#60;/p&#62;
&#60;p&#62;I would much prefer i2c_master_enable to be renamed to i2c_enable or somesuch.&#60;/p&#62;
&#60;p&#62;why?&#60;br /&#62;
1) slave depends on master code&#60;br /&#62;
2) enabling slave only would require duplicating a few of code paths. Unacceptable.&#60;br /&#62;
3) if you want to use slave only, don't call master_xfer :)&#60;br /&#62;
4) slave extensions to IRQ handlers are very small. separating them to accommodate i2c_reconfigure or somesuch is code duplication, and I feel a bit overkill.&#60;br /&#62;
5) barely any of the patch will be optimised out by the compiler because it is mostly in interrupt callbacks&#60;/p&#62;
&#60;p&#62;well... I will let you decide what is best. I will happily make some changes to the code to better fit the rest.&#60;/p&#62;
&#60;p&#62;back to implementing CAN bus!&#60;/p&#62;
&#60;p&#62;ginge
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13035</link>
			<pubDate>Fri, 31 Aug 2012 19:32:58 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13035@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok you are only really talking a minor change to the code for this.  &#60;/p&#62;
&#60;p&#62;* Enabling the master and the slave at the same time saves having to check the master is enabled and then initialising/re-initialising.&#60;br /&#62;
* Slave code is dependent on the master code. (clocks, irq setup, interrupts etc) to separate them completely would be a nightmare.&#60;/p&#62;
&#60;p&#62;I will add a slave_init function, but it will basically check the module is enabled, and if not call master_init with the same flags.&#60;br /&#62;
if the module is enabled, the simplest and most code efficient route would be to disable the I2C module and then call master_init with the new flags.&#60;/p&#62;
&#60;p&#62;Let me see what I can do :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13034</link>
			<pubDate>Fri, 31 Aug 2012 19:11:43 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">13034@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Awesome! Looks cool; thanks for posting. One issue, though:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
 Under the circumstances, I don't think i2c_master_init is a true representation of what it now does, but creating a slave_init function just added bloat.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;We can't call it i2c_master_init() if it also enables slave mode ;). Adding another function won't add to the code size of the final program unless it gets used (due to the -ffunction-sections -fdata-sections GCC flags used when compiling and --gc-sections flag passed when linking).&#60;/p&#62;
&#60;p&#62;You may be able to get master versus slave enabling sharing most of their code in a third function that's hidden from view. That's the approach taken in libmaple/spi.c: spi_master_enable() and spi_slave_enable() both defer to a single function, spi_reconfigure():&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/spi.c#L159&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/libmaple/spi.c#L159&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "I2C Slave code implemented"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2630#post-13032</link>
			<pubDate>Fri, 31 Aug 2012 18:43:27 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">13032@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi All,&#60;/p&#62;
&#60;p&#62;I am new here!&#60;br /&#62;
Long story short:&#60;br /&#62;
I needed I2C slave support in the libmaple core. I saw some half working and half implemented attempts scattered around, so I gave up and extended libmaple.&#60;/p&#62;
&#60;p&#62;So: I have a solid working I2C code implementation.&#60;/p&#62;
&#60;p&#62;Features:&#60;br /&#62;
*Allows STM to run as a slave AND as a master. Multi-master tested OK (apart from the usual multi-master issues)&#60;br /&#62;
*Allows each I2C module to run as a master and a slave&#60;br /&#62;
*Each I2C module can accept dual i2C bus addresses&#60;br /&#62;
*Supports General call write only addressing (on address 0x00)&#60;br /&#62;
*Has configurable callbacks for each i2C module&#60;br /&#62;
*Can callback on each incoming/outgoing byte&#60;br /&#62;
*supports buffered IO. Single RX callback and TX callback for each request&#60;br /&#62;
*Requests use the same dev_msg machanism&#60;/p&#62;
&#60;p&#62;I have extended a few chunks of code, but kept to the spirit of the current (excellent) design. notably each feature now has a new flag that is passed to i2c_master_init. Under the circumstances, I don't think i2c_master_init is a true representation of what it now does, but creating a slave_init function just added bloat.&#60;/p&#62;
&#60;p&#62;Resources:&#60;br /&#62;
Diff file &#60;a href=&#34;http://pastebin.com/k0vTt5rT&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/k0vTt5rT&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Example:&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
setup()&#60;br /&#62;
{&#60;br /&#62;
msgs.data = buf;&#60;br /&#62;
    i2c_master_enable(I2C1, I2C_FAST_MODE &#124; I2C_SLAVE_DUAL_ADDRESS &#124; I2C_SLAVE_GENERAL_CALL &#124; I2C_SLAVE_USE_RX_BUFFER &#124; I2C_SLAVE_USE_TX_BUFFER);&#60;br /&#62;
    i2c_slave_attach_recv_handler(I2C1, &#38;amp;msgs, funcrx);&#60;br /&#62;
    i2c_slave_attach_transmit_handler(I2C1, &#38;amp;msgs, functx);&#60;br /&#62;
    i2c_slave_set_own_address(I2C1, 0x0010);&#60;br /&#62;
    i2c_slave_set_own_address2(I2C1, 0x0020);&#60;br /&#62;
}&#60;br /&#62;
void funcrx(i2c_msg *msg)&#60;br /&#62;
{&#60;br /&#62;
	someval = msg-&#38;gt;data[0];&#60;br /&#62;
}&#60;br /&#62;
void functx(i2c_msg *msg)&#60;br /&#62;
{&#60;br /&#62;
	msg-&#38;gt;data[0] = 0x01;&#60;br /&#62;
	msg-&#38;gt;data[1] = 0x02;&#60;br /&#62;
	msg-&#38;gt;data[2] = 0x03;&#60;br /&#62;
	msg-&#38;gt;data[3] = 0x04;&#60;br /&#62;
	msg-&#38;gt;data[4] = 0x05;&#60;br /&#62;
	msg-&#38;gt;length = 5;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;i2c_msg msgs;&#60;br /&#62;
uint8 buf[255];&#60;br /&#62;
&#60;/code&#62;&#60;br /&#62;
Questions?&#60;/p&#62;
&#60;p&#62;Ginge
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
