<?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: Question about interrupts and SerialUSB</title>
		<link>http://forums.leaflabs.com/topic.php?id=2477</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:06:10 +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=2477" rel="self" type="application/rss+xml" />

		<item>
			<title>Anonymous on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12786</link>
			<pubDate>Tue, 21 Aug 2012 23:41:23 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">12786@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Doing a simple program again allowed SerialUSB to read while the interrupts were enabled.  Trying to enable them on my full sketch caused a lockup at various points, or at least, it appeared to lock up because the LCD display was not updating.  I'll have to poke around a bit to find out why.  I think we can write this one off as poor coding on my behalf.   Thanks for the help and pointers though.  :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12783</link>
			<pubDate>Tue, 21 Aug 2012 22:24:12 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">12783@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Sure, I'll give it another stab.  I'm going to try switching back to hardware SPI for the controller now that I have a cleaner circuit, it may be less prone to timing issues.&#60;/p&#62;
&#60;p&#62;Kinda sucks being a C++ noob though.  I find myself completely re-writing large chunks of code as I learn better ways of doing things, but hey, that's learning for ya.  Interesting problem I had was the menu system.  That is a subject for another thread altogether, since it will either provoke laughter or horror when people see how I handled it.  :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12775</link>
			<pubDate>Tue, 21 Aug 2012 17:09:49 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12775@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
the interrupt should never fire between the pause and resume commands, correct?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;that's correct. pausing the timer should prevent the counter from increasing, which should prevent any output compare interrupts from firing.&#60;/p&#62;
&#60;p&#62;can you post a short but complete program exhibiting the bad behavior? i'll try to reproduce and debug. (replacing the bit-banged SPI interrupt with a short delay might work.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pici on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12772</link>
			<pubDate>Tue, 21 Aug 2012 15:45:17 +0000</pubDate>
			<dc:creator>pici</dc:creator>
			<guid isPermaLink="false">12772@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Just a guess - i didn't follow your conversation completely - but had similiar problems with measuring time via irq. For me it worked out to add a delayMicroseconds(10) into loop().&#60;br /&#62;
So may be you add delayMicroseconds(10) after Timer3.pause().
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12770</link>
			<pubDate>Tue, 21 Aug 2012 15:37:36 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">12770@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yup, pinMode was set to output.  &#60;/p&#62;
&#60;p&#62;Maybe I do not understand the use of Timer for interrupts.  I would think that I could simply call  Timer3.pause() after attaching Timer3 to my interrupt handler to prevent the Maple from polling the input device.  I tried to work around this by doing the following within loop()...&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;Timer3.pause();
if (SerialUSB.available())
{
  digitalWrite(LEDpin, HIGH);
  command = SerialUSB.read();
  processCommand(command);
  command = 0;
}
Timer3.resume();&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I still get no LED when I bash away at the keyboard while attached to SerialUSB.  Interestingly enough, if I add debugging output via SerialUSB to my polling function, I get expected debugging output whenever the interrupt is triggered, just no input from SerialUSB apparently.  I don't understand why the above code does not work, however, because the interrupt should never fire between the pause and resume commands, correct?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12761</link>
			<pubDate>Tue, 21 Aug 2012 13:34:15 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12761@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
- returning immediately from the timer interrupt so that it does nothing? Did the SerialUSB.read work?&#60;br /&#62;
- not doing the bit-banging SPI, only the debugging, so it returns much faster?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;These are good ideas; please report the results.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Regarding the serialUSB.read question, the following failed to trigger the LED, so I would assume that it did not work.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Just as a sanity check, you did call &#60;code&#62;pinMode(BOARD_LED_PIN, OUTPUT)&#60;/code&#62;, yes?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12699</link>
			<pubDate>Sun, 19 Aug 2012 19:24:25 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">12699@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I cannot use the SPI peripheral because it is apparently too fast for my device.  One thing I did not think of doing is adding an entry in the hardware SPI library to lower the speed one more time.  &#60;/p&#62;
&#60;p&#62;I used the exact same hardware setup for bit banged and hardware-SPI, just loaded different sketches.  When I look at the logic analyzer traces for the hardware and bit-banged solutions, CLK, SS, and MOSI are identical except for the fact that the hardware solution is about 10% faster.  MISO, however, is not being driven by my SPI slave and I can only assume that it is because it does not acknowledge the communication attempts from the master.&#60;/p&#62;
&#60;p&#62;I will try to take another stab at it and see if an immediate return from the timer interrupt still causes a problem with SerialUSB.  Regarding the serialUSB.read question, the following failed to trigger the LED, so I would assume that it did not work.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if (SerialUSB.available())
{
  digitalWrite(LEDpin, HIGH);
  command = SerialUSB.read();
  processCommand(command);
  command = 0;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12694</link>
			<pubDate>Sun, 19 Aug 2012 09:21:17 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">12694@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;jwestervelt - what have you done to identify the defect causes?&#60;/p&#62;
&#60;p&#62;For example, have you tried:&#60;br /&#62;
- returning immediately from the timer interrupt so that it does nothing? Did the SerialUSB.read work?&#60;br /&#62;
- not doing the bit-banging SPI, only the debugging, so it returns much faster?&#60;br /&#62;
What happens?&#60;/p&#62;
&#60;p&#62;Is there a reason for not using the SPI peripheral to do the transfer?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Question about interrupts and SerialUSB"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2477#post-12634</link>
			<pubDate>Sat, 18 Aug 2012 20:58:57 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">12634@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have a quick question regarding using interrupts.   I am using one of the timers to attach an interrupt handler to poll my SPI device (Playstation2 controller) since there is no way for the SPI device to trigger an external interrupt.  I want to poll this device approximately 100 times a second.&#60;/p&#62;
&#60;p&#62;I have the interrupt handler working as expected, and the entire handler takes 0.8mS to execute (The device is slow, has to be bit-banged at about 100kHz).  I left the overflow at 65535, but set the pre-scalar at 10 so that it will overflow about 110 times a second, roughly what my desired polling rate is.  For debugging, I am dumping stuff over SerialUSB configured at 115200baud.  Everything works as expected.&#60;/p&#62;
&#60;p&#62;The gotcha, however, is that I am trying to also send commands to the Maple via SerialUSB and doing something like&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if (SerialUSB.available())
{
  command = SerialUSB.read();
  processCommand(command);
  command = 0;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I notice that the processCommand does not appear to get called.  In fact, I can set the LED pin high right before i do the SerialUSB.read() and the LED never triggers.  This tells me that Maple never sees data in the SerialUSB buffer.  :(&#60;/p&#62;
&#60;p&#62;Granted, I will not be using SerialUSB in the finished project, I am only using it for debugging.  I am curious, however, as to why it is not working as expected.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
