CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DMA and SPI [SOLVED]
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

DMA and SPI [SOLVED]
PostPosted: Tue Apr 10, 2018 10:57 pm     Reply with quote

I am starting to play with a DMA on a 24EP256GP206 chip. Running at 140MHz . Using SPI1 to transfer data to codec chip. All is well with how I have been running it up until now. I have been just using an SPI interrupt to load 8 words at a time. It chews through them and asks for another 8 words. Easy peasy.

Now trying to use the DMA to free up some CPU and do this stuff in the background.

I know all the hardware works and the SPI can transfer properly but I am not getting any transfer from DMA out to the SPI buffer. I can see that the DMA0PAD is set to the SPI1BUFF address on my chip 0x0248 and that the CHEN0 bit is set. I have the interrupt set to go off when the DMA is done which I can get to fire if I set the number of words to send from the DMA to the SPI to 1. Other than that the DMA interrupts will not fire and my SPI interrupt will not fire to indicate that anything is being transfered to the SPI.
Also the DMALCA shows 0x0000 indicating that it transferred out of the DMA0

Well check that, I can't even get the DMA INT to fire anymore.

If I can get this working then my next task will be to start reading the SD card with the DMA. But that will be another story. Smile

Here is the code I am using to set up the DMA
Code:

#BANK_DMA unsigned int dma_out_buff[16];

setup_dma(0, DMA_OUT_SPI1, DMA_WORD); //could be DMA_BYTE
enable_interrupts(INT_DMA0);

//dma_start(0, DMA_ONE_SHOT | DMA_FORCE_NOW, DMA_BUFFER_CH1[0], 16);

dma_start(0,DMA_ONE_SHOT|DMA_NO_INC|DMA_FORCE_NOW ,&dma_out_buff[0]); 

Any help would be appreciated. Thanks


Last edited by curt2go on Tue Apr 17, 2018 1:58 pm; edited 2 times in total
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Wed Apr 11, 2018 3:03 pm     Reply with quote

Is it my description, or is it that simple? I thought for sure someone would have some input. Anyways let me know if you can help. I'm stumped.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 12, 2018 12:08 am     Reply with quote

Look at the following thread:

Discussion PIC24 DMA help needed please [SOLVED]
http://www.ccsinfo.com/forum/viewtopic.php?t=51920
This is a 2-page thread.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Thu Apr 12, 2018 8:34 am     Reply with quote

Thanks PCM. I had read that one before. I did have some luck last night and was able to get the DMA interrupt to fire continuously now. I am using the SPI in enhanced mode because I am clocking out to a codec chip so I am getting the sync pulse on my SS line from that chip. But I think now the issue is that the SPI interrupt is firing with each word sent. The only way I can get the DMA to fire is to set the SPI interrupt to fire when " Interrupt when the last bit is shifted out of SPIxSR and the transmit is complete". That is the only interrupt type that will fire the DMA. But I put a counter in there and it counts with each word transferred. So I think i don't want the SPI interrupt firing all the time. That will slow things down will it not?

I also have an issue that it is not actually sending the right info out to the SPI buffer but I think thats just me being dumb somewhere...


So to recap. I have the DMA interrupt firing after its done 256 words. The SPI interrupt fires each word, i am not getting the right info to the SPI buffer.

So I am closer but still having issues. Any thoughts?
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sat Apr 14, 2018 4:32 pm     Reply with quote

OK. I have everything working as far as the interrupts and such. I can see I have set the peripheral address to SPI1BUFF and I am pulling from the correct address to shove there. I am also seeing that address incrementing so I know it's putting it there. The issue is that it is not actually writing out the SPI port.

When I do a normal SPI1BUFF = xx it writes properly and gets clocked out. I am set up as a slave.

Here is the setup I ended up using.
Code:

SPIBEN = 1;//enhanced buffer mode enabled.
SISEL2 = 1;
SISEL1 = 0;
SISEL0 = 1;

setup_spi(SPI_SLAVE | SPI_L_TO_H | SPI_MODE_16B);

setup_dma(0, DMA_OUT_SPI1, DMA_BYTE); //cound be DMA_BYTE
dma_start(0,DMA_PING_PONG ,playBufferAddress,fillBufferAddress,256); // DMA_CONTINOUS//DMA_PING_PONG
enable_interrupts(INT_DMA0);

Then i am writing to the SPI1BUFF to start the process. That was a part i did not have before...


{UPDATE}
I don't think its loading the buffer. Because I am in slave mode and the way I had the SPI intterupt bits set it was just clocking out 0's and letting me know it was empty again. Because I am shifting nothing into it. So I still have a fundamental problem. What it is , is still a mystery.

So Please any insight would be awesome. I know I am missing something dumb. Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 1:57 am     Reply with quote

Some comments:

You are setting the SPI to use word mode. It needs to be sent words. However critical question here is what is that master doing?. Is it clocking bytes or words?. If bytes then the SPI and DMA both need to be configured to byte mode. If words then both need to be in word mode.

Your need to start by loading is described in the data sheet:
Quote:

TX Only in Slave mode:
In this configuration, no DMA request is issued until the first block of SPIx data is received. To
initiate the DMA transfers, the user application must first send data using the DMA Manual
Transfer mode or it must first write data into the SPIx Buffer (SPIxBUF), independently of the
DMA.


It is important to understand that SPI is always fundamentally duplex. Bytes are clocked to you, even if you don't want/use them. You will only get a DMA interrupt when the whole buffer has been transferred. If you are doing 256 word transfers your buffer needs to be 256 words long. When using SPI I've always used two DMA channels and had one handle the TX and the other the RX. How it'll run without the RX being handled I don't know.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 1:20 pm     Reply with quote

Thanks Ttelmah.

It is clocking words. The BCK and FCK are coming form the codec clocking out what I put to the SPI1BUFF. That all works fine when I just send a word to that buffer.

I am starting with the FORCE bit and I can see the DMA0STAL increment as well at that point. I can even do it multiple times but nothing is being sent out to the port?

I am not setting the enhanced buffer setup to see when the buffer initially fills up. Normally I can send 8 words to it and it will fill up. That's how I was loading before I would set this load the buffer then set SISEL0 = 0 and the next interrupt would tell me when to fill it up again. It worked really good but i am doing too much now and need the cpu so I want this to happen in the background now. I'm going to check the Arbiter now to see if it is stopping me. BUt Any other suggestions will be great. It all seems like it should work, just now getting out the port. Hardware is all good cause like i said I can send 1 word to SPI1BUFF and it sends it out. I even did a test where I wrote the contents of the DMA0STAL buffer out and it worked. So hardware is good.
Code:
SPIBEN = 1;//
SISEL2 = 1;
SISEL1 = 1;
SISEL0 = 1;
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 3:17 pm     Reply with quote

TX Only in Slave mode:
In this configuration, no DMA request is issued until the first block of SPIx data is received.

I am not even using the RX on the SPI, is this where my fundamental issue is?

Or is that meaning the data I am sending to it? I am getting more lost with this as time goes on.

I have tried using the FORCE but to start and just writing to the SPIBUFF, both
will eventuly give me a DMA interrupt. But using FORCE does not send anything out the SPI, writing to the SPI buff directly seems to keep sending out those same words over and over.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 8:24 pm     Reply with quote

Well after a lot of testing and messing around i have found it to have something to do with the enhanced buffer. Its like the enhanced buffer is not FIFO the buffer. I can at least get something to come out of the SPI now but now really sure why not with Enhanced on. I can see the DMA interrupt is firing meaning its being taken out of DMA and put in SPIBUFF.

Man this stuff is difficult. I will keep going on this but not sure how much more I can take. So just an update.

Any thoughts would be great... Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 9:23 pm     Reply with quote

Use Google to search the Microchip forums. Try this search string:
Quote:
site:microchip.com/forums DMA spi enhanced

There are many hits with that search string. Here is one of them:

SPI Enhanced mode FIFO not behaving | Microchip
http://www.microchip.com/forums/m597308.aspx
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 9:29 pm     Reply with quote

Thanks PCM. My enhanced is working in regular slave mode. But I will see if this helps in the DMA mode. I have basically given up on the idea. 50 hours will do that to you. I have tried before setting up another DMA to read as well. But to no avail. I will give things one more shot.

Oh I will also note I have nothing coming on the SPI receive. I am only sending info.

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 9:54 pm     Reply with quote

Ttelmah suggested that you setup both xmit and receive.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 9:57 pm     Reply with quote

Correct. I was doing that in numerous tries.

I found in another thread on microchip that you in fact can not be in enhanced mode for DMA.

I have been in a learning curve for this one. Very frustrating. I appreciate all the help.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 10:00 pm     Reply with quote

Is there a way to see what has been sent to the buffer from the DMA? Meaning what the buffer actually is seeing?

Thanks again for everything.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sun Apr 15, 2018 11:09 pm     Reply with quote

OK. I am actually getting somewhere.

I put my logic analyzer on the outgoing SPI. I am getting data that I know I am sending. The DMA keeps going.

My issue now is that I am only sending out 1 WORD, or the WORD that is at this address xx in my buffer, for example

dma_start(0,DMA_PING_PONG,playBufferAddress,fillBufferAddress,0);

that will send out what was in location 0, if I put a 1 at the end, that will send out what is in location 1 etc. but only that location then switch over to the secondary buffer and send out 1 byte at that location in the buffer.

Now what is going on. I thought that if I put 128 in there it would send out 128 words from that buffer incriminating each time?

Well at least I have something. I will post what I have and all the wrong doings after I get this.

Thanks again.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group