<?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 added to i2c.c  (PoC)</title>
		<link>http://forums.leaflabs.com/topic.php?id=1543</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:08:50 +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=1543" rel="self" type="application/rss+xml" />

		<item>
			<title>crenn on "I2C slave added to i2c.c  (PoC)"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1543#post-10934</link>
			<pubDate>Mon, 28 May 2012 08:40:27 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">10934@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The simple answer is yes. The new Wire structure is set up with this in mind, although the changes need to be integrated into i2c.h/c before I can do that part. I'll look into patching it in a week or so after exams.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>blackswords on "I2C slave added to i2c.c  (PoC)"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1543#post-10911</link>
			<pubDate>Sun, 27 May 2012 15:10:13 +0000</pubDate>
			<dc:creator>blackswords</dc:creator>
			<guid isPermaLink="false">10911@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I didn't try this but it's quite interesting, it is planned to be included in the future release of the Maple Library?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "I2C slave added to i2c.c  (PoC)"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1543#post-10155</link>
			<pubDate>Mon, 09 Apr 2012 17:42:55 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">10155@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I know there's not a great demand for I2C slave, but as proof of concept, I added slave code to i2c.c and i2c.h (maple ide v0.0.12). see code here&#60;br /&#62;
&#60;a href=&#34;http://pastebin.com/QdcwjgN4&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/QdcwjgN4&#60;/a&#62;&#60;br /&#62;
&#60;a href=&#34;http://pastebin.com/QTm6aHig&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/QTm6aHig&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Code is not industrial strength, only hobbyist strength with several TODOs. Code is interrupt driven and uses arduino-like event handlers. Setup would be&#60;/p&#62;
&#60;p&#62;    i2c_slave_enable(I2C2, I2CID, 0);  // 100KHz&#60;br /&#62;
    i2c_attachSlaveRxEvent(I2C2,receiveEvent);&#60;br /&#62;
    i2c_attachSlaveTxEvent(I2C2,requestEvent);&#60;/p&#62;
&#60;p&#62;with events handlers&#60;br /&#62;
void receiveEvent(int howMany)&#60;br /&#62;
{&#60;br /&#62;
    if (i2c_slave_available(I2C2)) x = i2c_slave_read(I2C2);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void requestEvent()&#60;br /&#62;
{&#60;br /&#62;
    uint8 data[32];&#60;br /&#62;
    x++;&#60;br /&#62;
    data[0] = x;&#60;br /&#62;
    i2c_slave_write(I2C2,data,1);    // send back to master&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Though code sort of supports both maple I2C interfaces, the i2c.c code needs additional work to replicate some of the data structures into each interface, if you really want to run two I2C interfaces at once.&#60;/p&#62;
&#60;p&#62;I've only tested at 100KHz from an arduino Wire I2C master. Seems to work with single and multiple byte transfers.&#60;/p&#62;
&#60;p&#62;I observed SDA/CLK with USB scope, and enabled I2C_DEBUG so I could print  out the event &#34;crumbs&#34; and also printed out I2C regs with&#60;/p&#62;
&#60;p&#62;void i2c_dump(){&#60;br /&#62;
  int i;&#60;br /&#62;
  unsigned int *p = (unsigned int *)0x40005800; //  i2c2  c1 is 5400&#60;br /&#62;
  for (i=0; i&#38;lt;9; i++){&#60;br /&#62;
    SerialUSB.println(p[i],HEX);&#60;br /&#62;
  }&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Only trick was that reference manual failed to mention that you need  to touch CR1 after slave transmit done (AF raised).&#60;/p&#62;
&#60;p&#62;Next I might try DMA, though I'm tempted to wait on next generation F4, e.g., Maple II or Arduino Due.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
