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 support@ccsinfo.com

dsPIC33 DMA loop back

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tripper269



Joined: 06 May 2013
Posts: 33
Location: Toronto

View user's profile Send private message

dsPIC33 DMA loop back
PostPosted: Fri Mar 18, 2016 7:15 am     Reply with quote

Hi there,
I am working on DSC dsPIC33 starter kit DM330011. I am using CCS v5 in MplabX environment. The Kit comes with WM8510 codec and connected with dsPIC through DCI and I2C. I have already tested generating tone with codec and playing it on speaker. Now I want to read a signal from CODEC and by using DMA (with minimum CPU involvement), loop it back to CODEC. I completed it with copying the signal with for loop
Code:

for(n=0;n++;n<128)
   BufferA[n] = BufferB[n];

What I am trying now is read BufferA and write BufferB and then read BufferB and write BufferA. I think the best way to do this is using user flag in DMA interrupts
Code:

#INT_DMA1

void dma1_isr()
{
    clear_interrupt(INT_DMA1);
    Rxflag++;
}

#INT_DMA2

void dma2_isr()
{
    clear_interrupt(INT_DMA2);   
    Txflag++;
}

and then
Code:

if(Rxflag == 1 && Txflag == 1)
  {
   dma_start(1, DMA_ONE_SHOT ,BufferB,FRAME_SIZE-1);
   dma_start(2, DMA_ONE_SHOT ,BufferA,FRAME_SIZE-1);
  }
           
if(Rxflag == 2 && Txflag == 2)
  {
   Rxflag = 0;
   Txflag = 0;
   dma_start(1, DMA_ONE_SHOT ,BufferA,FRAME_SIZE-1);
   dma_start(2, DMA_ONE_SHOT ,BufferB,FRAME_SIZE-1);
  }

Please suggest, Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Fri Mar 18, 2016 8:59 am     Reply with quote

Get rid of the clear_interrupt calls. Pointless.

Read the CCS manual on interrupts. Understand that unless you tell it not to (NOCLEAR option), the compiler will always clear the interrupt for you.

Simplest solution is to use a toggle:
Code:

int8 rx_buffer_number=0;
int8 tx_buffer_number=0;

#int_dma1
void dma1_isr()
{
   rx_buffer_number ^=1;
}

//etc. for other interrupt

//Then why not have a two dimensional array?.
if (rx_buffer_number==tx_buffer_number)
{
     dma_start(1, DMA_ONE_SHOT ,&bufferA[0][rx_buffer_number], FRAME_SIZE-1);
     dma_start(2, DMA_ONE_SHOT ,&bufferB[0][tx_buffer_number], FRAME_SIZE-1);
}


As a comment though, I'd have expected to want to alternate the value, so you receive to buffer0, toggle this byte to 1, so you start to receive to buffer1, then send buffer0.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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