<?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: USART3 Interrupt Grabbing?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1134</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:04:17 +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=1134" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134&amp;page=2#post-105731</link>
			<pubDate>Sat, 02 May 2015 03:22:07 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105731@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;While LeaqfLabs have 'end of lifed' their production of the product, it is still easy to get Maple or Maple mini, that is part of the potential power of Open Source Hardware.&#60;br /&#62;
For example search for &#60;a href=&#34;http://www.ebay.com/sch/i.html?_from=R40&#38;amp;_nkw=leaflabs+maple&#38;amp;_sacat=0&#34;&#62;&#34;leaflabs maple&#34; at eBay&#60;/a&#62;.&#60;br /&#62;
Mini's are under $5.&#60;/p&#62;
&#60;p&#62;So, IMHO, it is still worth sharing code, and, as @stephanschulz has written, it might also be ported to other manufacturers MCUs.&#60;/p&#62;
&#60;p&#62;I would add, AFAICT, DMA varies between different manufacturers, so it will take a bit of work to move to other manufacturers MCUs. Also, ST Micro's Nucleo's are 'cheap as chips', so that might provider another path to make low-level code available.&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stephanschulz on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134&amp;page=2#post-105727</link>
			<pubDate>Wed, 29 Apr 2015 14:39:08 +0000</pubDate>
			<dc:creator>stephanschulz</dc:creator>
			<guid isPermaLink="false">105727@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@konan&#60;br /&#62;
did you ever get your DMX code working by using DMA channels? want to share what your got?&#60;/p&#62;
&#60;p&#62;i know the maple is dead but other ARM micros like the Teensy might benefit from a DMA - DMX library :)&#60;/p&#62;
&#60;p&#62;thanks,&#60;br /&#62;
stephan.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>nickc on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-66804</link>
			<pubDate>Fri, 04 Oct 2013 11:42:12 +0000</pubDate>
			<dc:creator>nickc</dc:creator>
			<guid isPermaLink="false">66804@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;This forum post doesn't quite resolve this issue for me.&#60;/p&#62;
&#60;p&#62;What is the correct method for overriding default interrupt handlers?&#60;/p&#62;
&#60;p&#62;For example, I get multiple definitions errors of __irq_usart1 in the maple IDE unless I go in and comment out the code in the library usart.c&#60;/p&#62;
&#60;p&#62;It doesn't seem like there's currently any method or compiler macro in libmaple is this the case?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stephanschulz on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-22433</link>
			<pubDate>Fri, 22 Feb 2013 10:48:33 +0000</pubDate>
			<dc:creator>stephanschulz</dc:creator>
			<guid isPermaLink="false">22433@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;it seems i got it all up and running.&#60;/p&#62;
&#60;p&#62;- 16 LEDs can be dimmed NOT using the build in PWM mode&#60;br /&#62;
- DMX data is received&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/antimodular/maple_dmx_dimming&#34; rel=&#34;nofollow&#34;&#62;https://github.com/antimodular/maple_dmx_dimming&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-22409</link>
			<pubDate>Tue, 19 Feb 2013 19:49:45 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">22409@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;stephanschulz - can you try to attack the problem using some throw-away code?&#60;/p&#62;
&#60;p&#62;The symptoms might indicate characters are being lost.&#60;br /&#62;
This might be because of using USB for output, or other interrupts (for example USB or Systick).&#60;br /&#62;
So don't print to USB, and switch off USB, and Systick interrupts (IIRC there isn't anything else).&#60;/p&#62;
&#60;p&#62;My thought, which might be a bit too simple, is to write code which 'knows' what the data looks like, and which does nothing except for validating the DMX packets, after switching off everything else. The checking code would run for several hundred (or many thousand) iterations, and just count the number of errors. At the end of its iterations it would indicate the number of errors, maybe by lighting some combination of LEDs (or down a serial port if you can read it).&#60;/p&#62;
&#60;p&#62;Start the test at a slow transmission speed, and crank it up. If it runs at the current speed without error, then printing to USB or the other interrupts might be the cause.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stephanschulz on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-22408</link>
			<pubDate>Tue, 19 Feb 2013 16:56:26 +0000</pubDate>
			<dc:creator>stephanschulz</dc:creator>
			<guid isPermaLink="false">22408@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;i had a bunch of stuff in loop()&#60;/p&#62;
&#60;p&#62;taking that out helped to make this more stable.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stephanschulz on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-22407</link>
			<pubDate>Tue, 19 Feb 2013 15:44:57 +0000</pubDate>
			<dc:creator>stephanschulz</dc:creator>
			<guid isPermaLink="false">22407@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;i finally got brettlevine's code working. i will posted it eventually but at this point i forgot what i did different.&#60;/p&#62;
&#60;p&#62;i thing i am noticing is that the channels sequence shifts sometimes.&#60;br /&#62;
i have the pc fade only one channel and the channels stay at zero. on the maple the connected led fades nicely but sometimes the lower channel gets its value.&#60;/p&#62;
&#60;p&#62;for example here is a print out of 5 channels&#60;/p&#62;
&#60;p&#62;0 0 0 122 0&#60;br /&#62;
0 0 0 122 0&#60;br /&#62;
0 0 0 122 0&#60;br /&#62;
0 0 122 0 0&#60;br /&#62;
0 0 0 122 0&#60;/p&#62;
&#60;p&#62;this error happens more often the higher the channel numbers are.&#60;/p&#62;
&#60;p&#62;i am guessing that somewhere in this section of the code channels are being skipped?&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;case DMX_START:
      dmx_addr++;
      if (dmx_addr == dmx_start_addr)
      {
        chan_cnt = 0;
        dmx_data[chan_cnt++] = constrain(data,0,maxDMXvalue); //data;
        dmx_state = DMX_RUN;
      }
      break;

    case DMX_RUN:
      dmx_data[chan_cnt++] = constrain(data,0,maxDMXvalue); //data;
      if (chan_cnt &#38;gt;= DMX_NUM_CHANNELS)
      {
        dmx_state = DMX_IDLE;
      }
      break;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;what can i do about this?&#60;/p&#62;
&#60;p&#62;thanks.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stephanschulz on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-22292</link>
			<pubDate>Wed, 06 Feb 2013 10:19:07 +0000</pubDate>
			<dc:creator>stephanschulz</dc:creator>
			<guid isPermaLink="false">22292@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;i tried out the code provided by brettlevine and changed it to use usart1 and commented out the appropriate lines in the usart.c.&#60;/p&#62;
&#60;p&#62;i do get data on the usart1 line but it is not consistent. not all 8 channels always receive data, or not the same data.&#60;br /&#62;
i have a real dmx receiving light dimmer on the same dmx line which allows me to see if the data i am sending from the PC is correct.&#60;/p&#62;
&#60;p&#62;?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>konan on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-19827</link>
			<pubDate>Mon, 01 Oct 2012 15:37:34 +0000</pubDate>
			<dc:creator>konan</dc:creator>
			<guid isPermaLink="false">19827@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi guys! I'm trying to receive DMX too, but I want to use DMA for this, to free the processor for the other tasks. And I plan to use the USART frame error interrupt to start the DMA transfer. But the Maple hangs up at first interrupt. &#60;/p&#62;
&#60;p&#62;The program must receive DMX data and print to the SerialUSB first 10 channels, so I can see does it receive anything or not. If I disable the interrups and put the DMA in cycle mode, within that 10 channels I sometimes see the data that I send to the DMX input, so the DMA is working (but the 1st channel of DMX data may appear in any array element). But when I enable the USART interrups (rising 1st bit of the CR3), the program prints zero values when no DMX data at the input, and hangs when I connect the DMX cable. What may be wrong? Here's the code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;quot;dma.h&#38;quot;

#define dmxSerial Serial3		// USART class
#define dmxBase USART3_BASE		// USART regesters
#define dmxInDMA DMA_CH3			// DMA channel

uint32 lm;
byte dmx[513];
volatile uint8 a;

extern &#38;quot;C&#38;quot; {
void __irq_usart3(void) {
	if (dmxBase-&#38;gt;SR &#38;amp; USART_SR_FE) {		// break
		dma_disable(DMA1, dmxInDMA);
		a = dmxBase-&#38;gt;DR;			// clear error flag
		a = a;			// for compiler not to make warning
		dma_set_mem_addr(DMA1, dmxInDMA, &#38;amp;dmx);
		dma_set_num_transfers(DMA1, dmxInDMA, 513);
		dma_enable(DMA1, dmxInDMA);
	}
}
}

void setup() {
  dmxSerial.begin(250000);
  dmxBase-&#38;gt;CR2 &#124;= USART_CR2_STOP_BITS_2;
  dmxBase-&#38;gt;CR3 &#124;= USART_CR3_DMAT;
  dmxBase-&#38;gt;CR3 &#124;= USART_CR3_DMAR;
  dmxBase-&#38;gt;CR1 &#38;amp;= 0b1111111000001111;	// disable interrupts
  dmxBase-&#38;gt;CR2 &#38;amp;= 0b1111111110111111;	// disable interrupts
  dmxBase-&#38;gt;CR3 &#124;= 1;	// enable error interrupt

  dma_init(DMA1);
  dma_setup_transfer(DMA1,
		   dmxInDMA,
		   &#38;amp;dmxBase-&#38;gt;DR,
		   DMA_SIZE_8BITS,
		   &#38;amp;dmx,
		   DMA_SIZE_8BITS,
		   DMA_MINC_MODE);

  dma_set_num_transfers(DMA1, dmxInDMA, 513);

  lm = millis();

  pinMode(22, OUTPUT);
  digitalWrite(22, LOW);       // MAX485 receive enable
}

void loop() {
  if (millis()&#38;gt;lm+500) {
    lm = millis();
    for (int i=0; i&#38;lt;10; i++) {
      SerialUSB.print(dmx[i],DEC);
      SerialUSB.print(&#38;quot;, &#38;quot;);
    }
    SerialUSB.println();
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(Edit: I added code layout markup hopefully making it easier to read - gbulmer)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-7564</link>
			<pubDate>Wed, 11 Jan 2012 12:23:38 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">7564@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
By the way, what if we create a .c file/library? Do we need to include the irq handler in the extern C block?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;In general, IRQ handlers need C linkage. Within a C++ file, this means you either put them within an extern &#34;C&#34; block, or you declare them extern &#34;C&#34; with&#60;/p&#62;
&#60;p&#62;extern &#34;C&#34; void __irq_whatever(void) { ... }&#60;/p&#62;
&#60;p&#62;Within a C file, they'll have C linkage already, so the extern linkage specifier is unnecessary.&#60;/p&#62;
&#60;p&#62;Regarding how to release code which overrides IRQ handlers as a library, this is currently a pain, since you have to get your users to comment out the handlers in the copy of libmaple that comes with the IDE. That's obviously not ideal, so in the next version, we'll be making the libmaple IRQ handlers weak, so you can override them just by declaring your own.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-7549</link>
			<pubDate>Tue, 10 Jan 2012 23:36:05 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">7549@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;No worries.&#60;br /&#62;
Written words look different than they would sound. &#60;/p&#62;
&#60;p&#62;Thanks for the info.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-7542</link>
			<pubDate>Tue, 10 Jan 2012 12:31:43 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7542@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo - I apologise if my answer was a bit more than you wanted. &#60;/p&#62;
&#60;p&#62;I try to answer questions in a way that might help the poster, and future forum readers who want answers to similar questions.&#60;br /&#62;
IMHO the accurate technical answer (no, it isn't needed in that specific context), isn't all the issues to consider for someone who is looking to answer this sort of question. There would not be an error message if the interrupt handler is not linked in, so testing and debugging can be confusing and worrying, and reusing the code is a bit delicate. So I think those things are worth mentioning too.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-7541</link>
			<pubDate>Mon, 09 Jan 2012 22:11:43 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">7541@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Just asking...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-7537</link>
			<pubDate>Mon, 09 Jan 2012 19:42:35 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7537@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo - I shouldn't really answer a question with a question, but let me ask:&#60;br /&#62;
1. how would you debug getting the incorrect linkage (hint: there probably won't be any error messages), and&#60;br /&#62;
2. is there a possibility that you're code might find its way into a .cpp file? &#60;/p&#62;
&#60;p&#62;IMHO, code should be as clear and unambiguous as practical.&#60;br /&#62;
IMHO, putting the extern &#34;C&#34; block around the interrupt handler, even though it isn't essential, increases the robustness and clarity of the code, and hence folks have more chance of getting things right.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "USART3 Interrupt Grabbing?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1134#post-7531</link>
			<pubDate>Sun, 08 Jan 2012 21:21:43 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">7531@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;By the way, what if we create a .c file/library? Do we need to include the irq handler in the extern C block?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
