<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DMA for SPI master</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/1055/dma-for-spi-master</link><description>I&amp;#39;m reading AD-converter data usin nRF51822 SPI-Master. BLE-stack is active so I can&amp;#39;t use
interrupts with SPI. I get data every 2 ms. Sometimes Events are delayed so long that I get
erroneous data from AD. 
 Is there some way to implement DMA for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 20 Jan 2014 13:57:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/1055/dma-for-spi-master" /><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4991?ContentTypeID=1</link><pubDate>Mon, 20 Jan 2014 13:57:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:359c725a-ecf3-4ed7-b255-3a52562638b3</guid><dc:creator>Juha Okkonen</dc:creator><description>&lt;p&gt;I have been trying to make implementation using two timers and spi slave device to handle data transfer every two milliseconds.
One timer generates correct SCK for the SPI slave by toggling output pin.
Second timer counts pulses and stops first timer.
For some reason I can get correct output only if I run code in debugger by stepping source lines. If I just run without breakpoints nothing happens. And usually when stepping and things seem to work correctly otherwise ( I see correct pulse train on logicanalyzer ) debugging freezes immediately after starting both timers.
Any ideas what&amp;#39;s going on???&lt;/p&gt;
&lt;p&gt;Another question; how are functions wired into pins. Can I connect SPI:s SCK to same I/O-pin that timer is toggling. Or is only one function connected at a time. I have seen comments that behaviour is not specified if two different outputs are connected to same PIN, which would seem to implicate that what I want to do is possible.
I also need to connect SPI:s CS to a pin thats configured for output.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4990?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2013 20:17:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:560594b5-0f6b-4ccd-a0f1-342b676adf6c</guid><dc:creator>Bruce</dc:creator><description>&lt;p&gt;Hi Audun,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not doing much in the GPIOTE interrupt handler, just toggling the debug pin.  See the other thread linked below for code snippet.&lt;/p&gt;
&lt;h1&gt;I&amp;#39;m using app_gpiote and by looking at its implementation, clearing the EVENTS register is the first few things it does.&lt;/h1&gt;
&lt;p&gt;void GPIOTE_IRQHandler(void)
{
uint8_t  i;
uint32_t pins_state = NRF_GPIO-&amp;gt;IN;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Clear event.
NRF_GPIOTE-&amp;gt;EVENTS_PORT = 0;
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;...
...&lt;/h1&gt;
&lt;p&gt;I opened another thread for the GPIOTE interrupt issue so I don&amp;#39;t hijack this post.
&lt;a href="https://devzone.nordicsemi.com/index.php/radio-activity-causes-gpiote-interrupt-missing"&gt;devzone.nordicsemi.com/.../radio-activity-causes-gpiote-interrupt-missing&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks,
Bruce&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4988?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2013 17:42:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73cb02ba-4f43-4562-9d92-2607fbdfed3c</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;No problem. Regarding the missing interrupt, as you say it should be skewed when a lower stack interrupt occurs. How much processing are you doing in the GPIOTE interrupt handler? There is a chance that a lower stack interrupt happens while in the GPIOTE IRQHandler. If you haven&amp;#39;t cleared the EVENT register at this time and a new GPIOTE interrupt occurs, that new interrupt will be discarded once the EVENT register is cleared. If you aren&amp;#39;t already, try clearing the NRF_GPIOTE-&amp;gt;EVENTS_x register as the very first thing you do in the IRQHandler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4989?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2013 23:29:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad63b7c3-c4d2-43c9-963e-1edcd6dc5d4c</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;Thanks Audun.  I was just doing something similar to what you suggested.  I&amp;#39;m toggling a debug GPIO in AD&amp;#39;s interrupt GPIOTE interrupt handler.  However, from the debug GPIO captured by oscilloscope, I&amp;#39;m missing some interrupts if I turn on advertisement or if I&amp;#39;m in a connection.&lt;/p&gt;
&lt;p&gt;One thing puzzles me is the GPIOTE interrupt is not skewed, but some of them are missing completely.  I would imagine in this case a lower stack interrupt pushes GPIOTE interrupt, but not making it disappear.&lt;/p&gt;
&lt;p&gt;Any thought on that?&lt;/p&gt;
&lt;p&gt;Thanks,
Bruce&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4987?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2013 23:29:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ea4de0c-479d-471c-b390-320db714e020</guid><dc:creator>Bastiaan</dc:creator><description>&lt;p&gt;Thanks Audun.  I was just doing something similar to what you suggested.  I&amp;#39;m toggling a debug GPIO in AD&amp;#39;s interrupt GPIOTE interrupt handler.  However, from the debug GPIO captured by oscilloscope, I&amp;#39;m missing some interrupts if I turn on advertisement or if I&amp;#39;m in a connection.&lt;/p&gt;
&lt;p&gt;One thing puzzles me is the GPIOTE interrupt is not skewed, but some of them are missing completely.  I would imagine in this case a lower stack interrupt pushes GPIOTE interrupt, but not making it disappear.&lt;/p&gt;
&lt;p&gt;Any thought on that?&lt;/p&gt;
&lt;p&gt;Thanks,
Bruce&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4986?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2013 23:01:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13257980-400e-405b-9c8b-b9593b43a29f</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;Ah, I understand better now. Length of the radio interrupt is determined by:
a) How much data you have put in the softdevice TX buffer
b) Procedures initiated by the Master (channel map update, encryption, etc.)&lt;/p&gt;
&lt;p&gt;The softdevice will always try to send as many packets as possible during a single connection event. If you are sending multiple packets, the radio interrupt could be significantly longer (the Master actually decides how many packets can be sent during a connection interval). So, dont put more than X packets (I&amp;#39;m not sure of the exact number) in the TX buffer at a time. Then wait until you get a BLE_EVT_TX_COMPLETE event until you put in more.
Secondly, there are control procedures that can happen at any time. There will typically be channel map updates once in a while, but I&amp;#39;m not sure exactly how long radio interrupt that will cause.&lt;/p&gt;
&lt;p&gt;Anyway, I suggest using the radio notifications to trigger a GPIO, and use a logic analyzer or oscilloscope to see how long each interrupt actually takes. You can also have a main loop that toggles a GPIO, and you will see the toggling stopping during interrupts. This will give you a better feel of exactly how long each interrupt is. Note that some control procedures, such as channel map updates, is not something the application is aware of, and you would need a BLE sniffer to see when this is happening.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4985?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2013 22:15:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26e753b6-a87c-4344-ba7d-8253376eca3a</guid><dc:creator>Bruce</dc:creator><description>&lt;p&gt;Thanks for your reply, Audun.&lt;/p&gt;
&lt;p&gt;But unfortunately our AD runs on its own Crystal Oscillator and for sure it will collide with the radio events.  Which also implies that we cannot sync AD to radio notifications.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m just wondering if there&amp;#39;s a way to guarantee AD GPIOTE interrupt is serviced within 2ms (maybe 4ms or 8ms) with radio turned on?&lt;/p&gt;
&lt;p&gt;Thanks,
Bruce&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4984?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2013 21:30:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4c11915-f200-420d-b727-4136d3f31fe4</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;Hi Bruce,&lt;/p&gt;
&lt;p&gt;the radio notification functionality is a feature that triggers a software interrupt prior to, or after a radio interrupt (see &lt;a target="_blank" href="https://devzone.nordicsemi.com/documentation/nrf51/5.0.0/html/group__t__s110___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html#ga15378609daca09588e620b64555fc2e8" rel="nofollow"&gt;https://devzone.nordicsemi.com/documentation/nrf51/5.0.0/html/group__t__s110___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html#ga15378609daca09588e620b64555fc2e8&lt;/a&gt;). So if you need to perform stuff uninterrupted between radio events, or synchronize application tasks with radio activity, this is the best way.&lt;/p&gt;
&lt;p&gt;In your case, you could enable the radio notifications to give you an interrupt when the radio interrupt is finished. When the radio event finishes, you can start a repeated timer with your AD interrupt frequency. If the bluetooth connection parameters doesnt crash with your AD frequency, you should be able to get a stable AD read frequency. Note that there will be some drift (depending on your clock source), and you would probably want to add some logic to keep your AD timer synchronized with the radio notifications.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4983?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2013 20:27:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0a3df49-e20c-45aa-a9aa-c24c9770ad34</guid><dc:creator>Bruce</dc:creator><description>&lt;p&gt;Hi Audun,&lt;/p&gt;
&lt;p&gt;Could you please elaborate on how to synchronize radio activity with the AD reading to achieve 500Hz reading?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m in the same situation as Juha that the AD interupts every 2/4/8 milliseconds.  And unfortunately, the AD conversion data has to be read out before the next interrupt comes.&lt;/p&gt;
&lt;p&gt;Thanks,
Bruce&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4981?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2013 14:21:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c185c1e-43ca-46e2-905a-5f6173fa249d</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;You can keep track of the length by using a second timer as a counter, stopping the clock when the counter reaches the 9 byte clock value. Possibly the END event in the SPI slave can be of use, but I suspect this event connects to the CSN line.&lt;/p&gt;
&lt;p&gt;&amp;quot;Only one peripheral can be assigned to drive a particular GPIO pin at a time, failing to do so may result in unpredictable behavior.&amp;quot; You could give it a try, but it&amp;#39;s not designed to work like that.. :(&lt;/p&gt;
&lt;p&gt;Alternatively it&amp;#39;s possible to synchronize radio activity with your AD reads. Have you seen the radio notification functionality? You can use this to synch radio activity with a 2 ms application timer. Depending on the connection parameters and your application behaviour, you might be able to keep a steady 500 Hz AD reading. &lt;a target="_blank" href="http://devzone.nordicsemi.com/documentation/nrf51/5.0.0/html/group__t__s110___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html#ga15378609daca09588e620b64555fc2e8" rel="nofollow"&gt;http://devzone.nordicsemi.com/documentation/nrf51/5.0.0/html/group__t__s110___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html#ga15378609daca09588e620b64555fc2e8&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4982?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2013 14:08:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d34f99c6-e709-4022-82c7-79c010df7139</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;You understood problem correctly.
Luckily I dont&amp;#39; need to send anything when receiving values. All configuration is done beforehand.
Complication is, that interrupt from AD is kept active only until reading starts. So I don&amp;#39;t get signal telling how long to transfer bytes. Only a starting edge.
Every transfer is 9 bytes. So do you think it would be possible to generate both clock and length with a timer for the SPI-slave??&lt;/p&gt;
&lt;p&gt;Another complication is that I&amp;#39;m currently using BLE-module and not all the I/O-pins are available. It it were possible to configure SPI-slave and Timer -pins to same physical pins, it would be helpful. Is that at all possible. Theoretically I would expect it to be possible when one is output ant other input, but does HW support it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4980?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2013 14:08:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ec15957-502a-4a81-9b28-677ef2d0bf31</guid><dc:creator>Bastiaan</dc:creator><description>&lt;p&gt;You understood problem correctly.
Luckily I dont&amp;#39; need to send anything when receiving values. All configuration is done beforehand.
Complication is, that interrupt from AD is kept active only until reading starts. So I don&amp;#39;t get signal telling how long to transfer bytes. Only a starting edge.
Every transfer is 9 bytes. So do you think it would be possible to generate both clock and length with a timer for the SPI-slave??&lt;/p&gt;
&lt;p&gt;Another complication is that I&amp;#39;m currently using BLE-module and not all the I/O-pins are available. It it were possible to configure SPI-slave and Timer -pins to same physical pins, it would be helpful. Is that at all possible. Theoretically I would expect it to be possible when one is output ant other input, but does HW support it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DMA for SPI master</title><link>https://devzone.nordicsemi.com/thread/4979?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2013 13:43:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:958daa7e-6ab8-471d-92cf-513e214f79e9</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;Hi Juha,&lt;/p&gt;
&lt;p&gt;just to clarify: the SPI transfer itself is not corrupted, right? As the SPI Master, if you get interrupted in between byte transfers your next byte transfer is simply delayed. The hardware will always complete a byte transfer, even when the CPU is interrupted.&lt;/p&gt;
&lt;p&gt;My understanding of the problem is that the data you want to read becomes invalid if you delay reading it for too long.&lt;/p&gt;
&lt;p&gt;Unfortunately, there is no DMA support for the SPI Master. Only for the SPI Slave. But it might be possible to use the SPI Slave functionality in this case.&lt;/p&gt;
&lt;p&gt;I suppose your AD is a SPI Slave device, and cannot act as a Master.
What you would need to do is set up the SPI Slave peripheral. As both SPI devices are now slaves, you need to generate a clock signal on a different pin and connect it to the SPI Clock line. The clock can be generated using PPI and a TIMER.
Load up the TX buffer with the required data (register addresses etc., depending on your AD).
Configure the GPIOTE to generate an event on the AD interrupt (on both set and release edge), and connect it to your clock timer START and STOP tasks.
You might also have to connect the interrupt event to the AD Slave select line.
When the AD asserts the interrupt line, your GPIOTE interrupt event will fire, initiating the transfer.
With large enough TX/RX buffers, you should be able to line up multiple transfers.&lt;/p&gt;
&lt;p&gt;I realize this explanation is a bit messy, but hopefully you can make sense of it.&lt;/p&gt;
&lt;p&gt;Audun&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>