SPI latency DMA newbie question

I am an arduino newbie so know nothing and am hoping begging for some advice will help me get kick started.....

Basically I have not done anything yet as I want to be sure it is possible before starting coding .

I worry I will look stupid as I maybe ask the impossible or should have done some research first, I show below my pseudocode/thoughts/ideas/system description, but will ask my questions first...

  1. How can I setup dma on arduino to handle SPI (does arduino even have dma for SPI as slave??) i have seen this http://arduino.cc/forum/index.php?PHPSESSID=3224079b565191d380db0d82da085c82&topic=147858.0, but no mention of dma..

  2. How fast can arduino handle dma and interupts and what are speed considerations?, i.e. what is the shortest usleep in the main loop that can guarantee a constant step rate?

  3. Is there any example code of similar projects available?

System definition:

Arduino as SPI slave that works as a digital IO interface (basically constant step rate switching gpio pins dependent on SPI data)

  1. The arduino must take SPI packets of data (64 bytes I guess) as fast as possible
  2. store SPI data in memory
  3. constantly step through memory and switching IO pins
  4. flag SPI master if it runs out of data
  5. (possibly in future add some code for config the arduino via SPI e.g change step rate, number of io pins being switched etc..)

I am guessing what I need to do is

allocate 3 64 byte buffers
setup arduino dma to write SPI data to buffers (double buffering)
create interupt to rotate through the buffer when SPI dma completes
write the data output loop

I am assuming arduino has dma for SPI and it can be setup for 64 byte packets, I have not found any information about SPI dma yet??????

outline pseudo code below :

current_buffer = 0; // pointer indexing where we are for comparison purposes
dma_buffer = 0; // pointer to where SPI data is buffered by dma
out_buffer = -1; // pointer to buffer currently being read to output pins

setup_dma(); // function, how do we setup dma to copy 64 bytes from SPI to a memory buffer?????

// I imagine interupt routine should be similar to below:
interupt_service_routine()
{
// update circular buffer index
If (current_buffer == 3) current_buffer = 0 ;
else current_buffer = current_buffer + 1 ;

if(current_buffer==out_buffer) halt_spi_master(); // stop if we are going to over write the current output

if(current_buffer==3 & out_buffer==-1 ){ main_loop(); current_buffer=0; } // start the main loop once 3 buffers full
dma_buffer = current_buffer;
}
// I imagine the output loop should be similar to that below:
out_buffer=0;
main_loop()
{
DDRB = b11111111 ; // set portB output direction

for(;:wink:
{

PORTB= out_buffer[index]
index++;
usleep(step_time);
if(index==64) {
index=0;
If (out_buffer == 3) out_buffer = 0 ;
else out_buffer = out_buffer + 1 ;

if(out_buffer==dma_buffer) halt_master_flag_underrun();
}
}

Most Arduinos do not have ANY dma. Due might.

Not a mention of DMA anywhere in the datasheet. Another reason I never pick Atmel for my real projects. Just too under powered and feature scarce for the price.

Majenko, your anti-AVR tirades/whines are starting to get tedious.
Cut it out, there's a good chap.

Groove:
Majenko, your anti-AVR tirades/whines are starting to get tedious.
Cut it out, there's a good chap.

Hey, I'm getting better... I haven't mentioned my preferred alternative :wink:

majenko:

Groove:
Majenko, your anti-AVR tirades/whines are starting to get tedious.
Cut it out, there's a good chap.

Hey, I'm getting better... I haven't mentioned my preferred alternative :wink:

Okay after being told arduino does not have dma I just spent an hour doing research and find my project is probably impossible because I also have another requirement, chip must be easy hobby solderable DIP package.

What is your prefered alternative???

I checked the MSP430 and the DIP package chips don't have dma either :frowning:

Could this be done without dma, what is the max possible speed for a SPI transaction on an arduino, how many interupts does it generate etc????

Can you flesh out your requirements please?

The arduino must take SPI packets of data (64 bytes I guess) as fast as possible

is really a bit woolly.
It may be that DMA is unnecessary, but without solid numbers, it is tough to say.
DMA often implies external devices, wide busses, large memories and high pin counts, so it probably isn't surprising through-hole devices don't feature large in the candidate list.

At the risk of getting shot down in flames...

PIC18F26J11 Datasheet:
1024-byte SPI Direct Memory Access (DMA) channel

Available in 28-pin DIP, similar price to the ATMega328P. I've said enough. If I mention the fact that it's faster I'll get slapped.

AWOL:
Can you flesh out your requirements please?

The arduino must take SPI packets of data (64 bytes I guess) as fast as possible

is really a bit woolly.
It may be that DMA is unnecessary, but without solid numbers, it is tough to say.
DMA often implies external devices, wide busses, large memories and high pin counts, so it probably isn't surprising through-hole devices don't feature large in the candidate list.

Yes, sorry for the fuzzy requirements, I really just start thinking about it myself this afternoon and not put much thought into it.

Making things a little more solid numbers wise:

I am hoping to get minimum 100kHz switching speeds on the io pins, 16 bits of io or more, for high speed control of stepper motors. I assume that means SPI interupts at 200kHz?

Does that mean we get 100 instructions to handle each byte on a 20Mhz atmega168/328?

The control computer sends out SPI under dma in 64byte packets.

I have been looking around and is seems PIC32MX chips come in SPDIP package and have SPI and DMA available.

I got confused with arduino as I have seen mention of DMA, but now realise its on due and that uses SAM arm chip.

And the Arduino is ported to that processor is it?

Consider yourself shot down in a glorious Hindenburg-like blaze.

Seriously Majenko, why bother?

coughchipkitcough

coughchipkitcough

cough link to their forum? cough

AWOL:

coughchipkitcough

cough link to their forum? cough

But that would be treasonous wouldn't it?

But that would be treasonous wouldn't it?

Not if you are helping the OP.
You are helping the OP, aren't you?

Please stop being a prat.

AWOL:

But that would be treasonous wouldn't it?

Not if you are helping the OP.
You are helping the OP, aren't you?

Why would I ever do anything but? That is why we're all here, after all.

Why would I ever do anything but? That is why we're all here, after all.

You could have mentioned that in reply #2, but it seems you decided to spin it out, in what might be (mis?)interpreted as a cynical ploy to bump your post count.

AWOL:

Why would I ever do anything but? That is why we're all here, after all.

You could have mentioned that in reply #2, but it seems you decided to spin it out, in what might be (mis?)interpreted as a cynical ploy to bump your post count.

... like I need that ...

I have found that whenever I mention a microcontroller that isn't Atmel, that certain people immediately leap down my throat. Yes, I may prefer other brands, but that's not to say that Atmel is bad as such. It's horses for courses, and I just haven't found the right course for Atmel. I don't specifically favour any one brand - I have Atmel, TI, Microchip, even 8052 microcontrollers here. But 9 times out of 10 I always come back to the same type, because they seem to have the best offerings.

But heaven forbid I should actually suggest that to someone...

If you think that Arduino is not a sensible way to solve a given problem then I think it's appropriate to say that. If you're able to suggest a different solution which is more feasible, so much the better. Just don't expect to get help for non-Arduino problems on the Arduino forum.

whenever I mention a microcontroller that isn't Atmel, that certain people immediately leap down my throat.

Really? Here, rather than over on avrfreaks (which is Atmel-sponsored)?
I haven't had that problem; and I've mentioned/discussed Chipkit, teensy 3, launchpad, and others.

Perhaps it's your delivery...

majenko:
Another reason I never pick Atmel for my real projects. Just too under powered and feature scarce for the price.

Why are you here then, out of curiosity?

It's like going onto a Ford motor car forum, and saying "I never drive a Ford, they are hopeless". What's the point?