<?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: [BUG] Recent  I2C slave updates in github/master breaks I2C master</title>
		<link>http://forums.leaflabs.com/topic.php?id=13458</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:05:19 +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=13458" rel="self" type="application/rss+xml" />

		<item>
			<title>Mike McCauley on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-97571</link>
			<pubDate>Wed, 09 Oct 2013 05:40:59 +0000</pubDate>
			<dc:creator>Mike McCauley</dc:creator>
			<guid isPermaLink="false">97571@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Same test (whatever it turns out to be: prefer a separate master/slave flag) needs to be used in _i2c_irq_error_handler().
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Mike McCauley on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-97563</link>
			<pubDate>Wed, 09 Oct 2013 05:38:59 +0000</pubDate>
			<dc:creator>Mike McCauley</dc:creator>
			<guid isPermaLink="false">97563@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Actually, the test: (dev-&#38;gt;state != I2C_STATE_BUSY) is not a strong enough test to detect slave mode. There are race conditions where an interrupt can occur when acting as a master, but when state is not I2C_STATE_BUSY (eg DONE or ERROR).&#60;/p&#62;
&#60;p&#62;Really need to have a separate flag to indicate whether it is in slave or master mode.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Mike McCauley on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-36150</link>
			<pubDate>Fri, 27 Sep 2013 21:49:11 +0000</pubDate>
			<dc:creator>Mike McCauley</dc:creator>
			<guid isPermaLink="false">36150@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Im also affected by this bug in git master, slowing the port of an open source project to Maple.&#60;br /&#62;
Can it please be either fixed soon, or the offending update removed?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-30969</link>
			<pubDate>Fri, 20 Sep 2013 14:32:23 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">30969@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The following is my local patch to restore i2c master functionality (tested).&#60;br /&#62;
It doesnt touch the slave part so it 'should' keep slave functionality intact (untested).&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
@@ -348,8 +348,8 @@ void _i2c_irq_handler(i2c_dev *dev) {&#60;br /&#62;
      * Add Slave support&#60;br /&#62;
      */&#60;/p&#62;
&#60;p&#62;-    /* Check to see if MSL master slave bit is set */&#60;br /&#62;
-    if ((sr2 &#38;amp; I2C_SR2_MSL) != I2C_SR2_MSL) { /* 0 = slave mode 1 = master */&#60;br /&#62;
+    /* Check to see if that a master transfer is not active */&#60;br /&#62;
+    if (dev-&#38;gt;state != I2C_STATE_BUSY) { /* Master Xfer and no place else sets I2C_STATE_BUSY */&#60;/p&#62;
&#60;p&#62;         /* Check for address match */&#60;br /&#62;
         if (sr1 &#38;amp; I2C_SR1_ADDR) {
&#60;/p&#62;&#60;/blockquote&#62;</description>
		</item>
		<item>
			<title>hitcher404 on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-30957</link>
			<pubDate>Thu, 19 Sep 2013 21:56:03 +0000</pubDate>
			<dc:creator>hitcher404</dc:creator>
			<guid isPermaLink="false">30957@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Wow, should have looked at the forums before spending hours figuring this out myself.&#60;/p&#62;
&#60;p&#62;'ginge' could you at least ask someone to revert your pull request?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-28634</link>
			<pubDate>Fri, 30 Aug 2013 11:25:52 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">28634@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I think there must be a separate state flag to show if we are making a master or slave transfer.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ginge on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458&amp;page=2#post-28633</link>
			<pubDate>Fri, 30 Aug 2013 11:13:22 +0000</pubDate>
			<dc:creator>ginge</dc:creator>
			<guid isPermaLink="false">28633@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;confirmed. as the original submitter of the slave code, I will try and get to the bottom of this over as soon as possible.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458#post-28631</link>
			<pubDate>Fri, 30 Aug 2013 10:45:26 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">28631@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The following small sketch crashes but works if I remove the slave part of the interrupt handler. The borad is connected to a BMP050 barometric pressure sensor.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
#include &#38;lt;stdint.h&#38;gt;&#60;/p&#62;
&#60;p&#62;#include &#38;lt;libmaple/i2c.h&#38;gt;&#60;/p&#62;
&#60;p&#62;#define I2CPORT I2C2&#60;/p&#62;
&#60;p&#62;/************************************************************&#60;br /&#62;
 *&#60;br /&#62;
 *  I2C convenience functions&#60;br /&#62;
 *&#60;br /&#62;
 ************************************************************/&#60;/p&#62;
&#60;p&#62;i2c_msg msg[2];&#60;br /&#62;
uint8_t buffer[20];&#60;/p&#62;
&#60;p&#62;void i2c_read_buffer(uint8_t device, uint8_t address, uint8_t * buf, uint8_t count)&#60;br /&#62;
{&#60;br /&#62;
  int32_t rc;&#60;br /&#62;
  /* registar address (W)*/&#60;br /&#62;
  msg[0].addr = device;&#60;br /&#62;
  msg[0].flags = 0;&#60;br /&#62;
  msg[0].data = (uint8_t *)&#38;address;&#60;br /&#62;
  msg[0].length = 1;&#60;br /&#62;
  msg[0].xferred = 0;&#60;br /&#62;
  /* count byte's data request (R)*/&#60;br /&#62;
  msg[1].addr = device;&#60;br /&#62;
  msg[1].flags = I2C_MSG_READ;&#60;br /&#62;
  msg[1].data = buf;&#60;br /&#62;
  msg[1].length = count;&#60;br /&#62;
  msg[1].xferred = 0;&#60;br /&#62;
  rc = i2c_master_xfer(I2CPORT,msg,2,1000);&#60;br /&#62;
    if (rc&#38;lt;0) {&#60;br /&#62;
      I2CPORT-&#38;gt;error_flags = 0;&#60;br /&#62;
      I2CPORT-&#38;gt;state = I2C_STATE_IDLE;&#60;br /&#62;
  }&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;/*******************************************************************&#60;/p&#62;
&#60;p&#62;Application - setup and main loop&#60;/p&#62;
&#60;p&#62;*******************************************************************/&#60;/p&#62;
&#60;p&#62;void setup() {&#60;/p&#62;
&#60;p&#62;    SerialUSB.begin();&#60;br /&#62;
    i2c_init(I2CPORT);&#60;br /&#62;
    i2c_master_enable(I2CPORT, I2C_BUS_RESET);&#60;/p&#62;
&#60;p&#62;    int16_t value;&#60;br /&#62;
    i2c_read_buffer(0x77, 0xAA, buffer, 2);&#60;br /&#62;
    value = (buffer[0]&#38;lt;&#38;lt;8) + buffer[1];&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
    if (SerialUSB.available()&#38;gt;0) {&#60;br /&#62;
        SerialUSB.read();&#60;br /&#62;
        int16_t value;&#60;br /&#62;
        i2c_read_buffer(0x77, 0xAA, buffer, 2);&#60;br /&#62;
        value = (buffer[0]&#38;lt;&#38;lt;8) + buffer[1];&#60;br /&#62;
        SerialUSB.println(value);&#60;br /&#62;
    }&#60;br /&#62;
}&#60;br /&#62;
&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458#post-28629</link>
			<pubDate>Fri, 30 Aug 2013 10:20:58 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">28629@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Its a big sketch with lots of other stuff in it but I will try to prepare a minimal example. I think any I2C master read transfer will break, but I havn't had time to test this yet.&#60;/p&#62;
&#60;p&#62;Its not an OS issue but I am using the latest updated github libmaple code and an Olimex Maple clone, compiling under Fedora 18 with gcc version 4.7.4 20130613 (release) [ARM/embedded-4_7-branch revision 200083].&#60;/p&#62;
&#60;p&#62;The i2c slave support was merged into the main leaflabs git repository on 26 of july so it is a rather recent issue, and it appeared for me after merging the latest leaflabs patches into my repository a few days ago.&#60;/p&#62;
&#60;p&#62;I have used a debugger (JTAG) to find the exact line in the code where the crash happens.&#60;/p&#62;
&#60;p&#62;470:/work/hardware/leaflabs/cores/maple/libmaple/i2c.c ****                 dev-&#38;gt;i2c_slave_msg-&#38;gt;data[0] = dev-&#38;gt;regs-&#38;gt;DR;&#60;/p&#62;
&#60;p&#62;This is in the newly added I2C slave handling code in the interrupt handler, and since I only do master transfers, the slave part of the handler should not be reached.&#60;br /&#62;
Once the slave section is reached the code will try to write the read data into the slave message structure which is not defined since we are in a master read, Bang-Crash :(&#60;/p&#62;
&#60;p&#62;Regards&#60;br /&#62;
Magnus
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458#post-28625</link>
			<pubDate>Fri, 30 Aug 2013 09:17:22 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">28625@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Can you post the sketch which exhibited this issue? I haven't seen this occur before. Also what libmaple/Maple IDE version were you using and what OS and board?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "[BUG] Recent  I2C slave updates in github/master breaks I2C master"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13458#post-28619</link>
			<pubDate>Fri, 30 Aug 2013 04:23:11 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">28619@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The latest work on I2C, great work really, breaks the Master I2C mode.&#60;br /&#62;
The problem seems to be that after a master receive operation the MSL bit&#60;br /&#62;
in I2C_SR2 is reset to 0 when the stop condition is detected, and this happens&#60;br /&#62;
before the ISR can handle the received master data.&#60;/p&#62;
&#60;p&#62;Changing line 352 in i2c.c from:&#60;br /&#62;
&#60;code&#62;if ((sr2 &#38;amp; I2C_SR2_MSL) != I2C_SR2_MSL) { /* 0 = slave mode 1 = master */&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;to:&#60;br /&#62;
&#60;code&#62;if (0) { /*ALWAYS MASTER */&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;thus disabling all slave interrupt handling, restores master functionality in my I2C sketch.&#60;/p&#62;
&#60;p&#62;Regards&#60;br /&#62;
Magnus
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
